Refactored namespace

Added autoload to composer.json
This commit is contained in:
PJ Dietz 2013-01-10 20:09:07 -05:00
parent 2f328bb5e8
commit e4972e1bf0
16 changed files with 25 additions and 18 deletions

View File

@ -1,6 +1,6 @@
<?php <?php
namespace wellrested; namespace pjdietz\WellRESTed;
require_once(dirname(__FILE__) . '/Request.inc.php'); require_once(dirname(__FILE__) . '/Request.inc.php');
require_once(dirname(__FILE__) . '/Response.inc.php'); require_once(dirname(__FILE__) . '/Response.inc.php');

View File

@ -1,6 +1,6 @@
<?php <?php
namespace wellrested; namespace pjdietz\WellRESTed;
/** /**
* Common base class for the Request and Response classes. * Common base class for the Request and Response classes.

View File

@ -1,6 +1,6 @@
<?php <?php
namespace wellrested; namespace pjdietz\WellRESTed;
require_once(dirname(__FILE__) . '/Message.inc.php'); require_once(dirname(__FILE__) . '/Message.inc.php');
require_once(dirname(__FILE__) . '/Response.inc.php'); require_once(dirname(__FILE__) . '/Response.inc.php');

View File

@ -1,6 +1,6 @@
<?php <?php
namespace wellrested; namespace pjdietz\WellRESTed;
require_once(dirname(__FILE__) . '/Message.inc.php'); require_once(dirname(__FILE__) . '/Message.inc.php');

View File

@ -1,6 +1,6 @@
<?php <?php
namespace wellrested; namespace pjdietz\WellRESTed;
/******************************************************************************* /*******************************************************************************
* Route * Route

View File

@ -1,6 +1,6 @@
<?php <?php
namespace wellrested; namespace pjdietz\WellRESTed;
require_once(dirname(__FILE__) . '/Request.inc.php'); require_once(dirname(__FILE__) . '/Request.inc.php');
require_once(dirname(__FILE__) . '/Response.inc.php'); require_once(dirname(__FILE__) . '/Response.inc.php');

View File

@ -12,5 +12,8 @@
], ],
"require": { "require": {
"php": ">=5.3.0" "php": ">=5.3.0"
},
"autoload": {
"psr-0": { "pjdietz/WellRESTed": "" }
} }
} }

View File

@ -1,6 +1,6 @@
<?php <?php
namespace wellrested\exceptions; namespace pjdietz\WellRESTed\exceptions;
require_once(dirname(__FILE__) . '/WellrestedException.inc.php'); require_once(dirname(__FILE__) . '/WellrestedException.inc.php');

View File

@ -1,6 +1,6 @@
<?php <?php
namespace wellrested\exceptions; namespace pjdietz\WellRESTed\exceptions;
/** /**
* Top level class for custom exceptions thrown by Well RESTed. * Top level class for custom exceptions thrown by Well RESTed.

View File

@ -2,12 +2,16 @@
namespace apisample; namespace apisample;
use pjdietz\WellRESTed\Router;
use pjdietz\WellRESTed\Route;
require_once(dirname(__FILE__) . '/../../Router.inc.php'); require_once(dirname(__FILE__) . '/../../Router.inc.php');
/** /**
* Loads and instantiates handlers based on URI. * Loads and instantiates handlers based on URI.
*/ */
class ApiSampleRouter extends \wellrested\Router { class ApiSampleRouter extends Router {
public function __construct() { public function __construct() {
@ -20,12 +24,12 @@ class ApiSampleRouter extends \wellrested\Router {
$this->addTemplate('/articles/{id}', $this->addTemplate('/articles/{id}',
'ArticleItemHandler', 'ArticleItemHandler',
'ArticleItemHandler.inc.php', 'ArticleItemHandler.inc.php',
array('id' => \wellrested\Route::RE_NUM)); array('id' => Route::RE_NUM));
$this->addTemplate('/articles/{slug}', $this->addTemplate('/articles/{slug}',
'ArticleItemHandler', 'ArticleItemHandler',
'ArticleItemHandler.inc.php', 'ArticleItemHandler.inc.php',
array('slug' => \wellrested\Route::RE_SLUG)); array('slug' => Route::RE_SLUG));
} }
@ -36,7 +40,7 @@ class ApiSampleRouter extends \wellrested\Router {
$handlerClassName = '\apisample\handlers\\' . $handlerClassName; $handlerClassName = '\apisample\handlers\\' . $handlerClassName;
$handlerFilePath = dirname(__FILE__) . '/handlers/' . $handlerFilePath; $handlerFilePath = dirname(__FILE__) . '/handlers/' . $handlerFilePath;
$this->addRoute(\wellrested\Route::newFromUriTemplate( $this->addRoute(Route::newFromUriTemplate(
$template, $handlerClassName, $handlerFilePath, $variables)); $template, $handlerClassName, $handlerFilePath, $variables));
} }

View File

@ -8,7 +8,7 @@ require_once(dirname(__FILE__) . '/../ArticlesController.inc.php');
/** /**
* Handler class for a list of articles. * Handler class for a list of articles.
*/ */
class ArticleCollectionHandler extends \wellrested\Handler { class ArticleCollectionHandler extends \pjdietz\WellRESTed\Handler {
/** /**
* Respond to a GET request. * Respond to a GET request.

View File

@ -11,7 +11,7 @@ require_once(dirname(__FILE__) . '/../ArticlesController.inc.php');
* When instantiated by the Router, this class should receive an id or slug * When instantiated by the Router, this class should receive an id or slug
* argument to identify the article. * argument to identify the article.
*/ */
class ArticleItemHandler extends \wellrested\Handler { class ArticleItemHandler extends \pjdietz\WellRESTed\Handler {
/** /**
* Respond to a GET request. * Respond to a GET request.

View File

@ -14,7 +14,7 @@ require_once('../Request.inc.php');
require_once('../Response.inc.php'); require_once('../Response.inc.php');
// Make a custom request to talk to the server. // Make a custom request to talk to the server.
$rqst = new \wellrested\Request(); $rqst = new \pjdietz\WellRESTed\Request();
// Use the client-site-endpoint.php script // Use the client-site-endpoint.php script
$rqst->hostname = $_SERVER['HTTP_HOST']; $rqst->hostname = $_SERVER['HTTP_HOST'];

View File

@ -8,7 +8,7 @@
require_once('../Request.inc.php'); require_once('../Request.inc.php');
// Make a requst to Google in one line: // Make a requst to Google in one line:
$rqst = new \wellrested\Request(); $rqst = new \pjdietz\WellRESTed\Request();
$rqst->uri = 'https://www.google.com/search?q=my+search+terms'; $rqst->uri = 'https://www.google.com/search?q=my+search+terms';
// You could also set the members individually, like this: // You could also set the members individually, like this:

View File

@ -12,7 +12,7 @@ require_once('../Request.inc.php');
require_once('../Response.inc.php'); require_once('../Response.inc.php');
// Read the request sent to the server as the singleton instance. // Read the request sent to the server as the singleton instance.
$rqst = \wellrested\Request::getRequest(); $rqst = \pjdietz\WellRESTed\Request::getRequest();
// Alternatively, you can create a new Request and call readHttpRequest(). // Alternatively, you can create a new Request and call readHttpRequest().
// $rqst = new \wellrested\Request(); // $rqst = new \wellrested\Request();

View File

@ -7,7 +7,7 @@
require_once('../Response.inc.php'); require_once('../Response.inc.php');
// Create a new Response instance. // Create a new Response instance.
$resp = new \wellrested\Response(); $resp = new \pjdietz\WellRESTed\Response();
$resp->statusCode = 200; $resp->statusCode = 200;
$resp->setHeader('Content-Type', 'text/plain'); $resp->setHeader('Content-Type', 'text/plain');
$resp->body = 'This is a response.'; $resp->body = 'This is a response.';