-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #421 from tdt/development
Development
- Loading branch information
Showing
15 changed files
with
361 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
* @license AGPLv3 | ||
* @author Jan Vansteenlandt <[email protected]> | ||
*/ | ||
abstract class ApiController extends \Controller | ||
abstract class ApiController extends Controller | ||
{ | ||
|
||
protected $definition; | ||
|
@@ -23,27 +23,26 @@ public function __construct(DefinitionRepositoryInterface $definition) | |
|
||
public function handle($uri) | ||
{ | ||
|
||
$uri = ltrim($uri, '/'); | ||
|
||
// Delegate the request based on the used http method | ||
$method = \Request::getMethod(); | ||
|
||
switch ($method) { | ||
case "PUT": | ||
case 'PUT': | ||
return $this->put($uri); | ||
break; | ||
case "GET": | ||
case 'GET': | ||
return $this->get($uri); | ||
break; | ||
case "POST": | ||
case "PATCH": | ||
case 'POST': | ||
case 'PATCH': | ||
return $this->patch($uri); | ||
break; | ||
case "DELETE": | ||
case 'DELETE': | ||
return $this->delete($uri); | ||
break; | ||
case "HEAD": | ||
case 'HEAD': | ||
return $this->head($uri); | ||
break; | ||
default: | ||
|
@@ -55,26 +54,26 @@ public function handle($uri) | |
|
||
public function get($uri) | ||
{ | ||
\App::abort(405, "The HTTP method GET is not supported by this resource."); | ||
\App::abort(405, 'The HTTP method GET is not supported by this resource.'); | ||
} | ||
|
||
public function put($uri) | ||
{ | ||
\App::abort(405, "The HTTP method PUT is not supported by this resource."); | ||
\App::abort(405, 'The HTTP method PUT is not supported by this resource.'); | ||
} | ||
|
||
public function patch($uri) | ||
{ | ||
\App::abort(405, "The HTTP method PATCH is not supported by this resource."); | ||
\App::abort(405, 'The HTTP method PATCH is not supported by this resource.'); | ||
} | ||
|
||
public function head($uri) | ||
{ | ||
\App::abort(405, "The HTTP method HEAD is not supported by this resource."); | ||
\App::abort(405, 'The HTTP method HEAD is not supported by this resource.'); | ||
} | ||
|
||
public function delete($uri) | ||
{ | ||
\App::abort(405, "The HTTP method DELETE is not supported by this resource."); | ||
\App::abort(405, 'The HTTP method DELETE is not supported by this resource.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
* @license AGPLv3 | ||
* @author Michiel Vancoillie <[email protected]> | ||
*/ | ||
class BaseController extends \Controller | ||
class BaseController extends Controller | ||
{ | ||
/* | ||
* Handles all core requests | ||
|
@@ -29,7 +29,10 @@ public function handleRequest($uri) | |
$controller = 'Tdt\\Core\\Definitions\\DiscoveryController'; | ||
break; | ||
case 'api': | ||
switch (\Request::segment(2)) { | ||
// Allow for content negotiation for api endpoints | ||
list($apiResource, $extension) = self::processURI(\Request::segment(2)); | ||
|
||
switch ($apiResource) { | ||
case 'definitions': | ||
// Definitions request | ||
$controller = 'Tdt\\Core\\Definitions\\DefinitionController'; | ||
|
@@ -74,7 +77,7 @@ public function handleRequest($uri) | |
$uri = str_replace('api/keywords', '', $uri); | ||
break; | ||
default: | ||
\App::abort(404, "Page not found."); | ||
\App::abort(404, 'Page not found.'); | ||
break; | ||
} | ||
|
||
|
@@ -107,4 +110,38 @@ public function handleRequest($uri) | |
return $response; | ||
} | ||
} | ||
|
||
/** | ||
* Process the URI and return the extension (=format) and the resource identifier URI | ||
* | ||
* @param string $uri The URI that has been passed | ||
* @return array | ||
*/ | ||
public static function processURI($uri) | ||
{ | ||
$dot_position = strrpos($uri, '.'); | ||
|
||
if (! $dot_position) { | ||
return array($uri, null); | ||
} | ||
|
||
// If a dot has been found, do a couple | ||
// of checks to find out if it introduces a formatter | ||
$uri_parts = explode('.', $uri); | ||
|
||
$possible_extension = strtoupper(array_pop($uri_parts)); | ||
|
||
$uri = implode('.', $uri_parts); | ||
|
||
$formatter_class = 'Tdt\\Core\\Formatters\\' . $possible_extension . 'Formatter'; | ||
|
||
if (! class_exists($formatter_class)) { | ||
// Re-attach the dot with the latter part of the uri | ||
$uri .= '.' . strtolower($possible_extension); | ||
|
||
return array($uri, null); | ||
} | ||
|
||
return array($uri, strtolower($possible_extension)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace Tdt\Core; | ||
|
||
class Controller extends \Controller | ||
{ | ||
/** | ||
* Process the URI and return the extension (=format) and the resource identifier URI | ||
* | ||
* @param string $uri The URI that has been passed | ||
* @return array | ||
*/ | ||
public static function processURI($uri) | ||
{ | ||
$dot_position = strrpos($uri, '.'); | ||
|
||
if (! $dot_position) { | ||
return array($uri, null); | ||
} | ||
|
||
// If a dot has been found, do a couple | ||
// of checks to find out if it introduces a formatter | ||
$uri_parts = explode('.', $uri); | ||
|
||
$possible_extension = strtoupper(array_pop($uri_parts)); | ||
|
||
$uri = implode('.', $uri_parts); | ||
|
||
$formatter_class = 'Tdt\\Core\\Formatters\\' . $possible_extension . 'Formatter'; | ||
|
||
if (! class_exists($formatter_class)) { | ||
// Re-attach the dot with the latter part of the uri | ||
$uri .= '.' . strtolower($possible_extension); | ||
|
||
return array($uri, null); | ||
} | ||
|
||
return array($uri, strtolower($possible_extension)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.