Пример #1
0
 /**
  * @param $value
  * @param $filter
  * @throws \Twig_Error_Runtime
  * @return \FM\BbcodeBundle\Decoda\Decoda
  */
 public function filter($value, $filter)
 {
     if (!is_string($value)) {
         throw new \Twig_Error_Runtime('The filter can be applied to strings only.');
     }
     $messages = $this->container->getParameter('fm_bbcode.config.messages');
     $messages = empty($messages) ? array() : json_decode(\file_get_contents($messages), true);
     $code = new Decoda($value, $messages);
     $current_filter = $this->filter_sets[$filter];
     $locale = $current_filter['locale'];
     $xhtml = $current_filter['xhtml'];
     if (empty($locale)) {
         // apply locale from the session
         if ('default' == $this->locale) {
             $code->setLocale($this->container->get('session')->getLocale());
             // apply locale defined in the configuration
         } else {
             // apply locale from the template
             $code->setLocale($this->locale);
         }
     } else {
         $code->setLocale($locale);
     }
     if (true === $xhtml) {
         $code->setXhtml(true);
     }
     $decoda_manager = new DecodaManager($code, $current_filter['filters'], $current_filter['hooks'], $current_filter['whitelist']);
     return $decoda_manager->getResult()->parse();
 }
Пример #2
0
 /**
  * Strip tags.
  *
  * @param $value
  * @param $filterSet
  *
  * @return string
  *
  * @throws \Twig_Error_Runtime
  */
 public function clean($value, $filterSet = DecodaManager::DECODA_DEFAULT)
 {
     if (!is_string($value)) {
         throw new \Twig_Error_Runtime('The filter can be applied to strings only.');
     }
     return $this->decodaManager->get($value, $filterSet)->strip(true);
 }
 public function testSetHook()
 {
     $hook = $this->getMock('Decoda\\Hook');
     $this->object->setHook('foo', $hook);
     $this->assertTrue($this->object->hasHook('foo'));
     $this->assertSame($hook, $this->object->getHook('foo'));
 }