コード例 #1
0
ファイル: ParserTest.php プロジェクト: nasimnabavi/Shortcode
 public function testDifferentSyntaxEscapedQuotes()
 {
     $parser = new RegexParser(new Syntax('^', '$', '&', '!!!', '@@'));
     $shortcode = $parser->parse('^code a!!!@@\\"\\"@@ b!!!@@x\\"y@@ c$cnt^&code$');
     $this->assertSame('code', $shortcode[0]->getName());
     $this->assertSame(array('a' => '\\"\\"', 'b' => 'x\\"y', 'c' => null), $shortcode[0]->getParameters());
     $this->assertSame('cnt', $shortcode[0]->getContent());
 }
コード例 #2
0
 public function unserialize($text)
 {
     $parser = new RegexParser();
     $shortcodes = $parser->parse($text);
     if (empty($shortcodes)) {
         $msg = 'Failed to unserialize shortcode from text %s!';
         throw new \InvalidArgumentException(sprintf($msg, $text));
     }
     if (count($shortcodes) > 1) {
         $msg = 'Provided text %s contains more than one shortcode!';
         throw new \InvalidArgumentException(sprintf($msg, $text));
     }
     return array_shift($shortcodes);
 }
コード例 #3
0
 public function unserialize($text)
 {
     $parser = new RegexParser();
     $shortcodes = $parser->parse($text);
     if (empty($shortcodes)) {
         $msg = 'Failed to unserialize shortcode from text %s!';
         throw new \InvalidArgumentException(sprintf($msg, $text));
     }
     if (count($shortcodes) > 1) {
         $msg = 'Provided text %s contains more than one shortcode!';
         throw new \InvalidArgumentException(sprintf($msg, $text));
     }
     /** @var $parsed ShortcodeInterface */
     $parsed = array_shift($shortcodes);
     $name = $parsed->getName();
     $parameters = $parsed->getParameters();
     $content = $parsed->getContent();
     $bbCode = $parsed->getBbCode();
     return new Shortcode($name, $parameters, $content, $bbCode);
 }
コード例 #4
0
ファイル: ProcessorTest.php プロジェクト: rhukster/Shortcode
 public function testStripOuter()
 {
     $handlers = new HandlerContainer();
     $handlers->add('q', function (ShortcodeInterface $s) {
         return $s->getContent();
     });
     $handlers->add('p', function (ProcessedShortcode $s) use(&$handlers) {
         $parser = new RegexParser();
         $processor = new Processor($parser, $handlers);
         $shortcodes = $parser->parse($s->getTextContent());
         return array_reduce($shortcodes, function ($result, ParsedShortcodeInterface $s) use($processor) {
             return $result . $processor->process($s->getText());
         }, '');
     });
     $processor = new Processor(new RegexParser(), $handlers);
     $this->assertSame('x ab y', $processor->process('x [p] [q]a[/q] [q]b[/q] [/p] y'));
     $this->assertSame('x ab c y', $processor->process('x [p] [q]a[/q] [q]b [q]c[/q][/q] [/p] y'));
 }