PageRenderTime 105ms CodeModel.GetById 23ms RepoModel.GetById 5ms app.codeStats 0ms

/modules/sprig-aacl/classes/sprig/aacl.php

https://bitbucket.org/seyar/startech.local
PHP | 101 lines | 48 code | 10 blank | 43 comment | 4 complexity | 666d4a4e96849abab43b9266042e6b89 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1
  1. <?php defined('SYSPATH') or die ('No direct script access.');
  2. /**
  3. * Base class for access controlled Sprig Models
  4. *
  5. * @see http://github.com/banks/aacl
  6. * @package AACL
  7. * @uses Auth
  8. * @uses Sprig
  9. * @author Paul Banks
  10. * @copyright (c) Paul Banks 2010
  11. * @license MIT
  12. */
  13. abstract class Sprig_AACL extends Sprig implements AACL_Resource
  14. {
  15. /**
  16. * AACL_Resource::acl_id() implementation
  17. *
  18. * @return string
  19. */
  20. public function acl_id()
  21. {
  22. // Create unique id from primary key if it is set
  23. if (is_array($this->_primary_key))
  24. {
  25. $id = '';
  26. foreach ($this->_primary_key as $name)
  27. {
  28. $id .= (string) $this->$name;
  29. }
  30. }
  31. else
  32. {
  33. $id = (string) $this->{$this->_primary_key};
  34. }
  35. if ( ! empty($id))
  36. {
  37. $id = '.'.$id;
  38. }
  39. // Model namespace, model name, pk
  40. return 'm:'.strtolower($this->_model).$id;
  41. }
  42. /**
  43. * AACL_Resource::acl_actions() implementation
  44. *
  45. * @param bool $return_current [optional]
  46. * @return mixed
  47. */
  48. public function acl_actions($return_current = FALSE)
  49. {
  50. if ($return_current)
  51. {
  52. // We don't know anything about what the user intends to do with us!
  53. return NULL;
  54. }
  55. // Return default model actions
  56. return array('create', 'read', 'update', 'delete');
  57. }
  58. /**
  59. * AACL_Resource::acl_conditions() implementation
  60. *
  61. * @param Model_User $user [optional] logged in user model
  62. * @param object $condition [optional] condition to test
  63. * @return mixed
  64. */
  65. public function acl_conditions(Model_User $user = NULL, $condition = NULL)
  66. {
  67. if (is_null($user) AND is_null($condition))
  68. {
  69. // We have no conditions - they will be model specific
  70. return array();
  71. }
  72. else
  73. {
  74. // We have no conditions so this test should fail!
  75. return FALSE;
  76. }
  77. }
  78. /**
  79. * AACL_Resource::acl_instance() implementation
  80. *
  81. * Note that the object instance returned should not be used for anything except querying the acl_* methods
  82. *
  83. * @param string Class name of object required
  84. * @return Object
  85. */
  86. public static function acl_instance($class_name)
  87. {
  88. $model_name = strtolower(substr($class_name, 6));
  89. return Sprig::factory($model_name);
  90. }
  91. } // End Sprig_AACL