function testLoad() { $file = __DIR__ . "/file.php"; file_put_contents($file, "<?php return array('a' => 'b');"); $cache = new Cache($file); $this->assertEquals("b", $cache->get("a")); unset($cache); unlink($file); }
function testMethodNotAllowedMatch() { $this->cache->get("router")->shouldBeCalled()->willReturn(TestResource::expectedTable()); $router = new Router($this->cache->reveal(), new UrlTools()); $resources = array(__NAMESPACE__ . "\\TestResource"); $match = $router->match($resources, "POST", "/this/is/static"); $this->assertEquals(Router::METHOD_NOT_ALLOWED, $match->status, "Match"); $this->assertEquals(array("GET"), $match->allowed, "Allowed"); }
/** * Returns an array containing the compiled routing information based off of * the provided resource objects. * * !!! WARNING !!! This will use the cached version of the table if available * without checking for updates. It is the end users job to ensure that this * cache file is kept updated. * * @param array $resources * @return array */ public function getRoutingTable(array $resources) { if ($table = $this->cache->get("router")) { return $table; } $table = array("static" => array(), "dynamic" => array()); foreach ($resources as $resourceName) { $routes = $this->buildRoutingTableEntryForResource($resourceName); $table["static"] += $routes["static"]; $table["dynamic"] += $routes["dynamic"]; } return $table; }
/** * This method can be used to give a significant performance boost to your * application by pre-generating and caching the routing table. Note that * this caching is NOT performed automatically and that the $api->cacheFile * property needs to be set to a writable path for this to succeed. * * @see cacheFile * @return void */ public function createCache() { $cache = new Cache($this->cacheFile); $router = new Router($cache, new UrlTools()); $table = $router->getRoutingTable($this->resources); $cache->set("router", $table); }