3 * Zend Framework (http://framework.zend.com/)
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
10 namespace Zend\Config\Processor
;
12 class Constant
extends Token
implements ProcessorInterface
15 * Replace only user-defined tokens
19 protected $userOnly = true;
22 * Constant Processor walks through a Config structure and replaces all
23 * PHP constants with their respective values
25 * @param bool $userOnly True to process only user-defined constants, false to process all PHP constants
26 * @param string $prefix Optional prefix
27 * @param string $suffix Optional suffix
28 * @return \Zend\Config\Processor\Constant
30 public function __construct($userOnly = true, $prefix = '', $suffix = '')
32 $this->setUserOnly($userOnly);
33 $this->setPrefix($prefix);
34 $this->setSuffix($suffix);
36 $this->loadConstants();
42 public function getUserOnly()
44 return $this->userOnly
;
48 * Should we use only user-defined constants?
50 * @param bool $userOnly
53 public function setUserOnly($userOnly)
55 $this->userOnly
= (bool) $userOnly;
60 * Load all currently defined constants into parser.
64 public function loadConstants()
66 if ($this->userOnly
) {
67 $constants = get_defined_constants(true);
68 $constants = isset($constants['user']) ?
$constants['user'] : array();
69 $this->setTokens($constants);
71 $this->setTokens(get_defined_constants());
76 * Get current token registry.
79 public function getTokens()