diff --git a/samples/apisample/ApiSampleRouter.php b/samples/apisample/ApiSampleRouter.php index e4e720b..e6dff38 100644 --- a/samples/apisample/ApiSampleRouter.php +++ b/samples/apisample/ApiSampleRouter.php @@ -1,6 +1,6 @@ addTemplate( '/articles/', - 'ArticleCollectionHandler', - 'ArticleCollectionHandler.php' + 'ArticleCollectionHandler' ); - $this->addTemplate( '/articles/{id}', 'ArticleItemHandler', - 'ArticleItemHandler.inc.php', array('id' => Route::RE_NUM) ); - $this->addTemplate( '/articles/{slug}', 'ArticleItemHandler', - 'ArticleItemHandler.inc.php', array('slug' => Route::RE_SLUG) ); - } - public function addTemplate($template, $handlerClassName, $handlerFilePath, $variables = null) + public function addTemplate($template, $handlerClassName, $variables = null) { // Customize as needed based on your server. $template = '/wellrested/samples/apisample' . $template; $handlerClassName = '\apisample\handlers\\' . $handlerClassName; - $handlerFilePath = dirname(__FILE__) . '/handlers/' . $handlerFilePath; $this->addRoute( Route::newFromUriTemplate( $template, $handlerClassName, - $handlerFilePath, $variables ) ); diff --git a/samples/apisample/ArticlesController.php b/samples/apisample/ArticlesController.php index b8349da..740a306 100644 --- a/samples/apisample/ArticlesController.php +++ b/samples/apisample/ArticlesController.php @@ -1,6 +1,6 @@ getResponse(); $response->respond(); exit; diff --git a/src/pjdietz/WellRESTed/Route.php b/src/pjdietz/WellRESTed/Route.php index 60e05c4..951cd92 100644 --- a/src/pjdietz/WellRESTed/Route.php +++ b/src/pjdietz/WellRESTed/Route.php @@ -39,23 +39,14 @@ class Route */ public $handler; - /** - * The path to the source file defing the handler class. - * - * @var string - */ - public $handlerPath; - /** * @param $pattern * @param $handler - * @param $handlerPath */ - public function __construct($pattern, $handler, $handlerPath = null) + public function __construct($pattern, $handler) { $this->pattern = $pattern; $this->handler = $handler; - $this->handlerPath = $handlerPath; } /** @@ -63,7 +54,6 @@ class Route * * @param string $uriTemplate * @param string $handler - * @param string $handlerPath * @param array $variables * @throws \Exception * @return Route @@ -71,7 +61,6 @@ class Route static public function newFromUriTemplate( $uriTemplate, $handler, - $handlerPath = null, $variables = null ) { @@ -133,7 +122,7 @@ class Route $pattern = '/^' . $pattern . '$/'; $klass = __CLASS__; - $route = new $klass($pattern, $handler, $handlerPath); + $route = new $klass($pattern, $handler); return $route; } diff --git a/src/pjdietz/WellRESTed/Router.php b/src/pjdietz/WellRESTed/Router.php index 9a1fb89..fccbe67 100644 --- a/src/pjdietz/WellRESTed/Router.php +++ b/src/pjdietz/WellRESTed/Router.php @@ -55,12 +55,6 @@ class Router if (preg_match($route->pattern, $path, $matches)) { $klass = $route->handler; - - // Autoload, if needed. - if (is_string($route->handlerPath) && !class_exists($klass)) { - require_once($route->handlerPath); - } - $handler = new $klass($request, $matches); return $handler->response;