/** * */ public static function loadConfig($options) { $controllers = $options['controllers']; ptc_listen('app.start', function () use($controllers) { \helpers\Website\Manager::autoload($controllers); }, $options['listener_priority']); return $options; }
public function host() { return Manager::host(); }
/** * */ protected static function _build($items, $type, $comment = null) { if (!static::_initialize()) { return false; } $tpl = 'css' === $type ? '<link rel="stylesheet" href="{path}">' : '<script type="text/javascript" src="{path}"></script>'; $dep = $comment ? "\t" . '<!-- ' . $comment . '-->' . "\n" : null; $items = is_array($items) ? $items : array($items); foreach ($items as $item) { if (!isset(static::$_resources[$item])) { trigger_error('Resource id "' . $item . '" is not set!', E_USER_ERROR); return false; } $path = !static::$_resources[$item]['external'] ? Manager::getPath() : null; $item = static::$_resources[$item]['file']; $dep .= "\t" . str_replace('{path}', $path . $item, $tpl) . "\n"; } return $dep; }
/** * */ protected function _buildRoutes($block, $routes, array $filters = array()) { $controller_id = $this->_controllerID; foreach ($routes as $route) { if (!$route->map) { trigger_error('Please add a map tag to route ' . $route->attributes()->url . '!', E_USER_ERROR); return false; } if (array_key_exists('before', $filters)) { $route->before = ($b = (string) $route->attributes()->before) ? $filters['before'] . '|' . $b : $filters['before']; } else { if ($b = (string) $route->attributes()->before) { $route->before = $b; } } if (array_key_exists('after', $filters)) { $route->after = ($a = (string) $route->attributes()->after) ? $filters['after'] . '|' . $a : $filters['after']; } else { if ($a = (string) $route->attributes()->after) { $route->after = $a; } } $map = (string) $route->map[0]; $callback = function () use($route, $controller_id, $map) { \helpers\Website\Manager::currentController($controller_id); \helpers\Website\Manager::currentRoute($map); \helpers\Website\Manager::setLang($controller_id); $metatags = $route->metatags ? (array) $route->metatags[0] : array(); \helpers\Website\Manager::setMetaTags((string) $route->page[0], $metatags); return \helpers\Website\Manager::page((string) $route->page[0]); }; $url = $route->attributes()->url; if ($this->_prefix) { $url = '/' === substr($url, 0, 1) ? substr($url, 1) : $url; $this->_prefix = '/' !== substr($this->_prefix, -1) ? $this->_prefix . '/' : $this->_prefix; $url = $this->_prefix . $url; } $params = array($url, $callback); $requests = ($r = (string) $route->attributes()->request) ? explode('|', $r) : array('get'); $a = 0; foreach ($requests as $request) { $router = call_user_func_array('\\Router::' . $request, $params); foreach (Manager::getUrlPatterns() as $k => $v) { if (preg_match('<{' . $k . '}|{' . $k . '\\?}>', $url)) { $router->where($k, $v); } } $router->map((string) $route->map[0]); $router->set('controller', $controller_id); if ($route->protocol || $this->_protocol) { $prot = ($p = (string) $route->protocol) ? $p : $this->_protocol; $router->protocol($prot); } if ($route->domain || $this->_domain) { $dom = ($d = (string) $route->domain) ? $d : $this->_domain; $router->domain($dom); } if ($route->before) { $router->before((string) $route->before); } if ($route->after) { $router->after((string) $route->after); } ++$a; } } return true; }