/** * get callable module list * * @return array */ public function getCallableModules() { $dirIterator = new \RecursiveDirectoryIterator($this->path, \FilesystemIterator::NEW_CURRENT_AND_KEY | \FilesystemIterator::SKIP_DOTS); $modules = array(); foreach ($dirIterator as $k => $v) { $doVotedModule = false; if ($dirIterator->hasChildren()) { foreach ($dirIterator->getChildren() as $key => $value) { $entension = $value->getExtension(); if (!$entension || 'php' !== $entension) { continue; } $fileBasename = $value->getBasename('.php'); $module_to_be = $v->getBasename(); $expectedClassName = $this->baseNamespace . NAMESPACE_SEPARATOR . $module_to_be . NAMESPACE_SEPARATOR . $fileBasename; Loader::getInstance()->import($value->__toString()); if (!class_exists($expectedClassName, false)) { // not a standard class file! continue; } if (!$doVotedModule) { $modules[] = $module_to_be; $doVotedModule = true; } } } } return $modules; }
/** * $path: user/profile.json * * @param $path * @param Request $request * @param Response $response * @return bool|\Closure */ public function apply(&$path, Request &$request, Response &$response) { if (false !== ($postfixPos = strrpos($path, '.'))) { $realPath = substr($path, 0, $postfixPos); $postfix = substr($path, $postfixPos + 1); if ($postfix == $this->_ruleStr) { $path = $realPath; Loader::getInstance()->import("lib/Hydrogen/Http/Response/MIME.php"); // automatically setup Content-type if (null !== ($content_type = getMIMEheader($postfix))) { $response->withHeader(HTTP_HEADER_CONTENT_TYPE, $content_type); } $this->performCallback(); } } return false; }
<?php \Hydrogen\Load\Loader::getInstance()->import('application/module/ModuleInit.php'); $EXE = \Hydrogen\Application\Execute\Executor::getInstance(); $baseModuleNS = 'application\\module\\front'; foreach (array('ctrl') as $registry) { $EXE->setNamespaceDir($baseModuleNS . '\\' . $registry, APPLICATION_PATH . '/module/front/' . $registry, true); }
private function importFileByAbsPath($absPath) { if (!file_exists($absPath)) { return false; } if (false === Loader::getInstance()->import($absPath)) { throw new LoadFailedException('Failed to load file: ' . $absPath); } return true; }