From a2255bebd9fc145c1c00fe0eff08a766b7115724 Mon Sep 17 00:00:00 2001 From: PJ Dietz Date: Wed, 5 Dec 2012 16:08:30 -0500 Subject: [PATCH] Namespace API sample. Add and update comments. --- samples/apisample/ApiSampleRouter.inc.php | 12 +++++++++--- .../apisample/data/ArticlesControler.inc.php | 5 +++++ .../handlers/ArticleCollectionHandler.inc.php | 15 ++++++++++++--- .../handlers/ArticleItemHandler.inc.php | 19 +++++++++++++++++-- samples/apisample/index.php | 2 +- 5 files changed, 44 insertions(+), 9 deletions(-) diff --git a/samples/apisample/ApiSampleRouter.inc.php b/samples/apisample/ApiSampleRouter.inc.php index 92660af..f321cfc 100644 --- a/samples/apisample/ApiSampleRouter.inc.php +++ b/samples/apisample/ApiSampleRouter.inc.php @@ -1,7 +1,12 @@ addTemplate('/articles/', - '\handlers\ArticleCollectionHandler', + 'ArticleCollectionHandler', 'ArticleCollectionHandler.inc.php'); $this->addTemplate('/articles/{id}', - '\handlers\ArticleItemHandler', + 'ArticleItemHandler', 'ArticleItemHandler.inc.php', array('id' => \wellrested\Route::RE_NUM)); $this->addTemplate('/articles/{slug}', - '\handlers\ArticleItemHandler', + 'ArticleItemHandler', 'ArticleItemHandler.inc.php', array('slug' => \wellrested\Route::RE_SLUG)); @@ -28,6 +33,7 @@ class ApiSampleRouter extends \wellrested\Router { // Customize as needed based on your server. $template = '/wellrested/samples/apisample' . $template; + $handlerClassName = '\apisample\handlers\\' . $handlerClassName; $handlerFilePath = dirname(__FILE__) . '/handlers/' . $handlerFilePath; $this->addRoute(\wellrested\Route::newFromUriTemplate( diff --git a/samples/apisample/data/ArticlesControler.inc.php b/samples/apisample/data/ArticlesControler.inc.php index b4ce53e..c9538e1 100644 --- a/samples/apisample/data/ArticlesControler.inc.php +++ b/samples/apisample/data/ArticlesControler.inc.php @@ -1,5 +1,10 @@ data)) { @@ -28,6 +34,9 @@ class ArticleCollectionHandler extends \wellrested\Handler { } + /** + * Respond to a POST request. + */ protected function post() { // Read the request body, and ensure it is in the proper format. @@ -64,7 +73,7 @@ class ArticleCollectionHandler extends \wellrested\Handler { } // Ensure slug is not a duplicate. - $articles = new \ArticlesControler(); + $articles = new \apisample\data\ArticlesControler(); if ($articles->getArticleBySlug($article['slug']) !== false) { $this->response->statusCode = 409; $this->response->setHeader('Content-type', 'text/plain'); diff --git a/samples/apisample/handlers/ArticleItemHandler.inc.php b/samples/apisample/handlers/ArticleItemHandler.inc.php index 2675743..5f82ad3 100644 --- a/samples/apisample/handlers/ArticleItemHandler.inc.php +++ b/samples/apisample/handlers/ArticleItemHandler.inc.php @@ -1,16 +1,25 @@ getResponse(); $response->respond(); exit;