コード例 #1
0
 public function testImmutableHandlerContainer()
 {
     $handlers = new HandlerContainer();
     $handlers->add('code', function () {
     });
     $handlers->addAlias('c', 'code');
     $handlers = new ImmutableHandlerContainer($handlers);
     $this->assertNull($handlers->get('missing'));
     $this->assertNotNull($handlers->get('code'));
     $this->assertNotNull($handlers->get('c'));
     $defaultHandlers = new HandlerContainer();
     $defaultHandlers->setDefault(function () {
     });
     $defaultHandlers = new ImmutableHandlerContainer($defaultHandlers);
     $this->assertNotNull($defaultHandlers->get('missing'));
 }
コード例 #2
0
 public function direct(Entry $entry, ActivityLog $activityLog = null)
 {
     /* @var $resolver \Dewdrop\ActivityLog\HandlerResolver */
     $resolver = Pimple::getResource('activity-log.handler-resolver');
     $handlers = new HandlerContainer();
     $handlers->setDefault(function (ShortcodeInterface $s) use($entry, $resolver) {
         try {
             $handler = $resolver->resolve($s->getName());
             $entity = $entry->getEntity($handler, $s->getParameter('id'));
             return trim($this->view->activityLogEntity($entity));
         } catch (ActivityLog\Exception\HandlerNotFound $e) {
             return '<strong>Unknown Type</strong>';
         } catch (ActivityLog\Exception\EntityNotFound $e) {
             return '<strong>Entity Not in DB</strong>';
         }
     });
     $processor = new Processor(new RegularParser(), $handlers);
     return $processor->process($entry->getMessage());
 }
コード例 #3
0
 public function testDefaultHandler()
 {
     $handlers = new HandlerContainer();
     $handlers->setDefault(function (ShortcodeInterface $s) {
         return $s->getName();
     });
     $processor = new Processor(new RegexParser(), $handlers);
     $this->assertSame('namerandom', $processor->process('[name][other][/name][random]'));
 }
コード例 #4
0
ファイル: Shortcode.php プロジェクト: adrianthedev/shortcode
 /**
  * Return true is the given content contain the given name shortcode.
  *
  * @param string $content
  * @param string $name
  *
  * @return bool
  */
 public function contains($content, $name)
 {
     $hasShortcode = false;
     $handlers = new HandlerContainer();
     $handlers->setDefault(function (ShortcodeInterface $s) use($name, &$hasShortcode) {
         if ($s->getName() === $name) {
             $hasShortcode = true;
         }
     });
     $processor = new Processor(new RegexParser(), $handlers);
     $processor->process($content);
     return $hasShortcode;
 }
コード例 #5
0
 /**
  * @param $defaultHandler
  * @return Processor
  */
 private function createShortcodeProcessor($defaultHandler)
 {
     $handlers = new HandlerContainer();
     $handlers->setDefault($defaultHandler);
     return new Processor(new RegularParser(), $handlers);
 }