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

/vendor/zendframework/zendframework/library/Zend/Config/Processor/Constant.php

https://bitbucket.org/raulgracia/zendframework2
PHP | 83 lines | 36 code | 8 blank | 39 comment | 2 complexity | 3951e018f85e43928aab5c3294313a57 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * Zend Framework (http://framework.zend.com/)
  4. *
  5. * @link http://github.com/zendframework/zf2 for the canonical source repository
  6. * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
  7. * @license http://framework.zend.com/license/new-bsd New BSD License
  8. */
  9. namespace Zend\Config\Processor;
  10. class Constant extends Token implements ProcessorInterface
  11. {
  12. /**
  13. * Replace only user-defined tokens
  14. *
  15. * @var bool
  16. */
  17. protected $userOnly = true;
  18. /**
  19. * Constant Processor walks through a Config structure and replaces all
  20. * PHP constants with their respective values
  21. *
  22. * @param bool $userOnly True to process only user-defined constants, false to process all PHP constants
  23. * @param string $prefix Optional prefix
  24. * @param string $suffix Optional suffix
  25. * @return \Zend\Config\Processor\Constant
  26. */
  27. public function __construct($userOnly = true, $prefix = '', $suffix = '')
  28. {
  29. $this->setUserOnly($userOnly);
  30. $this->setPrefix($prefix);
  31. $this->setSuffix($suffix);
  32. $this->loadConstants();
  33. }
  34. /**
  35. * @return bool
  36. */
  37. public function getUserOnly()
  38. {
  39. return $this->userOnly;
  40. }
  41. /**
  42. * Should we use only user-defined constants?
  43. *
  44. * @param bool $userOnly
  45. * @return Constant
  46. */
  47. public function setUserOnly($userOnly)
  48. {
  49. $this->userOnly = (bool) $userOnly;
  50. return $this;
  51. }
  52. /**
  53. * Load all currently defined constants into parser.
  54. *
  55. * @return void
  56. */
  57. public function loadConstants()
  58. {
  59. if ($this->userOnly) {
  60. $constants = get_defined_constants(true);
  61. $constants = isset($constants['user']) ? $constants['user'] : array();
  62. $this->setTokens($constants);
  63. } else {
  64. $this->setTokens(get_defined_constants());
  65. }
  66. }
  67. /**
  68. * Get current token registry.
  69. * @return array
  70. */
  71. public function getTokens()
  72. {
  73. return $this->tokens;
  74. }
  75. }