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'));
 }
 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());
 }
Example #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]'));
 }
Example #4
0
 /**
  * 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;
 }
 /**
  * @param $defaultHandler
  * @return Processor
  */
 private function createShortcodeProcessor($defaultHandler)
 {
     $handlers = new HandlerContainer();
     $handlers->setDefault($defaultHandler);
     return new Processor(new RegularParser(), $handlers);
 }