/** * @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; }
/** * 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); }