/** * @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); }
public function serialize(ShortcodeInterface $shortcode) { $open = $this->syntax->getOpeningTag(); $close = $this->syntax->getClosingTag(); $marker = $this->syntax->getClosingTagMarker(); $parameters = $this->serializeParameters($shortcode->getParameters()); $return = $open . $shortcode->getName() . $parameters; return null === $shortcode->getContent() ? $return . ($shortcode instanceof ParsedShortcodeInterface && $shortcode->getMarkerOffset() ? ' ' . $marker : '') . $close : $return . $close . $shortcode->getContent() . $open . $marker . $shortcode->getName() . $close; }
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; }
/** * [declare name]Your name is %value%[/declare] * [name value="Thomas" /] * * @param ShortcodeInterface $shortcode */ public function __invoke(ShortcodeInterface $shortcode) { $args = $shortcode->getParameters(); if (empty($args)) { return; } $keys = array_keys($args); $name = array_shift($keys); $content = $shortcode->getContent(); $delimiter = $this->delimiter; $this->handlers->add($name, function (ShortcodeInterface $shortcode) use($content, $delimiter) { $args = $shortcode->getParameters(); $keys = array_map(function ($key) use($delimiter) { return $delimiter . $key . $delimiter; }, array_keys($args)); $values = array_values($args); return str_replace($keys, $values, $content); }); }
/** * [placeholder value=18]You age is %value%[/placeholder] * * @param ShortcodeInterface $shortcode * * @return mixed */ public function __invoke(ShortcodeInterface $shortcode) { $args = $shortcode->getParameters(); $delimiter = $this->delimiter; $keys = array_map(function ($key) use($delimiter) { return $delimiter . $key . $delimiter; }, array_keys($args)); $values = array_values($args); return str_replace($keys, $values, $shortcode->getContent()); }
/** * <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(); }
public function serialize(ShortcodeInterface $shortcode) { return json_encode(array('name' => $shortcode->getName(), 'parameters' => $shortcode->getParameters(), 'content' => $shortcode->getContent())); }
public function serialize(ShortcodeInterface $shortcode) { return Yaml::dump(array('name' => $shortcode->getName(), 'parameters' => $shortcode->getParameters(), 'content' => $shortcode->getContent(), 'bbCode' => $shortcode->getBbCode())); }