Caution: The documentation you are viewing is
for an older version of Zend Framework.
You can find the documentation of the current version at:
https://docs.zendframework.com/zend-config/
Zend\Config\Processor — Zend Framework 2 2.1.5 documentation
Zend\Config\Processor gives you the ability to perform some operations on a Zend\Config\Config object. The Zend\Config\Processor is an interface that defines two methods: process() and processValue(). These operations are provided by the following concrete implementations:
Below we reported some examples for each type of processor.
Using Zend\Config\Processor\Constant
This example illustrates the basic use of Zend\Config\Processor\Constant:
1 2 3 4 5 6 7 8
define ('TEST_CONST', 'bar'); // set true to Zend\Config\Config to allow modifications $config = new Zend\Config\Config(array('foo' => 'TEST_CONST'), true); $processor = new Zend\Config\Processor\Constant(); echo $config->foo . ','; $processor->process($config); echo $config->foo;
This example returns the output: TEST_CONST, bar..
Using Zend\Config\Processor\Filter
This example illustrates the basic use of Zend\Config\Processor\Filter:
1 2 3 4 5 6 7 8 9 10 11 12
use Zend\Filter\StringToUpper; use Zend\Config\Processor\Filter as FilterProcessor; use Zend\Config\Config; $config = new Config(array ('foo' => 'bar'), true); $upper = new StringToUpper(); $upperProcessor = new FilterProcessor($upper); echo $config->foo . ','; $upperProcessor->process($config); echo $config->foo;
This example returns the output: bar,BAR.
Using Zend\Config\Processor\Queue
This example illustrates the basic use of Zend\Config\Processor\Queue:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
use Zend\Filter\StringToLower; use Zend\Filter\StringToUpper; use Zend\Config\Processor\Filter as FilterProcessor; use Zend\Config\Processor\Queue; use Zend\Config\Config; $config = new Config(array ('foo' => 'bar'), true); $upper = new StringToUpper(); $lower = new StringToLower(); $lowerProcessor = new FilterProcessor($lower); $upperProcessor = new FilterProcessor($upper); $queue = new Queue(); $queue->insert($upperProcessor); $queue->insert($lowerProcessor); $queue->process($config); echo $config->foo;
This example returns the output: bar. The filters in the queue are applied with a FIFO logic (First In, First Out).
Using Zend\Config\Processor\Token
This example illustrates the basic use of Zend\Config\Processor\Token:
1 2 3 4 5 6 7 8
// set the Config to true to allow modifications $config = new Config(array('foo' => 'Value is TOKEN'), true); $processor = new TokenProcessor(); $processor->addToken('TOKEN', 'bar'); echo $config->foo . ','; $processor->process($config); echo $config->foo;
This example returns the output: Value is TOKEN,Value is bar.
Using Zend\Config\Processor\Translator
This example illustrates the basic use of Zend\Config\Processor\Translator:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
use Zend\Config\Config; use Zend\Config\Processor\Translator as TranslatorProcessor; use Zend\I18n\Translator\Translator; $config = new Config(array('animal' => 'dog'), true); /* * The following mapping would exist for the translation * loader you provide to the translator instance * $italian = array( * 'dog' => 'cane' * ); */ $translator = new Translator(); // ... configure the translator ... $processor = new TranslatorProcessor($translator); echo "English: {$config->animal}, "; $processor->process($config); echo "Italian: {$config->animal}";
This example returns the output: English: dog, Italian: cane.