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 routes |
||
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 | [ |
||
84 | 1 | ObjectRoute::OBJECT_STR => (ObjectRoute::OBJECT & $enable) ? ObjectAction::class : null, |
|
85 | 1 | ObjectRoute::TYPE_STR => (ObjectRoute::TYPE & $enable) ? TypeAction::class : null, |
|
86 | 1 | ObjectRoute::OBJECTS_STR => (ObjectRoute::OBJECTS & $enable) ? ObjectsAction::class : null, |
|
87 | ], |
||
88 | array_slice( |
||
89 | [ |
||
90 | 1 | ObjectRoute::SECOND_STR => (ObjectRoute::SECOND & $enable) ? SecondAction::class : null, |
|
91 | 1 | ObjectRoute::MINUTE_STR => (ObjectRoute::MINUTE & $enable) ? MinuteAction::class : null, |
|
92 | 1 | ObjectRoute::HOUR_STR => (ObjectRoute::HOUR & $enable) ? HourAction::class : null, |
|
93 | 1 | ObjectRoute::DAY_STR => (ObjectRoute::DAY & $enable) ? DayAction::class : null, |
|
94 | 1 | ObjectRoute::MONTH_STR => (ObjectRoute::MONTH & $enable) ? MonthAction::class : null, |
|
95 | 1 | ObjectRoute::YEAR_STR => (ObjectRoute::YEAR & $enable) ? YearAction::class : null, |
|
96 | ], |
||
97 | 1 | 6 - $datePrecision |
|
98 | ) |
||
99 | ) |
||
100 | ); |
||
101 | |||
102 | // Add a repository sub-pattern |
||
103 | 1 | if (strlen($repositoryPath)) { |
|
104 | 1 | $selectorRegex = '(?:/(?P<repository>.+?))'.$selectorRegex; |
|
105 | 1 | $routeName .= '.'.$repositoryPath; |
|
106 | } |
||
107 | |||
108 | 1 | $route = new Route(Route::GET, $routeName, $selectorRegex, $objectRouteActions); |
|
109 | 1 | $route->setAccepts(ObjectRoute::$accept); |
|
110 | 1 | $this->registerRoute($route); |
|
111 | 1 | } |
|
112 | |||
113 | /** |
||
114 | * Prepare and return a route action |
||
115 | * |
||
116 | * @param ServerRequestInterface $request Request |
||
117 | * @param AbstractActionRoute $route Route |
||
118 | * @return ActionInterface|Callable $action Action |
||
119 | */ |
||
120 | 77 | public function getRouteAction(ServerRequestInterface $request, AbstractActionRoute $route) |
|
124 | |||
125 | /** |
||
126 | * Return view resources |
||
127 | * |
||
128 | * @param string|null $name Optional: view resource name |
||
129 | * @return array View resources |
||
130 | */ |
||
131 | 75 | public function getViewResources($name = null) |
|
132 | { |
||
133 | 75 | return ($name === null) ? |
|
134 | $this->viewResources : |
||
135 | 75 | (array_key_exists($name, $this->viewResources) ? $this->viewResources[$name] : null); |
|
136 | } |
||
137 | |||
138 | /** |
||
139 | * Set the view resources |
||
140 | * |
||
141 | * @param array $viewResources View resources |
||
142 | */ |
||
143 | 1 | public function setViewResources(array $viewResources) |
|
147 | } |
||
148 |