modaccess.class.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /*
  3. * This file is part of MODX Revolution.
  4. *
  5. * Copyright (c) MODX, LLC. All Rights Reserved.
  6. *
  7. * For complete copyright and license information, see the COPYRIGHT and LICENSE
  8. * files found in the top-level directory of this distribution.
  9. */
  10. /**
  11. * Defines an access control policy between a principal and a target object.
  12. *
  13. * {@internal Implement derivatives to define a policy relationship to a
  14. * specific target class, which must extend modAccessibleObject or
  15. * modAccessibleSimpleObject, and must have an integer or string primary key.}
  16. *
  17. * @param string $target The target this ACL is attached to
  18. * @param string $principal_class The class key of the principal this ACL is attached to
  19. * @param int $principal The ID of the principal this ACL is attached to
  20. * @param int $authority The minimum authority level required to obtain this ACL
  21. * @param int $policy The ID of the modAccessPolicy that is attached to this ACL
  22. *
  23. * @abstract
  24. * @package modx
  25. */
  26. class modAccess extends xPDOSimpleObject {
  27. /**
  28. * Override getOne to get the appropriate Principal class.
  29. *
  30. * @param $alias
  31. * @param null $criteria
  32. * @param bool $cacheFlag
  33. * @return null|xPDOObject
  34. */
  35. public function & getOne($alias, $criteria= null, $cacheFlag= true) {
  36. $object = null;
  37. if ($alias === 'Principal') {
  38. if ($fkdef= $this->getFKDefinition($alias)) {
  39. $k= $fkdef['local'];
  40. $fk= $fkdef['foreign'];
  41. if (isset ($this->_relatedObjects[$alias])) {
  42. if (is_object($this->_relatedObjects[$alias])) {
  43. $object= & $this->_relatedObjects[$alias];
  44. return $object;
  45. }
  46. }
  47. if ($criteria === null) {
  48. $criteria= array(
  49. $fk => $this->get($k),
  50. );
  51. }
  52. $fkdef['class'] = $this->get('principal_class');
  53. if ($object= $this->xpdo->getObject($fkdef['class'], $criteria, $cacheFlag)) {
  54. $this->_relatedObjects[$alias]= $object;
  55. }
  56. }
  57. } else {
  58. $object = parent::getOne($alias, $criteria, $cacheFlag);
  59. }
  60. return $object;
  61. }
  62. }