/** * @see sfGenerator */ public function generate($params = array()) { $this->params = $params; foreach (array('index_class', 'moduleName') as $required) { if (!isset($this->params[$required])) { throw new xfGeneratorException('You must specify "' . $required . '".'); } } if (!class_exists($this->params['index_class'])) { throw new xfGeneratorException('Unable to build interface for nonexistant index "' . $this->params['index_class'] . '"'); } if (null !== ($form = $this->get('simple.form.class', null))) { $reflection = new ReflectionClass($form); if (!$reflection->isSubClassOf(new ReflectionClass('xfForm'))) { throw new xfGeneratorException('Form class must extend xfForm'); } } // check to see if theme exists if (!isset($this->params['theme'])) { $this->params['theme'] = 'default'; } $themeDir = $this->generatorManager->getConfiguration()->getGeneratorTemplate($this->getGeneratorClass(), $this->params['theme'], ''); $this->setGeneratedModuleName('auto' . ucfirst($this->params['moduleName'])); $this->setModuleName($this->params['moduleName']); $this->setTheme($this->params['theme']); $themeFiles = sfFinder::type('file')->relative()->discard('.*')->in($themeDir); $this->generatePhpFiles($this->generatedModuleName, $themeFiles); $data = "require_once(sfConfig::get('sf_module_cache_dir') . '/" . $this->generatedModuleName . "/actions/actions.class.php');"; $data .= "require_once(sfConfig::get('sf_module_cache_dir') . '/" . $this->generatedModuleName . "/actions/components.class.php');"; return $data; }
/** * Identify concrete extensible interface name based on the class name. * * @param string $extensibleClassName * @return string */ public function getExtensibleInterfaceName($extensibleClassName) { $exceptionMessage = "Class '{$extensibleClassName}' must implement an interface, " . "which extends from '" . self::EXTENSIBLE_INTERFACE_NAME . "'"; $notExtensibleClassFlag = ''; if (isset($this->classInterfaceMap[$extensibleClassName])) { if ($notExtensibleClassFlag === $this->classInterfaceMap[$extensibleClassName]) { throw new \LogicException($exceptionMessage); } else { return $this->classInterfaceMap[$extensibleClassName]; } } $modelReflection = new \ReflectionClass($extensibleClassName); if ($modelReflection->isInterface() && $modelReflection->isSubClassOf(self::EXTENSIBLE_INTERFACE_NAME) && $modelReflection->hasMethod('getExtensionAttributes')) { $this->classInterfaceMap[$extensibleClassName] = $extensibleClassName; return $this->classInterfaceMap[$extensibleClassName]; } foreach ($modelReflection->getInterfaces() as $interfaceReflection) { if ($interfaceReflection->isSubclassOf(self::EXTENSIBLE_INTERFACE_NAME) && $interfaceReflection->hasMethod('getExtensionAttributes')) { $this->classInterfaceMap[$extensibleClassName] = $interfaceReflection->getName(); return $this->classInterfaceMap[$extensibleClassName]; } } $this->classInterfaceMap[$extensibleClassName] = $notExtensibleClassFlag; throw new \LogicException($exceptionMessage); }
public function add($className) { $reflection = new ReflectionClass(new $className()); if ($reflection->isSubClassOf("Sabel_Test_TestSuite")) { $this->addTest($reflection->getMethod("suite")->invoke(null)); } else { $this->addTest(new self($className)); } }
/** * Constructor * * @param string $translationClass * @param string $entityClass * @param string $field * * @throws \InvalidArgumentException */ public function __construct($translationClass, $entityClass, $field) { $refl = new \ReflectionClass($translationClass); if (!$refl->isSubClassOf('Akeneo\\Component\\Localization\\Model\\AbstractTranslation')) { throw new \InvalidArgumentException(sprintf('The translation class "%s" must extends "%s"', $translationClass, 'Akeneo\\Component\\Localization\\Model\\AbstractTranslation')); } $this->translationClass = $translationClass; $this->entityClass = $entityClass; $this->field = $field; }
/** * Constructor * * @param string $translationClass * @param string $entityClass * @param string $field * * @throws \InvalidArgumentException */ public function __construct($translationClass, $entityClass, $field) { $refl = new \ReflectionClass($translationClass); if (!$refl->isSubClassOf('Pim\\Bundle\\TranslationBundle\\Entity\\AbstractTranslation')) { throw new \InvalidArgumentException(sprintf('The translation class "%s" must extends "%s"', $translationClass, 'Pim\\Bundle\\TranslationBundle\\Entity')); } $this->translationClass = $translationClass; $this->entityClass = $entityClass; $this->field = $field; }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { if (!class_exists($arguments['class'])) { throw new InvalidArgumentException(sprintf('The class "%s" could not be found.', $arguments['class'])); } $r = new ReflectionClass($arguments['class']); if (0 !== strpos($r->getFilename(), sfConfig::get('sf_lib_dir'))) { throw new InvalidArgumentException(sprintf('The class "%s" is not located in the project lib/ directory.', $r->getName())); } $path = str_replace(sfConfig::get('sf_lib_dir'), '', dirname($r->getFilename())); $test = sfConfig::get('sf_test_dir') . '/unit' . $path . '/' . $r->getName() . 'Test.php'; if (file_exists($test)) { if ($options['force']) { $this->getFilesystem()->remove($test); } else { $this->logSection('task', sprintf('A test script for the class "%s" already exists.', $r->getName())); if (isset($options['editor-cmd'])) { $this->getFilesystem()->sh($options['editor-cmd'] . ' ' . $test); } return 1; } } $template = ''; $database = false; if (!$options['disable-defaults']) { if ($r->isSubClassOf('sfForm')) { $options['without-methods'] = true; if (!$r->isAbstract()) { $template = 'Form'; } } if (class_exists('Propel') && ($r->isSubclassOf('BaseObject') || 'Peer' == substr($r->getName(), -4) || $r->isSubclassOf('sfFormPropel')) || class_exists('Doctrine') && ($r->isSubclassOf('Doctrine_Record') || $r->isSubclassOf('Doctrine_Table') || $r->isSubclassOf('sfFormDoctrine')) || $r->isSubclassOf('sfFormFilter')) { $database = true; } } $tests = ''; if (!$options['without-methods']) { foreach ($r->getMethods() as $method) { if ($method->getDeclaringClass()->getName() == $r->getName() && $method->isPublic()) { $type = $method->isStatic() ? '::' : '->'; $tests .= <<<EOF // {$type}{$method->getName()}() \$t->diag('{$type}{$method->getName()}()'); EOF; } } } $this->getFilesystem()->copy(dirname(__FILE__) . sprintf('/skeleton/test/UnitTest%s.php', $template), $test); $this->getFilesystem()->replaceTokens($test, '##', '##', array('CLASS' => $r->getName(), 'TEST_DIR' => str_repeat('/..', substr_count($path, DIRECTORY_SEPARATOR) + 1), 'TESTS' => $tests, 'DATABASE' => $database ? "\n\$databaseManager = new sfDatabaseManager(\$configuration);\n" : '')); if (isset($options['editor-cmd'])) { $this->getFilesystem()->sh($options['editor-cmd'] . ' ' . $test); } }
/** * Inspects if current interface injector is to be used with a given class * * @param string $object * @return boolean */ public function supports($object) { if (is_string($object)) { $reflection = new \ReflectionClass($object); return $reflection->isSubClassOf($this->class) || $object === $this->class; } if (!is_object($object)) { throw new InvalidArgumentException(sprintf("%s expects class or object, %s given", __METHOD__, substr(str_replace("\n", '', var_export($object, true)), 0, 10))); } return is_a($object, $this->class); }
public function executeIndex(dmWebRequest $request) { $this->charts = array(); foreach ($this->getServiceContainer()->getServiceIds() as $serviceId) { if (substr($serviceId, -6) === '_chart') { $reflection = new ReflectionClass($this->getServiceContainer()->getParameter($serviceId . '.class')); if ($reflection->isSubClassOf('dmChart')) { $this->charts[substr($serviceId, 0, strlen($serviceId) - 6)] = $this->getServiceContainer()->getParameter($serviceId . '.options'); } } } $this->selectedIndex = array_search($request->getParameter('name'), array_keys($this->charts)); }
public function isAccept($state) { if (is_string($state) && class_exists($state)) { $checkClass = 'FormObject\\StateBase'; $newClass = new \ReflectionClass($state); if ($newClass->isSubClassOf($checkClass)) { return true; } } elseif ($state instanceof State) { return true; } return false; }
public function add($testName) { $dir = RUN_BASE . DS . "tests" . DS . "functional" . DS; $parts = explode("_", $testName); $last = array_pop($parts); if (count($parts) > 0) { $dir .= strtolower(implode(DS, $parts)) . DS; } $className = "Functional_" . $testName; Sabel::fileUsing($dir . $last . ".php", true); $reflection = new ReflectionClass($className); if ($reflection->isSubClassOf("Sabel_Test_TestSuite")) { $this->addTest($reflection->getMethod("suite")->invoke(null)); } else { $this->addTest(new self($className)); } }
private function onRegen() { // Grabing essential data about the board $boardType = $this->db->select("boards")->fields("boards", array("board_type"))->condition("board_name", $this->request['board'])->execute()->fetchField(); // Nope if ($boardType === false) { $this->errorMessage = sprintf(_gettext("Couldn't find board /%s/."), $this->request['board']); return false; } //Check against our built-in board types. if (in_array($boardType, array(0, 1, 2, 3))) { $types = array('image', 'text', 'oekaki', 'upload'); $module_to_load = $types[$boardType]; } else { $result = $this->db->select("modules")->fields("modules", array("module_variables", "module_directory"))->condition("module_application", 1)->execute()->fetchAll(); foreach ($result as $line) { $varibles = unserialize($line->module_variables); if (isset($variables['board_type_id']) && $variables['board_type_id'] == $boardType) { $module_to_load = $line->module_directory; } } } // Module loading time! $moduledir = kxFunc::getAppDir("board") . '/modules/public/' . $module_to_load . '/'; if (file_exists($moduledir . $module_to_load . '.php')) { require_once $moduledir . $module_to_load . '.php'; } // Some routine checks... $className = "public_board_" . $module_to_load . "_" . $module_to_load; if (class_exists($className)) { $module_class = new ReflectionClass($className); if ($module_class->isSubClassOf(new ReflectionClass('kxCmd'))) { $this->_boardClass = $module_class->newInstance($this->environment); $this->_boardClass->execute($this->environment); } else { $this->errorMessage = sprintf("Couldn't find module %s", $className); return false; } } $this->_boardClass->regeneratePages(); $this->_boardClass->regenerateThreads(); return true; }
/** * routing(className and methodName) by Hoimi\Request * * this is template method * subclass need to implement "resolveClassName" and "resolveMethodName" * @param Request $request * @return array(instance of Action, methodName) * @throws \RuntimeException * @throws Exception\NotFoundException */ public function run(Request $request) { $url = $request->parseUrl(); if (!isset($url['path']) || !$url['path']) { $url['path'] = '/'; } $className = $this->resolveClassName($request); if ($className === null || !class_exists($className)) { throw new NotFoundException('Unsupported class:' . $className); } $clazz = new \ReflectionClass($className); if (!$clazz->isSubClassOf('Hoimi\\BaseAction')) { throw new \RuntimeException('InvalidClass:' . $className); } $requestMethod = $this->resolveMethodName($request); if (!$clazz->hasMethod($requestMethod)) { throw new NotFoundException('unsupported method :' . $requestMethod . '@' . $url['path']); } $action = $clazz->newInstance(); return array($action, $requestMethod); }
/** * Looks for models in the application and extracts the validation messages * to be added to the translation map * * @return void */ protected function _extractValidationMessages() { if (!$this->_extractValidation) { return; } App::uses('AppModel', 'Model'); $plugin = null; if (!empty($this->params['plugin'])) { App::uses($this->params['plugin'] . 'AppModel', $this->params['plugin'] . '.Model'); $plugin = $this->params['plugin'] . '.'; } $models = App::objects($plugin . 'Model', null, false); foreach ($models as $model) { App::uses($model, $plugin . 'Model'); $reflection = new ReflectionClass($model); if (!$reflection->isSubClassOf('Model')) { continue; } $properties = $reflection->getDefaultProperties(); $validate = $properties['validate']; if (empty($validate)) { continue; } $file = $reflection->getFileName(); $domain = $this->_validationDomain; if (!empty($properties['validationDomain'])) { $domain = $properties['validationDomain']; } foreach ($validate as $field => $rules) { $this->_processValidationRules($field, $rules, $file, $domain); } } }
public function getLoadedTasks() { $parent = new ReflectionClass('Doctrine_Task'); $classes = get_declared_classes(); $tasks = array(); foreach ($classes as $className) { $class = new ReflectionClass($className); if ($class->isSubClassOf($parent)) { $task = str_replace('Doctrine_Task_', '', $className); $tasks[$task] = $task; } } return array_merge($this->_tasks, $tasks); }
/** * Get all the models which are a part of a plugin and the name of the plugin. * The array format is modelName => pluginName * * @todo This method is ugly and is a very weird way of finding the models which * belong to plugins. If we could come up with a better way that'd be great * @return array $pluginModels */ public function getPluginModels() { if (!$this->pluginModels) { $plugins = $this->_getPlugins(); foreach ($plugins as $plugin) { $path = sfConfig::get('sf_plugins_dir') . '/' . $plugin . '/lib/model/doctrine'; $models = sfFinder::type('file')->name('*.php')->in($path); foreach ($models as $path) { $info = pathinfo($path); $e = explode('.', $info['filename']); $modelName = substr($e[0], 6, strlen($e[0])); if (class_exists($e[0]) && class_exists($modelName)) { $parent = new ReflectionClass('Doctrine_Record'); $reflection = new ReflectionClass($modelName); if ($reflection->isSubClassOf($parent)) { $pluginName = basename(dirname(dirname(dirname($info['dirname'])))); $this->pluginModels[$modelName] = $pluginName; $generators = Doctrine::getTable($modelName)->getGenerators(); foreach ($generators as $generator) { $this->pluginModels[$generator->getOption('className')] = $pluginName; } } } } } } return $this->pluginModels; }
function resolveCommand($cmd) { $classroot = $this->controllerMap->getClassroot($cmd); $namespaceRoot = core\ApplicationRegistry::getNamespaceRoot(); $filepath = core\HelperFunctions::replaceSlashes("{$namespaceRoot}/command/{$classroot}.php"); $classname = "\\{$namespaceRoot}\\command\\{$classroot}"; if (file_exists($filepath)) { require_once $filepath; if (class_exists($classname)) { $cmd_class = new \ReflectionClass($classname); if ($cmd_class->isSubClassOf(self::$base_cmd)) { return $cmd_class->newInstance(); } } } return null; }
function resolveCommand($cmd) { $classroot = $this->controllerMap->getClassroot($cmd); $filepath = "woo/command/{$classroot}.php"; $classname = "\\woo\\command\\{$classroot}"; if (file_exists($filepath)) { require_once "{$filepath}"; if (class_exists($classname)) { $cmd_class = new \ReflectionClass($classname); if ($cmd_class->isSubClassOf(self::$base_cmd)) { return $cmd_class->newInstance(); } } } return null; }
/** * Returns TRUE if the specified class is a Task, or FALSE otherwise * * @param string $className * @return bool */ protected function classIsTask($className) { $reflectionClass = new ReflectionClass($className); return (bool) $reflectionClass->isSubClassOf(self::TASK_BASE_CLASS); }
/** * This method is used to list all reports in the index page. * You can overload this method in order to restrict access for the users to some reports. * * @return \yii\db\ActiveQuery */ public static function findReports() { if (get_called_class() !== 'reportmanager\\models\\Reports') { return static::find(); } $class = static::$module->reportModelClass; if (!$class) { throw new \yii\base\ErrorException('You need to specify reportModelClass variable in model ReportClass configuration.'); } $rc = new \ReflectionClass($class); if (!$rc->isSubClassOf('\\reportmanager\\models\\Reports')) { throw new \yii\base\ErrorException('The reportModelClass must be a child of \\reportmanager\\models\\Reports.'); } return $class::findReports(); }
/** * Retreive our command * * @access public * @param object kxEnv reference * @return object */ public function getCmd(kxEnv $environment) { $module = kxEnv::$current_module; $section = kxEnv::$current_section; // No module? if (!$module) { if (IN_MANAGE && !isset(kxEnv::$request['app'])) { $module = 'index'; } else { // Get the first module in the DB $module = kxDB::getInstance()->select("modules")->fields("modules", array("module_file"))->condition("module_application", KX_CURRENT_APP)->condition("module_manage", IN_MANAGE)->orderBy("module_position")->execute()->fetchField(); } } $moduledir = kxFunc::getAppDir(KX_CURRENT_APP) . '/modules/' . self::$class_dir . '/' . $module . '/'; // No section? if (!$section) { if (file_exists($moduledir . 'default_section.php')) { $defaultSection = ""; require $moduledir . 'default_section.php'; if ($defaultSection) { $section = $defaultSection; } } } // Are we in manage? if (IN_MANAGE) { // Load the logging class here because we'll probably need it anyway in pretty much any manage function require_once kxFunc::getAppDir('core') . '/classes/logging.php'; $environment->set('kx:classes:core:logging:id', new logging($environment)); $validSession = kxFunc::getManageSession(); if ((!isset($environment::$request['module']) || isset($environment::$request['module']) && $environment::$request['module'] != 'login') && !$validSession) { // Force login if we have an invalid session $environment::$request['module'] = 'login'; kxEnv::$current_module = 'login'; require_once kxFunc::getAppDir('core') . "/modules/manage/login/login.php"; $login = new manage_core_login_login($environment); $login->execute($environment); exit; } } // Ban check ( may as well do it here before we do any further processing) $boardName = ""; if (KX_CURRENT_APP == "core" && $module == "post" && $section == "post") { if (isset($environment->request) && isset($environment->request['board'])) { $boardName = $environment->{$request}['board']; } } kxBans::banCheck($_SERVER['REMOTE_ADDR'], $boardName); $className = self::$class_dir . '_' . KX_CURRENT_APP . '_' . $module . '_' . $section; if (file_exists($moduledir . $section . '.php')) { require_once $moduledir . $section . '.php'; } if (class_exists($className)) { $cmd_class = new ReflectionClass($className); if ($cmd_class->isSubClassOf(self::$baseCmd)) { return $cmd_class->newInstance(); } else { throw new kxException("{$section} in {$module} does not exist!"); } } //If we somehow made it here, let's just use the default command return clone self::$defaultCmd; }
function getCommand(\woo\controller\Request $request) { $cmd = $request->getProperty('cmd'); $sep = DIRECTORY_SEPARATOR; if (!$cmd) { return self::$default_cmd; } $cmd = str_replace(array('.', $sep), "", $cmd); $filepath = "woo{$sep}command{$sep}{$cmd}.php"; $classname = "woo\\command\\{$cmd}"; if (file_exists($filepath)) { @(require_once "{$filepath}"); if (class_exists($classname)) { $cmd_class = new ReflectionClass($classname); if ($cmd_class->isSubClassOf(self::$base_cmd)) { return $cmd_class->newInstance(); } else { $request->addFeedback("command '{$cmd}' is not a Command"); } } } $request->addFeedback("command '{$cmd}' not found"); return clone self::$default_cmd; }
/** * Retreive the command * * @access public * @param object ipsRegistry reference * @return object */ public function getCommand(ipsRegistry $registry) { $_NOW = IPSDebug::getMemoryDebugFlag(); $module = ipsRegistry::$current_module; $section = ipsRegistry::$current_section; $filepath = IPSLib::getAppDir(IPS_APP_COMPONENT) . '/' . self::$modules_dir . '/' . $module . '/'; /* Bug Fix #21009 */ if (!ipsRegistry::$applications[IPS_APP_COMPONENT]['app_enabled']) { throw new Exception("The specified application has been disabled"); } if (!IN_ACP and !IPSLib::moduleIsEnabled($module, IPS_APP_COMPONENT) and $module != 'ajax') { throw new Exception("The specified module has been disabled"); } /* Got a section? */ if (!$section) { if (is_file($filepath . 'defaultSection.php')) { $DEFAULT_SECTION = ''; include $filepath . 'defaultSection.php'; /*noLibHook*/ if ($DEFAULT_SECTION) { $section = $DEFAULT_SECTION; ipsRegistry::$current_section = $section; } } } $_classname = self::$class_dir . '_' . IPS_APP_COMPONENT . '_' . $module . '_'; /* Rarely used, let's leave file_exists which is faster for non-existent files */ if (file_exists($filepath . 'manualResolver.php')) { $classname = IPSLib::loadActionOverloader($filepath . 'manualResolver.php', $_classname . 'manualResolver'); } else { if (is_file($filepath . $section . '.php')) { $classname = IPSLib::loadActionOverloader($filepath . $section . '.php', $_classname . $section); } } IPSDebug::setMemoryDebugFlag("Controller getCommand executed"); if (class_exists($classname)) { $cmd_class = new ReflectionClass($classname); if ($cmd_class->isSubClassOf(self::$base_cmd)) { return $cmd_class->newInstance(); } else { throw new Exception("{$section} in {$module} does not exist!"); } } else { throw new Exception("{$classname} does not exist!"); } # Fudge it to return just the default object return clone self::$default_cmd; }
public function testInheritanceGeneration() { $path = dirname(__FILE__) . '/import_builder_test'; $import = new Doctrine_Import_Schema(); $import->setOption('generateTableClasses', true); $import->importSchema('schema.yml', 'yml', $path); $models = Doctrine_Core::loadModels($path, Doctrine_Core::MODEL_LOADING_CONSERVATIVE); $schemaTestInheritanceParent = new ReflectionClass('SchemaTestInheritanceParent'); $schemaTestInheritanceChild1 = new ReflectionClass('SchemaTestInheritanceChild1'); $schemaTestInheritanceChild2 = new ReflectionClass('SchemaTestInheritanceChild2'); $schemaTestInheritanceParentTable = new ReflectionClass('SchemaTestInheritanceParentTable'); $schemaTestInheritanceChild1Table = new ReflectionClass('SchemaTestInheritanceChild1Table'); $schemaTestInheritanceChild2Table = new ReflectionClass('SchemaTestInheritanceChild2Table'); $this->assertTrue($schemaTestInheritanceParent->isSubClassOf('Doctrine_Record')); $this->assertTrue($schemaTestInheritanceParent->isSubClassOf('BaseSchemaTestInheritanceParent')); $this->assertTrue($schemaTestInheritanceParent->isSubClassOf('PackageSchemaTestInheritanceParent')); $this->assertTrue($schemaTestInheritanceChild1->isSubClassOf('BaseSchemaTestInheritanceChild1')); $this->assertTrue($schemaTestInheritanceChild2->isSubClassOf('BaseSchemaTestInheritanceChild2')); $this->assertTrue($schemaTestInheritanceChild1->isSubClassOf('SchemaTestInheritanceParent')); $this->assertTrue($schemaTestInheritanceChild1->isSubClassOf('BaseSchemaTestInheritanceParent')); $this->assertTrue($schemaTestInheritanceChild2->isSubClassOf('SchemaTestInheritanceParent')); $this->assertTrue($schemaTestInheritanceChild2->isSubClassOf('BaseSchemaTestInheritanceParent')); $this->assertTrue($schemaTestInheritanceChild2->isSubClassOf('SchemaTestInheritanceChild1')); $this->assertTrue($schemaTestInheritanceChild2->isSubClassOf('BaseSchemaTestInheritanceChild1')); $this->assertTrue($schemaTestInheritanceChild2->isSubClassOf('PackageSchemaTestInheritanceParent')); $this->assertTrue($schemaTestInheritanceParentTable->isSubClassOf('Doctrine_Table')); $this->assertTrue($schemaTestInheritanceChild1Table->isSubClassOf('SchemaTestInheritanceParentTable')); $this->assertTrue($schemaTestInheritanceChild1Table->isSubClassOf('PackageSchemaTestInheritanceParentTable')); $this->assertTrue($schemaTestInheritanceChild2Table->isSubClassOf('SchemaTestInheritanceParentTable')); $this->assertTrue($schemaTestInheritanceChild2Table->isSubClassOf('PackageSchemaTestInheritanceParentTable')); $this->assertTrue($schemaTestInheritanceChild2Table->isSubClassOf('SchemaTestInheritanceChild1Table')); $this->assertTrue($schemaTestInheritanceChild2Table->isSubClassOf('PackageSchemaTestInheritanceChild1Table')); # Simple Inheritance $schemaTestSimpleInheritanceParent = new ReflectionClass('SchemaTestSimpleInheritanceParent'); $schemaTestSimpleInheritanceChild = new ReflectionClass('SchemaTestSimpleInheritanceChild'); $this->assertTrue($schemaTestSimpleInheritanceParent->hasMethod('setTableDefinition')); $this->assertTrue($schemaTestSimpleInheritanceChild->isSubClassOf('SchemaTestSimpleInheritanceParent')); # Class Table Inheritance $schemaTestClassTableInheritanceParent = new ReflectionClass('SchemaTestClassTableInheritanceParent'); $schemaTestClassTableInheritanceChild = new ReflectionClass('SchemaTestClassTableInheritanceChild'); # Concrete Inheritance $schemaTestConcreteInheritanceParent = new ReflectionClass('SchemaTestConcreteInheritanceParent'); $schemaTestConcreteInheritanceChild = new ReflectionClass('SchemaTestConcreteInheritanceChild'); # Column Aggregation Inheritance $schemaTestColumnAggregationInheritanceParent = new ReflectionClass('SchemaTestColumnAggregationInheritanceParent'); $schemaTestColumnAggregationInheritanceChild = new ReflectionClass('SchemaTestColumnAggregationInheritanceChild'); $sql = Doctrine_Core::generateSqlFromArray(array('SchemaTestSimpleInheritanceParent', 'SchemaTestSimpleInheritanceChild')); $this->assertEqual(count($sql), 1); $this->assertEqual($sql[0], 'CREATE TABLE schema_test_simple_inheritance_parent (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(255), description VARCHAR(255))'); $sql = Doctrine_Core::generateSqlFromArray(array('SchemaTestClassTableInheritanceParent', 'SchemaTestClassTableInheritanceChild')); $this->assertEqual(count($sql), 2); $this->assertEqual($sql[0], 'CREATE TABLE schema_test_class_table_inheritance_parent (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(255))'); $this->assertEqual($sql[1], 'CREATE TABLE schema_test_class_table_inheritance_child (id INTEGER, title VARCHAR(255), description VARCHAR(255), PRIMARY KEY(id))'); $sql = Doctrine_Core::generateSqlFromArray(array('SchemaTestConcreteInheritanceParent', 'SchemaTestConcreteInheritanceChild')); $this->assertEqual(count($sql), 2); $this->assertEqual($sql[0], 'CREATE TABLE schema_test_concrete_inheritance_parent (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(255))'); $this->assertEqual($sql[1], 'CREATE TABLE schema_test_concrete_inheritance_child (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(255), title VARCHAR(255), description VARCHAR(255))'); $sql = Doctrine_Core::generateSqlFromArray(array('SchemaTestColumnAggregationInheritanceParent', 'SchemaTestColumnAggregationInheritanceChild')); $this->assertEqual(count($sql), 2); $this->assertEqual($sql[0], 'CREATE TABLE schema_test_column_aggregation_inheritance_parent (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(255), type VARCHAR(255), title VARCHAR(255), description VARCHAR(255))'); $this->assertEqual($sql[1], 'CREATE INDEX schema_test_column_aggregation_inheritance_parent_type_idx ON schema_test_column_aggregation_inheritance_parent (type)'); Doctrine_Lib::removeDirectories($path); }
/** * Создание экземпляра контролера на основе имени контролера. * * @param string $nameController. * @return object контролер */ private function createController($nameController) { $this->executingController = null; if (BaseService::isNotString($nameController)) { throw new FrmworkExcep\InvalidArgumentException(self::$msgForInvalidArgExcp, Routing::class, __METHOD__, '$nameController', 'string'); } $className = NamespaceController::class . "\\{$nameController}"; $filepath = '..' . DIRECTORY_SEPARATOR . 'framework' . DIRECTORY_SEPARATOR . 'controllers' . DIRECTORY_SEPARATOR . $nameController . '.php'; if (!file_exists($filepath)) { throw new FrmworkExcep\FileNotFoundException(self::$msgForCreateObjExcp . $nameController . '" из файлa "' . $filepath . '.php".', Routing::class, __METHOD__); } if (!class_exists($className)) { throw new FrmworkExcep\RunTimeException(self::$msgForCreateObjExcp . $nameController . '".', Routing::class, __METHOD__, 'Проверьте ' . $className); } $controllerClass = new \ReflectionClass($className); if (!self::$baseController) { self::$baseController = new \ReflectionClass(NamespaceController::class . '\\ControllerBase'); } if (!$controllerClass->isSubClassOf(self::$baseController)) { throw new FrmworkExcep\RunTimeException(self::$msgForCreateObjExcp . $nameController . '".', Routing::class, __METHOD__, 'Класс контролера должен быть потомком ControllerBase.'); } try { // создание экземпляра контролера по имени $nameController: $this->executingController = $controllerClass->newInstance($this); return $this->executingController; } catch (\Exception $ex) { throw new FrmworkExcep\CreateObjectException('Невозможно создать экземпляр класса "' . $className . '" ' . $ex->getMessage(), Routing::class, __METHOD__); } }
/** * Checks if what is passed is a valid Doctrine_Record * Will load class in to memory in order to inflect it and find out information about the class * * @param mixed $class Can be a string named after the class, an instance of the class, or an instance of the class reflected * @return boolean */ public static function isValidModelClass($class) { if ($class instanceof Doctrine_Record) { $class = get_class($class); } if (is_string($class) && class_exists($class)) { $class = new ReflectionClass($class); } if ($class instanceof ReflectionClass) { // Skip the following classes // - abstract classes // - not a subclass of Doctrine_Record if (!$class->isAbstract() && $class->isSubClassOf('Doctrine_Record')) { return true; } } return false; }
/** * Get all the models which are a part of a plugin and the name of the plugin. * The array format is modelName => pluginName * * @todo This method is ugly and is a very weird way of finding the models which * belong to plugins. If we could come up with a better way that'd be great * @return array $pluginModels */ public function getPluginModels() { if (!$this->pluginModels) { $plugins = $this->generatorManager->getConfiguration()->getPlugins(); $pluginPaths = $this->generatorManager->getConfiguration()->getAllPluginPaths(); foreach ($pluginPaths as $pluginName => $path) { if (!in_array($pluginName, $plugins)) { continue; } foreach (sfFinder::type('file')->name('*.php')->in($path . '/lib/model/doctrine') as $path) { $info = pathinfo($path); $e = explode('.', $info['filename']); $modelName = substr($e[0], 6, strlen($e[0])); if (class_exists($e[0]) && class_exists($modelName)) { $parent = new ReflectionClass('Doctrine_Record'); $reflection = new ReflectionClass($modelName); if ($reflection->isSubClassOf($parent)) { $this->pluginModels[$modelName] = $pluginName; if ($reflection->isInstantiable()) { $generators = Doctrine_Core::getTable($modelName)->getGenerators(); foreach ($generators as $generator) { $this->pluginModels[$generator->getOption('className')] = $pluginName; } } } } } } } return $this->pluginModels; }
/** * Retreive the command * * @access public * @param object ipsRegistry reference * @return object */ public function getCommand(ipsRegistry $registry) { $_NOW = IPSDebug::getMemoryDebugFlag(); $module = ipsRegistry::$current_module; $section = ipsRegistry::$current_section; $filepath = IPSLib::getAppDir(IPS_APP_COMPONENT) . '/' . self::$modules_dir . '/' . $module . '/'; /* Got a section? */ if (!$section) { if (file_exists($filepath . 'defaultSection.php')) { $DEFAULT_SECTION = ''; require $filepath . 'defaultSection.php'; if ($DEFAULT_SECTION) { $section = $DEFAULT_SECTION; } } } $classname = self::$class_dir . '_' . IPS_APP_COMPONENT . '_' . $module . '_' . $section; if (file_exists($filepath . 'manualResolver.php')) { require_once $filepath . 'manualResolver.php'; $classname = self::$class_dir . '_' . IPS_APP_COMPONENT . '_' . $module . '_manualResolver'; } else { if (file_exists($filepath . $section . '.php')) { require_once $filepath . $section . '.php'; } } /* Hooks: Are we overloading this class? */ $hooksCache = ipsRegistry::cache()->getCache('hooks'); if (isset($hooksCache['commandHooks']) and is_array($hooksCache['commandHooks']) and count($hooksCache['commandHooks'])) { foreach ($hooksCache['commandHooks'] as $hook) { foreach ($hook as $classOverloader) { /* Hooks: Do we have a hook that extends this class? */ if ($classOverloader['classToOverload'] == $classname) { if (file_exists(DOC_IPS_ROOT_PATH . 'hooks/' . $classOverloader['filename'])) { /* Hooks: Do we have the hook file? */ require_once DOC_IPS_ROOT_PATH . 'hooks/' . $classOverloader['filename']; if (class_exists($classOverloader['className'])) { /* Hooks: We have the hook file and the class exists - reset the classname to load */ $classname = $classOverloader['className']; } } } } } } IPSDebug::setMemoryDebugFlag("Controller getCommand executed", $_NOW); if (class_exists($classname)) { $cmd_class = new ReflectionClass($classname); if ($cmd_class->isSubClassOf(self::$base_cmd)) { return $cmd_class->newInstance(); } else { throw new Exception("{$section} in {$module} does not exist!"); } } # Fudge it to return just the default object return clone self::$default_cmd; }
/** * Get the command * * @access public * @param object ipsRegistry reference * @return object Command object */ public function getCommand(ipsRegistry $registry) { $module = ipsRegistry::$current_module; $section = ipsRegistry::$current_section; $filepath = IPS_IS_UPGRADER ? IPS_ROOT_PATH . 'setup/applications/upgrade/sections/' : IPS_ROOT_PATH . 'setup/applications/install/sections/'; /* Got a section? */ if (!$section) { if (is_file($filepath . 'index.php')) { $section = 'index'; } } $classname = IPS_APP_COMPONENT . '_' . $section; if (is_file($filepath . 'manualResolver.php')) { require_once $filepath . 'manualResolver.php'; /*noLibHook*/ $classname = IPS_APP_COMPONENT . '_' . $module . '_manualResolver'; } else { if (is_file($filepath . $section . '.php')) { require_once $filepath . $section . '.php'; /*noLibHook*/ } } if (class_exists($classname)) { $cmd_class = new ReflectionClass($classname); if ($cmd_class->isSubClassOf(self::$base_cmd)) { return $cmd_class->newInstance(); } else { throw new Exception("{$section} в модуле {$module} не существует!"); } } # Fudge it to return just the default object return clone self::$default_cmd; }
/** * Initializes the in-memory table definition. * * @param string $name */ public function initDefinition() { $name = $this->_options['name']; if (!class_exists($name) || empty($name)) { throw new Doctrine_Exception("Couldn't find class " . $name); } $record = new $name($this); $names = array(); $class = $name; // get parent classes do { if ($class === 'Doctrine_Record') { break; } $name = $class; $names[] = $name; } while ($class = get_parent_class($class)); if ($class === false) { throw new Doctrine_Table_Exception('Class "' . $name . '" must be a child class of Doctrine_Record'); } // reverse names $names = array_reverse($names); // save parents array_pop($names); $this->_options['parents'] = $names; // create database table if (method_exists($record, 'setTableDefinition')) { $record->setTableDefinition(); // get the declaring class of setTableDefinition method $method = new ReflectionMethod($this->_options['name'], 'setTableDefinition'); $class = $method->getDeclaringClass(); } else { $class = new ReflectionClass($class); } $this->_options['joinedParents'] = array(); foreach (array_reverse($this->_options['parents']) as $parent) { if ($parent === $class->getName()) { continue; } $ref = new ReflectionClass($parent); if ($ref->isAbstract() || !$class->isSubClassOf($parent)) { continue; } $parentTable = $this->_conn->getTable($parent); $found = false; $parentColumns = $parentTable->getColumns(); foreach ($parentColumns as $columnName => $definition) { if (!isset($definition['primary']) || $definition['primary'] === false) { if (isset($this->_columns[$columnName])) { $found = true; break; } else { if (!isset($parentColumns[$columnName]['owner'])) { $parentColumns[$columnName]['owner'] = $parentTable->getComponentName(); } $this->_options['joinedParents'][] = $parentColumns[$columnName]['owner']; } } else { unset($parentColumns[$columnName]); } } if ($found) { continue; } foreach ($parentColumns as $columnName => $definition) { $fullName = $columnName . ' as ' . $parentTable->getFieldName($columnName); $this->setColumn($fullName, $definition['type'], $definition['length'], $definition, true); } break; } $this->_options['joinedParents'] = array_values(array_unique($this->_options['joinedParents'])); $this->_options['declaringClass'] = $class; // set the table definition for the given tree implementation if ($this->isTree()) { $this->getTree()->setTableDefinition(); } $this->columnCount = count($this->_columns); if (!isset($this->_options['tableName'])) { $this->setTableName(Doctrine_Inflector::tableize($class->getName())); } return $record; }
public function exec(kxEnv $environment) { // Before we do anything, let's check if we even have any board info if (!$this->request['board']) { die; kxFunc::doRedirect(kxEnv::Get('kx:paths:main:webpath')); } // Grabing essential data about the board $boardType = $this->db->select("boards")->fields("boards", array("board_type"))->condition("board_name", $this->request['board'])->execute()->fetchField(); // Uh oh! Someone's being naughty! Silently redirect them to the mainpage if they supply us with a non-existing board. if ($boardType === false) { kxFunc::doRedirect(kxEnv::Get('kx:paths:main:webpath')); } //Check against our built-in board types. if (in_array($boardType, array(0, 1, 2, 3))) { $types = array('image', 'text', 'oekaki', 'upload'); $module_to_load = $types[$boardType]; } else { $result = $this->db->select("modules")->fields("modules", array("module_variables", "module_directory"))->condition("module_application", 1)->execute()->fetchAll(); foreach ($result as $line) { $varibles = unserialize($line->module_variables); if (isset($variables['board_type_id']) && $variables['board_type_id'] == $boardType) { $module_to_load = $line->module_directory; } } } // Module loading time! $moduledir = kxFunc::getAppDir("board") . '/modules/public/' . $module_to_load . '/'; if (file_exists($moduledir . $module_to_load . '.php')) { require_once $moduledir . $module_to_load . '.php'; } else { kxFunc::doRedirect(kxEnv::Get('kx:paths:main:webpath')); } // Some routine checks... $className = "public_board_" . $module_to_load . "_" . $module_to_load; if (class_exists($className)) { $module_class = new ReflectionClass($className); if ($module_class->isSubClassOf(new ReflectionClass('kxCmd'))) { $this->_boardClass = $module_class->newInstance($this->environment); $this->_boardClass->execute($this->environment); } else { kxFunc::doRedirect(kxEnv::Get('kx:paths:main:webpath')); } } else { kxFunc::doRedirect(kxEnv::Get('kx:paths:main:webpath')); } // Include our posting class require_once kxFunc::getAppDir('core') . '/classes/posting.php'; $this->_postingClass = new posting($this->environment); $this->environment->set('kx:classes:board:posting:id', $this->_postingClass); // Phew, that's over with. Let's now prepare our post for generation. //Are we UTF-8? $this->_postingClass->checkUTF8(); // Is post valid according to our board's spec? if ($this->_boardClass->validPost()) { $this->db->startTransaction(); // Do we have files? $this->postData['files'] = isset($_FILES['imagefile']) ? $_FILES['imagefile']['name'] : ''; // Backwards compatability hack for dumpers that don't support multifile uploading if ($this->postData['files'] && !is_array($this->postData['files'])) { foreach ($_FILES['imagefile'] as $key => $value) { $_FILES['imagefile'][$key] = array($value); } $this->postData['files'] = array($_FILES['imagefile']['name'][0]); } $this->postData['is_reply'] = $this->_postingClass->isReply($this->_boardClass->board->board_id); $this->_postingClass->checkPostingTime($this->postData['is_reply'], $this->_boardClass->board->board_id); $this->_postingClass->checkMessageLength($this->_boardClass->board->max_message_length); $this->_postingClass->checkBlacklistedText($this->_boardClass->board->board_id); $this->_postingClass->checkCaptcha($this->_boardClass->board, $this->postData); $this->_postingClass->checkBannedHash($this->_boardClass->board); //How many replies, is the thread locked, etc if ($this->postData['is_reply']) { $this->postData['thread_info'] = $this->_postingClass->threadInfo($this->_boardClass->board_id, $this->request['replythread']); } else { $this->postData['thread_info'] = array('replies' => 0, 'locked' => 0, 'parent' => 0); } // Subject, email, etc fields need special processing $this->postData['post_fields'] = $this->_postingClass->parseFields(); $this->postData['post_fields']['postpassword'] = isset($this->request['postpassword']) ? $this->request['postpassword'] : ''; $nextid = $this->db->select("posts")->fields("posts", array("post_id"))->condition("post_board", $this->_boardClass->board->board_id)->execute()->fetchField(); if ($nextid) { $this->postData['next_id'] = $nextid + 1; } else { $this->postData['next_id'] = 1; } // Are we modposting? $this->postData['user_authority'] = $this->_postingClass->userAuthority(); if (isset($this->request['displaystaffstatus'])) { $this->postData['flags'] .= 'D'; } if (isset($this->request['lockonpost'])) { $this->postData['flags'] .= 'L'; } if (isset($this->request['stickyonpost'])) { $this->postData['flags'] .= 'S'; } if (isset($this->request['rawhtml'])) { $this->postData['flags'] .= 'RH'; } if (isset($this->request['usestaffname'])) { $this->postData['flags'] .= 'N'; } $this->postData['display_status'] = 0; $this->postData['lock_on_post'] = 0; $this->postData['sticky_on_post'] = 0; // If they are just a normal user, or vip... if ($this->postData['user_authority'] == 0 || $this->postData['user_authority'] > 2) { // If the thread is locked if ($this->postData['thread_info']['locked'] == 1) { // Don't let the user post kxFunc::showError(_gettext('Sorry, this thread is locked and can not be replied to.')); } $this->postData['thread_info']['message'] = $this->_boardClass->parseData($this->request['message']); // Or, if they are a moderator/administrator... } else { // If they checked the D checkbox, set the variable to tell the script to display their staff status (Admin/Mod) on the post during insertion if (isset($this->request['displaystaffstatus'])) { $this->postData['display_status'] = true; } // If they checked the RH checkbox, set the variable to tell the script to insert the post as-is... if (isset($this->request['rawhtml'])) { $this->postData['thread_info']['message'] = $this->request['message']; // Otherwise, parse it as usual... } else { $this->postData['thread_info']['message'] = $this->_boardClass->parseData($this->request['message']); } // If they checked the L checkbox, set the variable to tell the script to lock the post after insertion if (isset($this->request['lockonpost'])) { $this->postData['lock_on_post'] = true; } // If they checked the S checkbox, set the variable to tell the script to sticky the post after insertion if (isset($this->request['stickyonpost'])) { $this->postData['sticky_on_post'] = true; } if (isset($this->request['usestaffname'])) { $_POST['name'] = kxFunc::md5_decrypt($this->request['modpassword'], kxEnv::Get('kx:misc:randomseed')); $post_name = kxFunc::md5_decrypt($this->request['modpassword'], kxEnv::Get('kx:misc:randomseed')); } } //kxFunc::checkBadUnicode($this->postData['post_fields']); $this->_boardClass->processPost($this->postData); $url = kxEnv::Get("kx:paths:boards:path") . '/' . $this->_boardClass->board->board_name; if (!$this->postData['is_reply']) { $url .= '/' . kxEnv::Get('kx:pages:first'); } else { $url .= '/res/' . intval($this->request['replythread']) . '.html'; } @header('Location: ' . $url); } }