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