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