PageRenderTime 39ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/seyar/ari100krat.local
PHP | 104 lines | 47 code | 13 blank | 44 comment | 4 complexity | 44487cb374ef05fb121f9ca1e7499c36 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 controllers
  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 Controller_AACL extends Controller_Template implements AACL_Resource
  14. {
  15. /**
  16. * AACL_Resource::acl_id() implementation
  17. *
  18. * @return string
  19. */
  20. public function acl_id()
  21. {
  22. // Controller namespace, controller name
  23. return 'c:'.strtolower($this->request->controller);
  24. }
  25. /**
  26. * AACL_Resource::acl_actions() implementation
  27. *
  28. * @param bool $return_current [optional]
  29. * @return mixed
  30. */
  31. public function acl_actions($return_current = FALSE)
  32. {
  33. if ($return_current)
  34. {
  35. return $this->request->action;
  36. }
  37. // Find all actions in this class
  38. $reflection = new ReflectionClass($this);
  39. $actions = array();
  40. // Add all public methods that start with 'action_'
  41. foreach ($reflection->getMethods(ReflectionMethod::IS_PUBLIC) as $method)
  42. {
  43. if (substr($method->name, 0, 7) === 'action_')
  44. {
  45. $actions[] = substr($method->name, 7);
  46. }
  47. }
  48. return $actions;
  49. }
  50. /**
  51. * AACL_Resource::acl_conditions() implementation
  52. *
  53. * @param Model_User $user [optional] logged in user model
  54. * @param object $condition [optional] condition to test
  55. * @return mixed
  56. */
  57. public function acl_conditions(Model_User $user = NULL, $condition = NULL)
  58. {
  59. if (is_null($user) AND is_null($condition))
  60. {
  61. // We have no conditions
  62. return array();
  63. }
  64. else
  65. {
  66. // We have no conditions so this test should fail!
  67. return FALSE;
  68. }
  69. }
  70. /**
  71. * AACL_Resource::acl_instance() implementation
  72. *
  73. * Note that the object instance returned should not be used for anything except querying the acl_* methods
  74. *
  75. * @param string Class name of object required
  76. * @return Object
  77. */
  78. public static function acl_instance($class_name)
  79. {
  80. // Return controller instance populated with manipulated request details
  81. $instance = new $class_name(Request::instance());
  82. $controller_name = strtolower(substr($class_name, 11));
  83. if ($controller_name !== Request::instance()->controller)
  84. {
  85. // Manually override controller name and action
  86. $instance->request->controller = strtolower(substr(get_class($this), 11));
  87. $instance->request->action = NULL;
  88. }
  89. return $instance;
  90. }
  91. } // End Controller_AACL