1 | <?php |
||
61 | class Server extends \Apparat\Server\Domain\Model\Server |
||
62 | { |
||
63 | /** |
||
64 | * View resources |
||
65 | * |
||
66 | * @var array |
||
67 | */ |
||
68 | protected $viewResources = []; |
||
69 | |||
70 | /** |
||
71 | * Enable the object route for a particular repository |
||
72 | * |
||
73 | * @param string $repositoryPath Repository path |
||
74 | * @param int $enable Enable / disable default actions |
||
75 | */ |
||
76 | 1 | public function enableObjectRoute($repositoryPath = '', $enable = ObjectRoute::ALL) |
|
77 | { |
||
78 | 1 | $routeName = ObjectRoute::OBJECT_STR; |
|
79 | 1 | $datePrecision = intval(getenv('OBJECT_DATE_PRECISION')); |
|
80 | 1 | $selectorRegex = SelectorFactory::getSelectorRegex($datePrecision); |
|
81 | 1 | $objectRouteActions = array_filter( |
|
82 | array_merge( |
||
83 | 1 | self::getEnabledObjectActionClasses($enable), |
|
84 | 1 | self::getEnabledDateActionClasses($enable, $datePrecision) |
|
85 | ) |
||
86 | ); |
||
87 | |||
88 | // Add a repository sub-pattern |
||
89 | 1 | if (strlen($repositoryPath)) { |
|
90 | 1 | $selectorRegex = '(?:/(?P<repository>.+?))'.$selectorRegex; |
|
91 | 1 | $routeName .= '.'.$repositoryPath; |
|
92 | } |
||
93 | |||
94 | 1 | $route = new Route(Route::GET, $routeName, $selectorRegex, $objectRouteActions); |
|
95 | 1 | $route->setAccepts(ObjectRoute::$accept); |
|
96 | 1 | $this->registerRoute($route); |
|
97 | 1 | } |
|
98 | |||
99 | /** |
||
100 | * Prepare and return a route action |
||
101 | * |
||
102 | * @param ServerRequestInterface $request Request |
||
103 | * @param AbstractActionRoute $route Route |
||
104 | * @return ActionInterface|Callable $action Action |
||
105 | */ |
||
106 | 78 | public function getRouteAction(ServerRequestInterface $request, AbstractActionRoute $route) |
|
110 | |||
111 | /** |
||
112 | * Return view resources |
||
113 | * |
||
114 | * @param string|null $name Optional: view resource name |
||
115 | * @return array View resources |
||
116 | */ |
||
117 | 76 | public function getViewResources($name = null) |
|
118 | { |
||
119 | 76 | return ($name === null) ? |
|
120 | $this->viewResources : |
||
121 | 76 | (array_key_exists($name, $this->viewResources) ? $this->viewResources[$name] : null); |
|
122 | } |
||
123 | |||
124 | /** |
||
125 | * Set the view resources |
||
126 | * |
||
127 | * @param array $viewResources View resources |
||
128 | */ |
||
129 | 1 | public function setViewResources(array $viewResources) |
|
133 | |||
134 | /** |
||
135 | * Return the enabled object action classes |
||
136 | * |
||
137 | * @param int $enable Enable / disable default actions |
||
138 | * @return array Enabled object action classes |
||
139 | */ |
||
140 | 1 | protected function getEnabledObjectActionClasses($enable) |
|
148 | |||
149 | /** |
||
150 | * Return the enabled date action classes |
||
151 | * |
||
152 | * @param int $enable Enable / disable default actions |
||
153 | * @param int $datePrecision Date precision |
||
154 | * @return array Enabled date action classes |
||
155 | */ |
||
156 | 1 | protected function getEnabledDateActionClasses($enable, $datePrecision) |
|
170 | } |
||
171 |