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.

74 lines
1.7 KiB

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