/**
  * {@inheritdoc}
  */
 public function setNormalizers(array $normalizers)
 {
     $this->validateOptionsExistence($normalizers);
     foreach ($normalizers as $option => $normalizer) {
         $this->defaultOptions->setNormalizer($option, $normalizer);
     }
     return $this;
 }
Exemple #2
0
 /**
  * Sets normalizers that are applied on resolved options.
  *
  * The normalizers should be closures with the following signature:
  *
  * <code>
  * function (Options $options, $value)
  * </code>
  *
  * The second parameter passed to the closure is the value of
  * the option.
  *
  * The closure should return the normalized value.
  *
  * @param array $normalizers An array of closures
  *
  * @return OptionsConfig This configuration instance
  */
 public function setNormalizers(array $normalizers)
 {
     Options::validateNames($normalizers, $this->knownOptions, true);
     foreach ($normalizers as $option => $normalizer) {
         $this->defaultOptions->setNormalizer($option, $normalizer);
     }
     return $this;
 }
 public function testNormalizerWithoutCorrespondingOption()
 {
     $test = $this;
     $this->options->setNormalizer('foo', function (Options $options, $previousValue) use($test) {
         $test->assertNull($previousValue);
         return '';
     });
     $this->assertEquals(array('foo' => ''), $this->options->all());
 }
 public function testAllInvokesEachNormalizerOnlyOnce()
 {
     $test = $this;
     $i = 1;
     $this->options->set('foo', 'bar');
     $this->options->set('bam', 'baz');
     $this->options->setNormalizer('foo', function (Options $options) use($test, &$i) {
         $test->assertSame(1, $i);
         ++$i;
         // Implicitly invoke normalizer for "bam"
         $options->get('bam');
     });
     $this->options->setNormalizer('bam', function (Options $options) use($test, &$i) {
         $test->assertSame(2, $i);
         ++$i;
     });
     $this->options->all();
 }