PageRenderTime 49ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/fuel/packages/auth/classes/auth/acl/driver.php

https://bitbucket.org/codeyash/bootstrap
PHP | 95 lines | 45 code | 17 blank | 33 comment | 6 complexity | 09cc2ae39f131b6e336afcca4ac8086d MD5 | raw file
Possible License(s): MIT, Apache-2.0
  1. <?php
  2. /**
  3. * Fuel is a fast, lightweight, community driven PHP5 framework.
  4. *
  5. * @package Fuel
  6. * @version 1.5
  7. * @author Fuel Development Team
  8. * @license MIT License
  9. * @copyright 2010 - 2013 Fuel Development Team
  10. * @link http://fuelphp.com
  11. */
  12. namespace Auth;
  13. abstract class Auth_Acl_Driver extends \Auth_Driver
  14. {
  15. /**
  16. * @var Auth_Driver default instance
  17. */
  18. protected static $_instance = null;
  19. /**
  20. * @var array contains references if multiple were loaded
  21. */
  22. protected static $_instances = array();
  23. public static function forge(array $config = array())
  24. {
  25. // default driver id to driver name when not given
  26. ! array_key_exists('id', $config) && $config['id'] = $config['driver'];
  27. $class = \Inflector::get_namespace($config['driver']).'Auth_Acl_'.ucfirst(\Inflector::denamespace($config['driver']));
  28. $driver = new $class($config);
  29. static::$_instances[$driver->get_id()] = $driver;
  30. is_null(static::$_instance) and static::$_instance = $driver;
  31. foreach ($driver->get_config('drivers', array()) as $type => $drivers)
  32. {
  33. foreach ($drivers as $d => $custom)
  34. {
  35. $custom = is_int($d)
  36. ? array('driver' => $custom)
  37. : array_merge($custom, array('driver' => $d));
  38. $class = 'Auth_'.ucfirst($type).'_Driver';
  39. $class::forge($custom);
  40. }
  41. }
  42. return $driver;
  43. }
  44. /**
  45. * Parses a conditions string into it's array equivalent
  46. *
  47. * @rights mixed conditions array or string
  48. * @return array conditions array formatted as array(area, rights)
  49. *
  50. */
  51. public static function _parse_conditions($rights)
  52. {
  53. if (is_array($rights))
  54. {
  55. return $rights;
  56. }
  57. if ( ! is_string($rights) or strpos($rights, '.') === false)
  58. {
  59. throw new \InvalidArgumentException('Given rights where not formatted proppery. Formatting should be like area.right or area.[right, other_right]. Received: '.$rights);
  60. }
  61. list($area, $rights) = explode('.', $rights);
  62. if (substr($rights, 0, 1) == '[' and substr($rights, -1, 1) == ']')
  63. {
  64. $rights = preg_split('#( *)?,( *)?#', trim(substr($rights, 1, -1)));
  65. }
  66. return array($area, $rights);
  67. }
  68. // ------------------------------------------------------------------------
  69. /**
  70. * Check access rights
  71. *
  72. * @param mixed condition to check for access
  73. * @param mixed user or group identifier in the form of array(driver_id, id)
  74. * @return bool
  75. */
  76. abstract public function has_access($condition, Array $entity);
  77. }
  78. /* end of file driver.php */