silverstripe /
silverstripe-restfulserver
| 1 | <?php |
||
| 2 | |||
| 3 | namespace SilverStripe\RestfulServer; |
||
| 4 | |||
| 5 | use SilverStripe\ORM\SS_List; |
||
| 6 | |||
| 7 | /** |
||
| 8 | * Restful server handler for a single DataObject |
||
| 9 | */ |
||
| 10 | class RestfulServerItem |
||
| 11 | { |
||
| 12 | private static $url_handlers = array( |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 13 | '$Relation' => 'handleRelation', |
||
| 14 | ); |
||
| 15 | |||
| 16 | public function __construct($item) |
||
| 17 | { |
||
| 18 | $this->item = $item; |
||
| 19 | } |
||
| 20 | |||
| 21 | public function handleRelation($request) |
||
| 22 | { |
||
| 23 | $funcName = $request('Relation'); |
||
| 24 | $relation = $this->item->$funcName(); |
||
| 25 | |||
| 26 | if ($relation instanceof SS_List) { |
||
| 27 | return new RestfulServerList($relation); |
||
| 28 | } else { |
||
| 29 | return new RestfulServerItem($relation); |
||
| 30 | } |
||
| 31 | } |
||
| 32 | } |
||
| 33 |