Example #1
0
 public function asConfig()
 {
     $bbcodes = parent::asConfig();
     foreach ($bbcodes as $bbcodeName => &$bbcode) {
         if (isset($bbcode['tagName']) && TagName::isValid($bbcodeName) && TagName::normalize($bbcodeName) === $bbcode['tagName']) {
             unset($bbcode['tagName']);
         }
         if (isset($bbcode['defaultAttribute']) && AttributeName::isValid($bbcodeName) && AttributeName::normalize($bbcodeName) === $bbcode['defaultAttribute']) {
             unset($bbcode['defaultAttribute']);
         }
     }
     unset($bbcode);
     return new Dictionary($bbcodes);
 }
 /**
  * {@inheritdoc}
  *
  * This method will remove redundant info such as the BBCode's tagName or defaultAttribute values
  * if they are the same as their default values
  */
 public function asConfig()
 {
     $bbcodes = parent::asConfig();
     foreach ($bbcodes as $bbcodeName => &$bbcode) {
         // Remove the tag name if it's the same name as the BBCode
         if (isset($bbcode['tagName']) && TagName::isValid($bbcodeName) && TagName::normalize($bbcodeName) === $bbcode['tagName']) {
             unset($bbcode['tagName']);
         }
         // Remove the defaultAttribute name if it's the same name as the BBCode
         if (isset($bbcode['defaultAttribute']) && AttributeName::isValid($bbcodeName) && AttributeName::normalize($bbcodeName) === $bbcode['defaultAttribute']) {
             unset($bbcode['defaultAttribute']);
         }
     }
     unset($bbcode);
     return new Dictionary($bbcodes);
 }
 /**
  * Return a value from this collection
  *
  * @param  string $key
  * @return \s9e\TextFormatter\Configurator\Items\ProgrammableCallback
  */
 public function get($key)
 {
     $key = $this->normalizeKey($key);
     if (!$this->exists($key)) {
         if ($key[0] === '#') {
             $this->set($key, self::getDefaultFilter(substr($key, 1)));
         } else {
             $this->set($key, new AttributeFilter($key));
         }
     }
     // Get the filter from the collection
     $filter = parent::get($key);
     // Clone it to preserve the original instance
     $filter = clone $filter;
     return $filter;
 }
 /**
  * Custom offsetSet() implementation to allow assignment with a null offset to append to the
  * chain
  *
  * @param  mixed $offset
  * @param  mixed $value
  * @return void
  */
 public function offsetSet($offset, $value)
 {
     if ($offset === null) {
         // $list[] = 'foo' maps to $list->append('foo')
         $this->append($value);
     } else {
         // Use the default implementation
         parent::offsetSet($offset, $value);
     }
 }
 /**
  * @testdox A collection proxy is iterable with foreach
  */
 public function testIterable()
 {
     $collection = new NormalizedCollection();
     $collection->add('one', 1);
     $collection->add('two', 2);
     $proxy = new CollectionProxyDummy($collection);
     $actual = [];
     foreach ($proxy as $k => $v) {
         $actual[$k] = $v;
     }
     $this->assertSame(['one' => 1, 'two' => 2], $actual);
 }
 /**
  * {@inheritdoc}
  */
 public function asConfig()
 {
     $plugins = parent::asConfig();
     // Adjust plugins' default properties
     foreach ($plugins as $pluginName => &$pluginConfig) {
         $plugin = $this->get($pluginName);
         // Add base properties
         $pluginConfig += $plugin->getBaseProperties();
         // Remove quickMatch if it's false
         if ($pluginConfig['quickMatch'] === false) {
             unset($pluginConfig['quickMatch']);
         }
         // Remove regexpLimit if there's no regexp
         if (!isset($pluginConfig['regexp'])) {
             unset($pluginConfig['regexpLimit']);
         }
         // Add the JavaScript parser (generated dynamically)
         if (!isset($pluginConfig['parser'])) {
             $pluginConfig['parser'] = new Variant();
             $pluginConfig['parser']->setDynamic('JS', [$plugin, 'getJSParser']);
         }
         // Remove className if it's a default plugin using its default name. Its class name will
         // be generated by the parser automatically
         $className = 's9e\\TextFormatter\\Plugins\\' . $pluginName . '\\Parser';
         if ($pluginConfig['className'] === $className) {
             unset($pluginConfig['className']);
         }
     }
     unset($pluginConfig);
     return $plugins;
 }
 /**
  * @testdox asConfig() returns the elements in lexical order
  */
 public function testAsConfigLexicalOrder()
 {
     $collection = new NormalizedCollection();
     $collection->add('foo', 'foo');
     $collection->add('bar', 'bar');
     $this->assertSame(['bar' => 'bar', 'foo' => 'foo'], $collection->asConfig());
 }