/** * @param $path */ function load_user_application($path) { if (is_dir($path)) { $libs_path = $path . "/libs"; // include model dir_include_all($libs_path . "/model", function ($file) { $model_name = pathinfo($file, PATHINFO_FILENAME); \PMP\ModelManager::add($model_name); }); dir_include_all($libs_path . "/include"); dir_include_all($libs_path . "/conf"); if ($dh = opendir($path)) { while (($file = readdir($dh)) !== false) { if ($file != "." && $file != "..") { load_application_model($path . "/" . $file); } } closedir($dh); } } }
/** * request to load controller */ static function action() { // benchmark $benchmark = new Benchmark(); $benchmark->start(); $request = new Request(); $request->setBaseUri(Application::getBaseUrl()); // auth checkc if (self::$auth) { foreach (self::$auth as $auth) { $auth->check($request->getUri()); } } $routing = new Routing(); if (!($data = $routing::getRouleClass($request->getUri()))) { if ($data = $routing::getRouleClass($request->getUri() . '/')) { Server::redirect(Application::getBaseUrl() . $request->getUri() . '/'); } } if (empty($data)) { $data = array('class' => 'core:default:error_404'); } else { if ($data['class'] == '') { $data = array('class' => 'core:default:index'); } } // pearse class method if (preg_match("/^([0-9a-zA-Z\\-_]+):([0-9a-zA-Z\\-_]+):?([0-9a-zA-Z\\-_]*)\$/", $data['class'], $matchs)) { $project = $matchs[1]; $class = $matchs[2]; $method = $matchs[3]; $method = !empty($method) ? $method : "index"; } else { throw new PMPException('Error Class Method or Class Name(`' . $data['class'] . '` is not routing find).'); } $benchmark->setMark("routing"); try { $path = self::$source_dir . '/' . $project; $filename = $path . '/conf'; dir_include_all($filename); $filename = $path . '/class'; dir_include_all($filename); $filename = $path . '/controller/' . $class . '.php'; if (file_exists($filename)) { include_once $filename; } else { $path = dirname(__FILE__) . '/../../component'; $filename = $path . '/controller/' . $class . '.php'; if (file_exists($filename)) { include_once $filename; } } $classname = $class . 'Controller'; $controller = new $classname($path, $class, $method, $project); $controller->addDefaultTemplatefiles(dirname(__FILE__) . '/../../component/view/form.tpl'); $benchmark->setMark('included'); if (isset($data['param'])) { $reflection = new \ReflectionClass($controller); $reflection_method = $reflection->getMethod($method); $params = array(); foreach ($reflection_method->getParameters() as $key => $p) { if (array_key_exists($p->getName(), $data['param'])) { $params[$key] = $data['param'][$p->getName()]; } else { if ($p->isDefaultValueAvailable()) { $params[$key] = $p->getDefaultValue(); } else { throw new PMPException(sprintf('Not Found Controller Paramater %s In %s', get_class($controller) . ':' . $method, $p->getName())); } } } call_user_func_array(array($controller, $method), $params); } else { $controller->{$method}(); } $benchmark->setMark("action"); $benchmark->stop(); //$benchmark->display(false); } catch (\Exception $e) { throw new PMPException($e); } }