You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
1.8 KiB

10 years ago
10 years ago
10 years ago
  1. <?php namespace Majestic;
  2. /**
  3. * @copyright NetMonsters <team@netmonsters.ru>
  4. * @link http://netmonsters.ru
  5. * @package Majestic
  6. * @subpackage Model
  7. * @since 2010-02-17
  8. */
  9. class Registry extends \ArrayObject
  10. {
  11. /**
  12. * Class name of the singleton registry object.
  13. * @var string
  14. */
  15. private static $_class_name = 'Registry';
  16. /**
  17. * Registry object provides storage for shared objects.
  18. * @var Registry
  19. */
  20. private static $_registry = null;
  21. /**
  22. * Constructs a parent ArrayObject with default
  23. * ARRAY_AS_PROPS to allow acces as an object
  24. *
  25. * @param array $array data array
  26. * @param integer $flags ArrayObject flags
  27. */
  28. public function __construct($array = array(), $flags = parent::ARRAY_AS_PROPS)
  29. {
  30. parent::__construct($array, $flags);
  31. }
  32. /**
  33. * Refuse clone
  34. * @codeCoverageIgnoreStart
  35. */
  36. private function __clone()
  37. {
  38. }
  39. /**
  40. * @codeCoverageIgnoreEnd
  41. */
  42. /**
  43. * Retrieves the default registry instance.
  44. *
  45. * @return Registry
  46. */
  47. public static function getInstance()
  48. {
  49. if (self::$_registry === null) {
  50. self::$_registry = new \Majestic\Registry();
  51. }
  52. return self::$_registry;
  53. }
  54. static public function get($name, $default = null)
  55. {
  56. $instance = self::getInstance();
  57. if (!$instance->offsetExists($name)) {
  58. return $default;
  59. }
  60. return $instance->offsetGet($name);
  61. }
  62. public static function set($index, $value)
  63. {
  64. $instance = self::getInstance();
  65. $instance->offsetSet($index, $value);
  66. }
  67. public static function isRegistered($index)
  68. {
  69. if (self::$_registry === null) {
  70. return false;
  71. }
  72. return self::$_registry->offsetExists($index);
  73. }
  74. }