-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef1a940
commit 2191b78
Showing
25 changed files
with
264 additions
and
210 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
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
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
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
44 changes: 44 additions & 0 deletions
44
lib/recess/apps/ide/controllers/RecessReflectorController.class.php
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,44 @@ | ||
<?php | ||
Library::import('recess.framework.controllers.Controller'); | ||
Library::import('app.controllers.RouteAnnotation', true); | ||
Library::import('recess.http.responses.NotFoundResponse'); | ||
Library::import('recess.framework.ResponseData'); | ||
Library::import('recess.http.responses.OkResponse'); | ||
|
||
class RecessReflectorController extends Controller { | ||
/** !Route GET, reflector/ */ | ||
public function home() { | ||
echo 'ROUTED home'; | ||
} | ||
|
||
/** !Route GET, reflector/package/$package */ | ||
public function package($package) { | ||
echo 'package/' . $package; exit; | ||
} | ||
|
||
/** !Route GET, reflector/model/$fullyQualifiedModel */ | ||
public function model($fullyQualifiedModel) { | ||
if(!Library::classExists($fullyQualifiedModel)) { | ||
return new NotFoundResponse($request); | ||
} | ||
|
||
$model = Library::getClassName($fullyQualifiedModel); | ||
$reflection = new RecessReflectionClass($model); | ||
|
||
$data = new stdclass; | ||
$data->reflection = $reflection; | ||
$data->relationships = Model::getRelationships($model); | ||
$data->columns = Model::getColumns($model); | ||
$data->table = Model::tableFor($model); | ||
|
||
return $this->ok(); | ||
|
||
// $response = new OkResponse($this->request, $data); | ||
// $response->meta->app = new RecessIdeApplication(); | ||
// $response->meta->viewName = 'reflector/model'; | ||
// return $response; | ||
} | ||
|
||
} | ||
|
||
?> |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
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
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,174 @@ | ||
<?php | ||
Library::import('recess.framework.controllers.Controller'); | ||
Library::import('recess.framework.views.View'); | ||
Library::import('recess.framework.interfaces.IPolicy'); | ||
|
||
class DefaultPolicy implements IPolicy { | ||
|
||
/** | ||
* Used to pre-process a request. | ||
* This may involve extracting information and transforming values. | ||
* For example, Transforming the HTTP method from POST to PUT based on a POSTed field. | ||
* | ||
* @param Request The Request to refine. | ||
* @return Request The refined Request. | ||
*/ | ||
public function preprocess(Request $request) { | ||
|
||
$this->getHttpMethodFromPost($request); | ||
|
||
$this->getFormatFromResourceString($request); | ||
|
||
if($request->format != Formats::xhtml) { | ||
$this->reparameterizeForFormat($request); | ||
} | ||
|
||
return $request; | ||
} | ||
|
||
public function getControllerFor(Request $request, array $applications, RoutingNode $routes) { | ||
|
||
$routeResult = $routes->findRouteFor($request); | ||
|
||
if($routeResult->routeExists) { | ||
if($routeResult->methodIsSupported) { | ||
$controller = $this->getControllerFromRouteResult($request, $routeResult); | ||
} else { | ||
// TODO: Shortwire a result here for a method not supported HTTP response. | ||
throw new RecessError('METHOD not supported.'); | ||
} | ||
} else { | ||
$controller = $this->getControllerFromResourceString($request, $applications); | ||
} | ||
|
||
return $controller; | ||
} | ||
|
||
public function getViewFor(Response $response) { | ||
$response->meta->app->loadView($response->meta->viewClass); | ||
return new $response->meta->viewClass; | ||
} | ||
|
||
///////////////////////////////////////////////////////////////////////// | ||
// Helper Methods | ||
|
||
const HTTP_METHOD_FIELD = '_METHOD'; | ||
|
||
protected function getHttpMethodFromPost(Request &$request) { | ||
if(array_key_exists(self::HTTP_METHOD_FIELD, $request->post)) { | ||
$request->method = $request->post[self::HTTP_METHOD_FIELD]; | ||
unset($request->post[self::HTTP_METHOD_FIELD]); | ||
if($request->method == Methods::PUT) { | ||
$request->put = $request->post; | ||
} | ||
} | ||
return $request; | ||
} | ||
|
||
protected function getFormatFromResourceString(Request &$request) { | ||
$lastPartIndex = count($request->resourceParts) - 1; | ||
if($lastPartIndex < 0) return $request; | ||
|
||
$lastPart = $request->resourceParts[$lastPartIndex]; | ||
|
||
$lastDotPosition = strrpos($lastPart, Library::dotSeparator); | ||
if($lastDotPosition !== false) { | ||
$substring = substr($lastPart, $lastDotPosition + 1); | ||
if(in_array($substring, Formats::$all)) { | ||
$request->format = $substring; | ||
$request->setResource(substr($request->resource, 0, strrpos($request->resource, Library::dotSeparator))); | ||
} else { | ||
$request->format = Formats::xhtml; | ||
} | ||
} | ||
return $request; | ||
} | ||
|
||
protected function reparameterizeForFormat(Request &$request) { | ||
// TODO: Think about how parameter passing via json/xml/post-vars can be streamlined | ||
if($request->format == Formats::json) { | ||
if(array_key_exists('json', $request->post)){ | ||
$request->post = json_decode($request->post['json']); | ||
} | ||
} else if ($request->format == Formats::xml) { | ||
// TODO: XML reparameterization in request transformer | ||
} | ||
return $request; | ||
} | ||
|
||
protected function getControllerFromRouteResult(Request &$request, RoutingResult $routeResult) { | ||
$request->meta->controllerMethod = $routeResult->route->function; | ||
$request->meta->controllerMethodArguments = $routeResult->arguments; | ||
$request->meta->useAssociativeArguments = true; | ||
return Library::importAndInstantiate($routeResult->route->class); | ||
} | ||
|
||
protected function getControllerFromResourceString(Request &$request, array $applications) { | ||
$partsCount = count($request->resourceParts); | ||
|
||
$prefixes = array_map(create_function('$app','return $app->routingPrefix;'), $applications); | ||
|
||
$request->meta->controllerMethodArguments = array(); | ||
$request->meta->useAssociativeArguments = false; | ||
// TODO: Clean this up. Throw better errors to reveal internal logic. | ||
switch($partsCount) { | ||
case 0: // DefaultApp, HomeController, home method | ||
$defaultAppKey = array_search('',$prefixes); | ||
if($defaultAppKey !== false) { | ||
$request->meta->controllerMethod = 'home'; | ||
$request->meta->app = $applications[$defaultAppKey]; | ||
return $applications[$defaultAppKey]->getController('HomeController'); | ||
} | ||
break; | ||
case 1: // | ||
$appKey = array_search($request->resourceParts[0], $prefixes); | ||
if($appKey !== false) { | ||
$request->meta->controllerMethod = 'home'; | ||
$request->meta->app = $applications[$appKey]; | ||
return $applications[$appKey]->getController('HomeController'); | ||
} else { | ||
$defaultAppKey = array_search('',$prefixes); | ||
if($defaultAppKey !== false) { | ||
$request->meta->controllerMethod = 'home'; | ||
$request->meta->app = $applications[$defaultAppKey]; | ||
return $applications[$defaultAppKey]->getController($request->resourceParts[0] . 'Controller'); | ||
} | ||
} | ||
break; | ||
case 2: | ||
$appKey = array_search($request->resourceParts[0], $prefixes); | ||
if($appKey !== false) { | ||
$request->meta->controllerMethod = 'home'; | ||
$request->meta->app = $applications[$appKey]; | ||
return $applications[$appKey]->getController($request->resourceParts[1] . 'Controller'); | ||
} else { | ||
$defaultAppKey = array_search('',$prefixes); | ||
if($defaultAppKey !== false) { | ||
$request->meta->controllerMethod = $request->resourceParts[1]; | ||
$request->meta->app = $applications[$defaultAppKey]; | ||
return $applications[$defaultAppKey]->getController($request->resourceParts[0] . 'Controller'); | ||
} | ||
} | ||
break; | ||
default: | ||
$appKey = array_search($request->resourceParts[0], $prefixes); | ||
if($appKey !== false) { | ||
$request->meta->controllerMethodArguments = array_slice($request->resourceParts,3); | ||
$request->meta->controllerMethod = $request->resourceParts[2]; | ||
$request->meta->app = $applications[$appKey]; | ||
return $applications[$appKey]->getController($request->resourceParts[1] . 'Controller'); | ||
} else { | ||
$defaultAppKey = array_search('',$prefixes); | ||
if($defaultAppKey !== false) { | ||
$request->meta->controllerMethodArguments = array_slice($request->resourceParts,2); | ||
$request->meta->controllerMethod = $request->resourceParts[1]; | ||
$request->meta->app = $applications[$defaultAppKey]; | ||
return $applications[$defaultAppKey]->getController($request->resourceParts[0] . 'Controller'); | ||
} | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
|
||
?> |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...ult/annotations/RouteAnnotation.class.php → ...ork/annotations/RouteAnnotation.class.php
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
2 changes: 1 addition & 1 deletion
2
...ault/annotations/ViewAnnotation.class.php → ...work/annotations/ViewAnnotation.class.php
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
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
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.