Route.php
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * ====================================================================== |
| 5 | * LICENSE: This file is subject to the terms and conditions defined in * |
| 6 | * file 'license.txt', which is part of this source code package. * |
| 7 | * ====================================================================== |
| 8 | */ |
| 9 | |
| 10 | /** |
| 11 | * API route object |
| 12 | * |
| 13 | * @since 6.5.0 https://github.com/aamplugin/advanced-access-manager/issues/105 |
| 14 | * @since 6.4.0 Enhancement https://github.com/aamplugin/advanced-access-manager/issues/56 |
| 15 | * @since 6.1.0 Fixed bug with incorrectly halted inheritance mechanism |
| 16 | * @since 6.0.0 Initial implementation of the class |
| 17 | * |
| 18 | * @package AAM |
| 19 | * @version 6.5.0 |
| 20 | */ |
| 21 | class AAM_Core_Object_Route extends AAM_Core_Object |
| 22 | { |
| 23 | |
| 24 | /** |
| 25 | * Type of object |
| 26 | * |
| 27 | * @version 6.0.0 |
| 28 | */ |
| 29 | const OBJECT_TYPE = 'route'; |
| 30 | |
| 31 | /** |
| 32 | * @inheritdoc |
| 33 | * |
| 34 | * @since 6.5.0 https://github.com/aamplugin/advanced-access-manager/issues/105 |
| 35 | * @since 6.1.0 Fixed bug with incorrectly halted inheritance mechanism |
| 36 | * @since 6.0.0 Initial implementation of the method |
| 37 | * |
| 38 | * @version 6.5.0 |
| 39 | */ |
| 40 | protected function initialize() |
| 41 | { |
| 42 | $option = $this->getSubject()->readOption('route'); |
| 43 | |
| 44 | $this->determineOverwritten($option); |
| 45 | |
| 46 | // Trigger custom functionality that may populate the menu options. For |
| 47 | // example, this hooks is used by Access Policy service |
| 48 | $option = apply_filters('aam_route_object_option_filter', $option, $this); |
| 49 | |
| 50 | // Making sure that all menu keys are lowercase |
| 51 | $normalized = array(); |
| 52 | foreach($option as $key => $val) { |
| 53 | $normalized[strtolower($key)] = $val; |
| 54 | } |
| 55 | |
| 56 | $this->setOption(is_array($normalized) ? $normalized : array()); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Check if route is restricted |
| 61 | * |
| 62 | * @param string $type REST or XMLRPC |
| 63 | * @param string $route |
| 64 | * @param string $method |
| 65 | * |
| 66 | * @return boolean |
| 67 | * |
| 68 | * @since 6.4.0 Added `aam_route_match_filter` to support enhancement |
| 69 | * https://github.com/aamplugin/advanced-access-manager/issues/56 |
| 70 | * @since 6.0.0 Initial implementation of the method |
| 71 | * |
| 72 | * @access public |
| 73 | * @version 6.4.0 |
| 74 | */ |
| 75 | public function isRestricted($type, $route, $method = 'POST') |
| 76 | { |
| 77 | $options = $this->getOption(); |
| 78 | $id = strtolower("{$type}|{$route}|{$method}"); |
| 79 | $matched = !empty($options[$id]); |
| 80 | |
| 81 | if ($matched === false) { |
| 82 | $matched = apply_filters( |
| 83 | 'aam_route_match_filter', false, $type, $route, $method, $this |
| 84 | ); |
| 85 | } |
| 86 | |
| 87 | return $matched; |
| 88 | } |
| 89 | |
| 90 | } |