Manager.php
105 lines
| 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 | * AAM core policy manager |
| 12 | * |
| 13 | * @package AAM |
| 14 | * @author Vasyl Martyniuk <vasyl@vasyltech.com> |
| 15 | * @since AAM v5.7.2 |
| 16 | */ |
| 17 | final class AAM_Core_Policy_Manager { |
| 18 | |
| 19 | /** |
| 20 | * Single instance of itself |
| 21 | * |
| 22 | * @var AAM_Core_Policy_Manager |
| 23 | * |
| 24 | * @access private |
| 25 | * @static |
| 26 | */ |
| 27 | private static $_instance = null; |
| 28 | |
| 29 | /** |
| 30 | * Policy core object |
| 31 | * |
| 32 | * @var AAM_Core_Object_Policy |
| 33 | * |
| 34 | * @access protected |
| 35 | */ |
| 36 | protected $policyObject; |
| 37 | |
| 38 | /** |
| 39 | * Constructor |
| 40 | * |
| 41 | * @access protected |
| 42 | * |
| 43 | * @return void |
| 44 | */ |
| 45 | protected function __construct() { |
| 46 | $this->policyObject = AAM::getUser()->getObject('policy'); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Find all the matching policies |
| 51 | * |
| 52 | * @param string $s RegEx |
| 53 | * @param AAM_Core_Subject $subject Subject to search for |
| 54 | * |
| 55 | * @return array |
| 56 | * |
| 57 | * @access public |
| 58 | */ |
| 59 | public function find($s, AAM_Core_Subject $subject = null) { |
| 60 | $statements = array(); |
| 61 | |
| 62 | // Get list of policies |
| 63 | if (is_null($subject)) { |
| 64 | $policies = $this->policyObject; |
| 65 | } else { |
| 66 | $policies = $subject->getObject('policy'); |
| 67 | } |
| 68 | |
| 69 | foreach($policies->getResources($subject) as $key => $stm) { |
| 70 | if (preg_match($s, $key)) { |
| 71 | $statements[strtolower($key)] = $stm; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | return $statements; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Get single instance of itself |
| 80 | * |
| 81 | * @return AAM_Core_Policy_Manager |
| 82 | * |
| 83 | * @access public |
| 84 | * @static |
| 85 | */ |
| 86 | public static function getInstance() { |
| 87 | if (is_null(self::$_instance)) { |
| 88 | self::$_instance = new self(); |
| 89 | } |
| 90 | |
| 91 | return self::$_instance; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Load the policy manager |
| 96 | * |
| 97 | * @return void |
| 98 | * |
| 99 | * @access public |
| 100 | * @static |
| 101 | */ |
| 102 | public static function bootstrap() { |
| 103 | self::getInstance(); |
| 104 | } |
| 105 | } |