1 | <?php |
||
19 | class RouteMaker |
||
20 | { |
||
21 | const ACTION_INDEX = 'index'; |
||
22 | const ACTION_NEW = 'new'; |
||
23 | const ACTION_CREATE = 'create'; |
||
24 | const ACTION_SHOW = 'show'; |
||
25 | const ACTION_EDIT = 'edit'; |
||
26 | const ACTION_UPDATE = 'update'; |
||
27 | const ACTION_DELETE = 'delete'; |
||
28 | |||
29 | const OPTION_ID_NAME = 'id_name'; |
||
30 | const OPTION_ID_REGEX = 'id_regex'; |
||
31 | const OPTION_ONLY = 'only'; |
||
32 | const OPTION_EXCEPT = 'except'; |
||
33 | const OPTION_AS = 'as'; |
||
34 | const OPTION_ACTIONS = 'actions'; |
||
35 | |||
36 | const SEPARATOR = ':'; |
||
37 | const CONTROLLER_ACTION_SEPARATOR = '#'; |
||
38 | |||
39 | /** |
||
40 | * @param string $name |
||
41 | * @param string $controller |
||
42 | * @param array $actions Action templates. |
||
43 | * @param array $options The following options are available: |
||
44 | * |
||
45 | * - `only`: Only the routes specified are made. |
||
46 | * - `except`: The routes specified are excluded. |
||
47 | * - `id_name`: Name of the identifier property. Defaults to `id`. |
||
48 | * - `id_regex`: Regex of the identifier value. Defaults to `\d+`. |
||
49 | * - `as`: Specifies the `as` option of the routes created. |
||
50 | * |
||
51 | * @return array |
||
52 | */ |
||
53 | static public function actions($name, $controller, $actions, array $options = []) |
||
79 | |||
80 | /** |
||
81 | * Makes route definitions for a resource. |
||
82 | * |
||
83 | * @param string $name |
||
84 | * @param string $controller |
||
85 | * @param array $options The following options are available: |
||
86 | * |
||
87 | * - `only`: Only the routes specified are made. |
||
88 | * - `except`: The routes specified are excluded. |
||
89 | * - `id_name`: Name of the identifier property. Defaults to `id`. |
||
90 | * - `id_regex`: Regex of the identifier value. Defaults to `\d+`. |
||
91 | * - `as`: Specifies the `as` option of the routes created. |
||
92 | * - `actions`: Additional actions templates. |
||
93 | * |
||
94 | * @return array |
||
95 | */ |
||
96 | static public function resource($name, $controller, array $options = []) |
||
103 | |||
104 | /** |
||
105 | * Normalizes options. |
||
106 | * |
||
107 | * @param array $options |
||
108 | * |
||
109 | * @return array |
||
110 | */ |
||
111 | static protected function normalize_options(array $options) |
||
124 | |||
125 | /** |
||
126 | * Returns default resource actions. |
||
127 | * |
||
128 | * @return array |
||
129 | */ |
||
130 | static protected function get_resource_actions() |
||
144 | |||
145 | /** |
||
146 | * Filters actions according to only/except options. |
||
147 | * |
||
148 | * @param array $actions |
||
149 | * @param array $options |
||
150 | * |
||
151 | * @return array |
||
152 | */ |
||
153 | static protected function filter_actions(array $actions, array $options = []) |
||
167 | |||
168 | /** |
||
169 | * Replaces pattern placeholders. |
||
170 | * |
||
171 | * @param string $name |
||
172 | * @param array $actions |
||
173 | * @param array $options |
||
174 | * |
||
175 | * @return array |
||
176 | */ |
||
177 | static protected function resolve_patterns($name, array $actions, $options) |
||
189 | } |
||
190 |