/** * Redefine run taking into account mountend end points */ public function run(Request $request = null) { $endPointName = $this->getEndPointName(); $applicationPath = $this->getEndPointPath(); $routerClass = $endPointName && isset($this->endPointCatalog[$endPointName]) ? $this->endPointCatalog[$endPointName] : ''; $virtualhost = empty($endPointName) ? $applicationPath : $applicationPath . '/' . $endPointName; if (!$routerClass) { $result = parent::run($request); //fall back to local application routing } else { // now we test that $routerclass is a valid end_point $myClass = get_class(); if ($routerClass == $myClass || is_subclass_of($routerClass, $myClass)) { // Create new end-point $endpoint = new $routerClass($virtualhost); $result = $endpoint->run(); } else { throw new HttpErrorException(HttpProblem::factory(500, 'Invalid endpoint', $routerClass . ' end point class is not a subClass of ' . $myClass)); } } //now prepare an error report for humans when something went wrong //Warning this trigger is called only in php >5.4. Otherwhise just empty content is printed //(but original status is preserved) if (empty($result) && ($errorCode = Http::getHttpResponseCode()) >= 400) { $result = ErrorManager::getInstance()->serializeHttpProblem(new HttpProblem($errorCode)); } return $result; }
/** * @covers Respect\Rest\Router::__call * @covers Respect\Rest\Router::staticRoute * @dataProvider provideForNonStaticRoutableValues * @expectedException InvalidArgumentException */ public function testMagicConstructorCannotRouteSomeStaticValues($staticValue, $reason) { $router = new Router(); $nonStaticRoute = $router->get('/', $staticValue); $router->run(); // __toString is not allowed to throw exceptions $this->assertNotInstanceOf('Respect\\Rest\\Routes\\StaticValue', $nonStaticRoute, $reason); }