Issues (97)

src/RestfulServerItem.php (2 issues)

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
The private property $url_handlers is not used, and could be removed.
Loading history...
13
        '$Relation' => 'handleRelation',
14
    );
15
16
    public function __construct($item)
17
    {
18
        $this->item = $item;
0 ignored issues
show
Bug Best Practice introduced by
The property item does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
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