protected function getActionsInDirectory($dir) { $classNames = array(); $recIt = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir)); $regexIt = new \RegexIterator($recIt, '/^.+\\.php$/i', \RecursiveRegexIterator::GET_MATCH); foreach ($regexIt as $entry) { $info = \helpers_PhpTools::getClassInfo($entry[0]); $fullname = empty($info['ns']) ? $info['class'] : $info['ns'] . '\\' . $info['class']; if (!in_array($fullname, self::$blackList) && is_subclass_of($fullname, Action::class)) { $classNames[] = $fullname; } } return $classNames; }
/** * get all modules of the extension * by searching the actions directory, not the ontology * * @access public * @author firstname and lastname of author, <*****@*****.**> * @return array */ public function getAllModules() { $returnValue = array(); // routes $namespaces = array(); foreach ($this->getManifest()->getRoutes() as $mapedPath => $ns) { $namespaces[] = trim($ns, '\\'); } if (!empty($namespaces)) { common_Logger::d('Namespace not empty for extension ' . $this->getId()); $recDir = new RecursiveDirectoryIterator($this->getDir()); $recIt = new RecursiveIteratorIterator($recDir); $regexIt = new RegexIterator($recIt, '/^.+\\.php$/i', RecursiveRegexIterator::GET_MATCH); foreach ($regexIt as $entry) { $info = helpers_PhpTools::getClassInfo($entry[0]); if (!empty($info['ns'])) { $ns = trim($info['ns'], '\\'); if (!empty($info['ns']) && in_array($ns, $namespaces)) { $returnValue[$info['class']] = $ns . '\\' . $info['class']; } } } } // legacy if ($this->hasConstant('DIR_ACTIONS') && file_exists($this->getConstant('DIR_ACTIONS'))) { $dir = new DirectoryIterator($this->getConstant('DIR_ACTIONS')); foreach ($dir as $fileinfo) { if (preg_match('/^class\\.[^.]*\\.php$/', $fileinfo->getFilename())) { $module = substr($fileinfo->getFilename(), 6, -4); $returnValue[$module] = $this->getId() . '_actions_' . $module; } } } // validate the classes foreach (array_keys($returnValue) as $key) { $class = $returnValue[$key]; if (!class_exists($class)) { common_Logger::w($class . ' not found'); unset($returnValue[$key]); } elseif (!is_subclass_of($class, 'Module')) { common_Logger::w($class . ' does not inherit Module'); unset($returnValue[$key]); } } return (array) $returnValue; }