Skip to content

Commit

Permalink
(merged from branches/roa. use "svn log -c <changeset> -g <module-svn…
Browse files Browse the repository at this point in the history
…-path>" for detailed commit message)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@60205 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information
chillu committed Aug 9, 2008
1 parent 9ac464c commit 03fcc80
Show file tree
Hide file tree
Showing 18 changed files with 951 additions and 369 deletions.
20 changes: 20 additions & 0 deletions _config.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,26 @@
* @subpackage core
*/

// Default director
Director::addRules(10, array(
'Security' => 'Security',
//'Security/$Action/$ID' => 'Security',
'db/$Action' => 'DatabaseAdmin',
'$Controller' => array(
),
'images/$Action/$Class/$ID/$Field' => 'Image_Uploader',
'' => 'RootURLController',
'sitemap.xml' => 'GoogleSitemap',
'api/v1' => 'RestfulServer',
));

Director::addRules(1, array(
'$URLSegment/$Action/$ID/$OtherID' => array(
'_PopTokeniser' => 1,
'Controller' => 'ModelAsController',
),
));

/**
* PHP 5.2 has a namespace conflict with our datetime class,
* for legacy support, we use this overload method.
Expand Down
54 changes: 53 additions & 1 deletion api/RestfulServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,20 @@
* @subpackage api
*/
class RestfulServer extends Controller {
static $url_handlers = array(
'$ClassName/#ID' => 'handleItem',
'$ClassName' => 'handleList',
);

protected static $api_base = "api/v1/";

function handleItem($params) {
return new RestfulServer_Item(DataObject::get_by_id($params["ClassName"], $params["ID"]));
}

function handleList($params) {
return new RestfulServer_List(DataObject::get($params["ClassName"],""));
}

/**
* This handler acts as the switchboard for the controller.
Expand Down Expand Up @@ -318,4 +331,43 @@ protected function notFound() {
return "That object wasn't found";
}

}
}


/**
* Restful server handler for a DataObjectSet
*/
class RestfulServer_List {
static $url_handlers = array(
'#ID' => 'handleItem',
);

function __construct($list) {
$this->list = $list;
}

function handleItem($params) {
return new RestulServer_Item($this->list->getById($params['ID']));
}
}

/**
* Restful server handler for a single DataObject
*/
class RestfulServer_Item {
static $url_handlers = array(
'$Relation' => 'handleRelation',
);

function __construct($item) {
$this->item = $item;
}

function handleRelation($params) {
$funcName = $params['Relation'];
$relation = $this->item->$funcName();

if($relation instanceof DataObjectSet) return new RestfulServer_List($relation);
else return new RestfulServer_Item($relation)l
}
}
1 change: 0 additions & 1 deletion core/ViewableData.php
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,6 @@ function CSSClasses($stopAtClass = false) {
return Convert::raw2att(implode(" ", $classes));
}


/**
* Object-casting information for class methods
* @var mixed
Expand Down
1 change: 0 additions & 1 deletion core/control/ContentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class ContentController extends Controller {
public function __construct($dataRecord) {
$this->dataRecord = $dataRecord;
$this->failover = $this->dataRecord;

parent::__construct();
}

Expand Down
Loading

0 comments on commit 03fcc80

Please sign in to comment.