public static function run($app, $controller = null, $action = null) { self::$app = $app; $autoload = AutoLoad::getInstance(); //加载配置文件 $config = DOCUMENT_ROOT . DS . 'app' . DS . $app . DS . 'config.php'; if (!is_file($config)) { throw new \Exception($app . '应用缺少config文件', 0); } else { require $config; self::$config = new \Config(); self::$config->loader($autoload); } //分发路由 $route = new Route($app); $route->execute($controller, $action); }
if ($articles = Mecha::eat($s)->chunk(1, $config->index->per_page)->vomit()) { $articles = Mecha::walk($articles, function ($path) use($excludes) { return Get::article($path, $excludes); }); } else { $articles = false; } Filter::add('pager:url', function ($url) { return Filter::apply('index:url', $url); }); Config::set(array('articles' => $articles, 'pagination' => Navigator::extract($s, 1, $config->index->per_page, $config->index->slug))); Shield::attach('page-home'); }, 110); /** * Route Hook: after * ----------------- */ Weapon::fire('routes_after'); /** * Do Routing * ---------- */ Route::execute(); /** * 404 Page * -------- * * Fallback to 404 page if nothing matched. * */ Shield::abort();
$filter = $filter ? Text::parse($filter, '->safe_file_name') : ""; $s = Get::closestFolders($destination, 'ASC', 'path', $filter); if (!($folders = Mecha::eat($s)->chunk($offset, $config->manager->per_page)->vomit())) { Shield::abort(); } Config::set(array('page_title' => $speak->plugins . $config->title_separator . $config->manager->title, 'offset' => $offset, 'pagination' => Navigator::extract($s, $offset, $config->manager->per_page, $config->manager->slug . '/plugin'), 'cargo' => 'cargo.plugin.php')); Shield::lot(array('segment' => 'plugin', 'folders' => Mecha::O($folders)))->attach('manager'); }); /** * Plugin Configurator * ------------------- */ Route::accept($config->manager->slug . '/plugin/(:any)', function ($slug = 1) use($config, $speak) { if (is_numeric($slug)) { // It's an index page Route::execute($config->manager->slug . '/plugin/(:num)', array($slug)); } if (!Guardian::happy(1)) { Shield::abort(); } if (!File::exist(PLUGIN . DS . $slug . DS . 'launch.php') && !File::exist(PLUGIN . DS . $slug . DS . '__launch.php')) { Shield::abort(); } $info = Plugin::info($slug); if (!($info->configurator = File::exist(PLUGIN . DS . $slug . DS . 'configurator.php'))) { $info->configurator = File::exist(PLUGIN . DS . $slug . DS . 'workers' . DS . 'configurator.php'); } Config::set(array('page_title' => $speak->managing . ': ' . $info->title . $config->title_separator . $config->manager->title, 'page' => $info, 'cargo' => 'repair.plugin.php')); Shield::lot(array('segment' => 'plugin', 'folder' => $slug))->attach('manager'); }); /**
/** * Execute a compiled route, and store the output to a file. * * @param Route $route The compiled route * @param mixed $compile Bool, or an iteratable dataset to compile * @param array|Closure $vars An array of vars, or a callback which * provides vars to be injected into the * route placeholders */ public function compile($route, $data, $vars) { if ($data === true) { $data = [$data]; } if (!(is_array($data) || $data instanceof Traversable)) { return; } // Loop through the provided data foreach ($data as $key => $value) { $params = $vars; if ($vars instanceof Closure) { // Run the compile callback to get the vars to include in the URI $params = $vars($value, $key); } // Pass the vars to the route, and spoof the returned URI $uri = $route->uri($params); $_SERVER['REQUEST_URI'] = $uri; $this->request->uri = $uri; // Execute the route, which now matches, and capture the results $result = $route->execute(); $this->store($uri, $result); } }
/** * @covers Zepto\Route::execute() */ public function testExecute() { $actual = $this->route->execute(); $this->assertEquals('Test callback', $actual); }
public function testACompleteResponseShouldStopFurtherRouteExecution() { $route = new Route('GET', '/test', function () { return 'callback'; }); $route->before(function (Response $response) { $response->send(); }); $response = new ResponseMock(); $route->execute(Request::create(false, 'localhost', '/test'), $response); $this->assertEquals('', $response->contents()); }