/** * @return NodeTraverser */ public static function getTraverser() { $traverser = new StackVarNodeTraverser(); // Find Path $reflector = new \Reflectionclass(__CLASS__); $path = $reflector->getFileName(); $path = dirname($path); // Generate base FQCN and path based on the current file $baseFqcn = __CLASS__; $baseFqcn = explode('\\', $baseFqcn); $baseFqcn[count($baseFqcn) - 1] = 'Visitors'; $baseFqcn = implode('\\', $baseFqcn); $baseFqcnPath = dirname(__FILE__) . "/Visitors/"; // Iterate node visitors and add them to the traverser $it = new \RecursiveDirectoryIterator($path . '/Visitors', \RecursiveDirectoryIterator::SKIP_DOTS); $it = new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::LEAVES_ONLY); foreach ($it as $fileInfo) { /* @var \SplFileInfo $fileInfo */ // Convert path into FQCN $class = $fileInfo->getPathname(); $class = str_replace($baseFqcnPath, "", $class); $class = str_replace('.php', '', $class); $class = str_replace('/', '\\', $class); $fqcn = $baseFqcn . '\\' . $class; $traverser->addVisitor(new $fqcn()); } return $traverser; }
/** * Return class instance * @return static **/ static function instance() { if (!Registry::exists($class = get_called_class())) { $ref = new Reflectionclass($class); $args = func_get_args(); Registry::set($class, $args ? $ref->newinstanceargs($args) : new $class()); } return Registry::get($class); }
public function getProperties($obj) { $reflect = new \Reflectionclass($obj); if ($reflect->isInternal()) { return $obj; } $read = $this->readClosure->bindTo($obj, $obj); return $read(); }
/** * Returns a class instance **/ static function instance() { $storage = new \Core\Storage(); $classes = $storage->get('CORE.instantiable') ?: []; if (!isset($classes[$class = get_called_class()])) { $ref = new \Reflectionclass($class); $args = func_get_args(); $classes[$class] = $args ? $ref->newinstanceargs($args) : new $class(); $storage->set('CORE.instantiable', $classes); } return $classes[$class] ?: null; }
/** * Registers an array of task objects. * * If you pass null, this method will register all available tasks. * * @param array $tasks An array of tasks */ public function registerTasks($tasks = null) { if (is_null($tasks)) { $tasks = array(); foreach (get_declared_classes() as $class) { $r = new Reflectionclass($class); if ($r->isSubclassOf('sfTask') && !$r->isAbstract()) { $tasks[] = new $class($this->dispatcher, $this->formatter); } } } foreach ($tasks as $task) { $this->registerTask($task); } }
/** * @param string $mod module name * @return bool */ public function batchConnect($mod_name = null) { $mods = array(); if (null !== $mod_name) { $mods[] = $mod_name; } else { $extensionService = $this->di['mod_service']('extension'); $mods = $extensionService->getCoreAndActiveModules(); } foreach ($mods as $m) { $mod = $this->di['mod']($m); if ($mod->hasService()) { $class = $mod->getService(); $reflector = new \Reflectionclass($class); foreach ($reflector->getMethods() as $method) { $p = $method->getParameters(); if ($method->isPublic() && isset($p[0]) && $p[0]->getclass() && in_array($p[0]->getclass()->getName(), array('Box_Event', '\\Box_Event'))) { $this->connect(array('event' => $method->getName(), 'mod' => $mod->getName())); } } } } $this->_disconnectUnavailable(); return true; }
/** * Reloads tasks. * * Useful when you install plugins with tasks and if you want to use them with the runTask() method. */ protected function reloadTasks() { if (null === $this->commandApplication) { return; } $this->configuration = $this->createConfiguration(null, null); $this->commandApplication->clearTasks(); $this->commandApplication->loadTasks($this->configuration); $disabledPluginsRegex = sprintf('#^(%s)#', implode('|', array_diff($this->configuration->getAllPluginPaths(), $this->configuration->getPluginPaths()))); $tasks = array(); foreach (get_declared_classes() as $class) { $r = new Reflectionclass($class); if ($r->isSubclassOf('sfTask') && !$r->isAbstract() && !preg_match($disabledPluginsRegex, $r->getFileName())) { $tasks[] = new $class($this->dispatcher, $this->formatter); } } $this->commandApplication->registerTasks($tasks); }
/** * Load tasks from the passed directory. If no directory is given it looks in the default * Doctrine/Task folder for the core tasks. * * @param mixed $directory Can be a string path or array of paths * @return array $loadedTasks Array of tasks loaded */ public function loadTasks($directory = null) { if ($directory === null) { $directory = Doctrine::getPath() . DIRECTORY_SEPARATOR . 'Doctrine' . DIRECTORY_SEPARATOR . 'Task'; } $parent = new ReflectionClass('Doctrine_Task'); $tasks = array(); if (is_dir($directory)) { foreach ((array) $directory as $dir) { $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::LEAVES_ONLY); foreach ($it as $file) { $e = explode('.', $file->getFileName()); if (end($e) === 'php' && strpos($file->getFileName(), '.inc') === false) { $className = 'Doctrine_Task_' . $e[0]; if (!class_exists($className)) { require_once $file->getPathName(); $class = new ReflectionClass($className); if ($class->isSubClassOf($parent)) { $tasks[$e[0]] = $e[0]; } } } } } } $classes = get_declared_classes(); foreach ($classes as $className) { $class = new Reflectionclass($className); if ($class->isSubClassOf($parent)) { $task = str_replace('Doctrine_Task_', '', $className); $tasks[$task] = $task; } } $this->_tasks = array_merge($this->_tasks, $tasks); return $this->_tasks; }
protected function model($name) { if (isset(self::$_models[$name])) { return self::$_models[$name]; } $class = APP_NAMESPACE . '\\Models\\' . $name; $ref = new \Reflectionclass($class); $args = array_slice(func_get_args(), 1); self::$_models[$name] = $args ? $ref->newinstanceargs($args) : new $class(); return self::$_models[$name]; }