public function serialize(ShortcodeInterface $shortcode)
 {
     $open = $this->syntax->getOpeningTag();
     $close = $this->syntax->getClosingTag();
     $marker = $this->syntax->getClosingTagMarker();
     $parameters = $this->serializeParameters($shortcode->getParameters());
     $bbCode = null !== $shortcode->getBbCode() ? $this->serializeValue($shortcode->getBbCode()) : '';
     $return = $open . $shortcode->getName() . $bbCode . $parameters;
     return null === $shortcode->getContent() ? $return . ' ' . $marker . $close : $return . $close . $shortcode->getContent() . $open . $marker . $shortcode->getName() . $close;
 }
 /**
  * @dataProvider provideUnserialized
  */
 public function testUnserialize(SerializerInterface $serializer, ShortcodeInterface $test, $text)
 {
     $tested = $serializer->unserialize($text);
     $this->assertSame($test->getName(), $tested->getName(), 'name: ' . $text);
     $this->assertSame($test->getParameters(), $tested->getParameters(), 'parameters: ' . $text);
     $this->assertSame($test->getContent(), $tested->getContent(), 'content: ' . $text);
     $this->assertSame($test->getBbCode(), $tested->getBbCode(), 'bbCode: ' . $text);
 }
 /**
  * <shortcode name="NAME">
  *   <bbCode>BBCODE</bbCode>
  *   <parameters>
  *     <parameter name="KEY">VALUE</parameter>
  *     <parameter name="KEY">VALUE</parameter>
  *   </parameters>
  *   <content>CONTENT></content>
  * </shortcode>
  *
  * @param ShortcodeInterface $shortcode
  *
  * @return string
  */
 public function serialize(ShortcodeInterface $shortcode)
 {
     $doc = new \DOMDocument('1.0', 'UTF-8');
     $doc->preserveWhiteSpace = false;
     $doc->formatOutput = true;
     $code = $doc->createElement('shortcode');
     $code->setAttribute('name', $shortcode->getName());
     $xml = $doc->appendChild($code);
     $xml->appendChild($this->createCDataNode($doc, 'bbCode', $shortcode->getBbCode()));
     $parameters = $xml->appendChild($doc->createElement('parameters'));
     foreach ($shortcode->getParameters() as $key => $value) {
         $parameter = $doc->createElement('parameter');
         $parameter->setAttribute('name', $key);
         if (null !== $value) {
             $parameter->appendChild($doc->createCDATASection($value));
         }
         $parameters->appendChild($parameter);
     }
     $xml->appendChild($this->createCDataNode($doc, 'content', $shortcode->getContent()));
     return $doc->saveXML();
 }
 /**
  * [email="*****@*****.**"]Contact me![/email]
  * [email="*****@*****.**" /]
  * [email]example@example.org[/email]
  *
  * @param ShortcodeInterface $shortcode
  *
  * @return string
  */
 public function __invoke(ShortcodeInterface $shortcode)
 {
     $email = $shortcode->getBbCode() ?: $shortcode->getContent();
     $content = $shortcode->getContent() === null ? $email : $shortcode->getContent();
     return '<a href="mailto:' . $email . '">' . $content . '</a>';
 }
 public function serialize(ShortcodeInterface $shortcode)
 {
     return json_encode(array('name' => $shortcode->getName(), 'parameters' => $shortcode->getParameters(), 'content' => $shortcode->getContent(), 'bbCode' => $shortcode->getBbCode()));
 }
 /**
  * [url="http://example.org"]Click![/url]
  * [url="http://example.org" /]
  * [url]http://example.org[/url]
  *
  * @param ShortcodeInterface $shortcode
  *
  * @return string
  */
 public function __invoke(ShortcodeInterface $shortcode)
 {
     $url = $shortcode->getBbCode() ?: $shortcode->getContent();
     return '<a href="' . $url . '">' . $shortcode->getContent() . '</a>';
 }