Factory.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 | * AAM core policy manager factory |
| 12 | * |
| 13 | * @since 6.1.0 Fixed bug with incorrectly managed internal cache |
| 14 | * @since 6.0.0 Initial implementation of the class |
| 15 | * |
| 16 | * @package AAM |
| 17 | * @version 6.1.0 |
| 18 | */ |
| 19 | final class AAM_Core_Policy_Factory |
| 20 | { |
| 21 | |
| 22 | /** |
| 23 | * Collection of policy manage instances |
| 24 | * |
| 25 | * @var array |
| 26 | * |
| 27 | * @access private |
| 28 | * @version 6.0.0 |
| 29 | */ |
| 30 | private static $_instances = array(); |
| 31 | |
| 32 | /** |
| 33 | * Get single instance of access manager |
| 34 | * |
| 35 | * @param AAM_Core_Subject $subject |
| 36 | * @param boolean $skipInheritance |
| 37 | * |
| 38 | * @return AAM_Core_Policy_Manager |
| 39 | * |
| 40 | * @since 6.1.0 Fixed bug with incorrectly managed internal caching |
| 41 | * @since 6.0.0 Initial implementation of the method |
| 42 | * |
| 43 | * @access public |
| 44 | * @version 6.1.0 |
| 45 | */ |
| 46 | public static function get(AAM_Core_Subject $subject = null, $skipInheritance) |
| 47 | { |
| 48 | if (is_null($subject)) { |
| 49 | $subject = AAM::getUser(); |
| 50 | } |
| 51 | |
| 52 | $id = $subject->getId(); |
| 53 | |
| 54 | $sid = $subject::UID . (empty($id) ? '' : '_' . $id); |
| 55 | $sid .= ($skipInheritance ? '_direct' : '_complete'); |
| 56 | |
| 57 | if (!isset(self::$_instances[$sid])) { |
| 58 | self::$_instances[$sid] = new AAM_Core_Policy_Manager( |
| 59 | $subject, $skipInheritance |
| 60 | ); |
| 61 | |
| 62 | // Parse all attached to the user policies |
| 63 | self::$_instances[$sid]->initialize(); |
| 64 | } |
| 65 | |
| 66 | return self::$_instances[$sid]; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Reset internal cache |
| 71 | * |
| 72 | * @return void |
| 73 | * |
| 74 | * @access public |
| 75 | * @version 6.0.0 |
| 76 | */ |
| 77 | public static function reset() |
| 78 | { |
| 79 | self::$_instances = array(); |
| 80 | } |
| 81 | |
| 82 | } |