Teknik is a suite of services with attractive and functional interfaces. https://www.teknik.io/
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.

Registry.php 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * Piwik - free/libre analytics platform
  4. *
  5. * @link http://piwik.org
  6. * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
  7. *
  8. */
  9. namespace Piwik;
  10. /**
  11. * Registry class.
  12. *
  13. * @method static \Piwik\Registry getInstance()
  14. */
  15. class Registry extends Singleton
  16. {
  17. private $data;
  18. protected function __construct()
  19. {
  20. $this->data = array();
  21. }
  22. public static function isRegistered($key)
  23. {
  24. return self::getInstance()->hasKey($key);
  25. }
  26. public static function get($key)
  27. {
  28. return self::getInstance()->getKey($key);
  29. }
  30. public static function set($key, $value)
  31. {
  32. self::getInstance()->setKey($key, $value);
  33. }
  34. public function setKey($key, $value)
  35. {
  36. $this->data[$key] = $value;
  37. }
  38. public function getKey($key)
  39. {
  40. if (!$this->hasKey($key)) {
  41. throw new \Exception(sprintf("Key '%s' doesn't exist in Registry", $key));
  42. }
  43. return $this->data[$key];
  44. }
  45. public function hasKey($key)
  46. {
  47. return array_key_exists($key, $this->data);
  48. }
  49. }