Ejemplo n.º 1
0
 public function givenIRegisteredAnEntityRepresenterFor($class)
 {
     if (array_key_exists($class, $this->representers)) {
         return;
     }
     $this->representers[$class] = new GenericEntityRepresenter($class);
     $this->registry->register($this->representers[$class]);
 }
Ejemplo n.º 2
0
 protected function getOptions()
 {
     $representer = $this->registry->getEntityRepresenter($this->entityClass);
     $options = [];
     foreach ($this->getEntityList() as $entity) {
         $options[(string) $representer->getProperties($entity)[$representer->keyProperty()]->get($entity)] = $representer->toString($entity);
     }
     return $options;
 }
Ejemplo n.º 3
0
 function testRegisterMethodAction()
 {
     $someAction = $this->registrar->addMethodAction('SomeActionHandler', 'someAction');
     $otherAction = $this->registrar->addMethodAction('SomeActionHandler', 'otherAction');
     $this->assertSame($someAction, $this->registry->getActionRepresenter($someAction->getClass()));
     $actions = $this->registrar->getRepresenter()->getActions(new \DateTime());
     $this->assertCount(2, $actions);
     $this->assertEquals($someAction->getClass(), $actions[0]->getClass());
     $this->assertEquals($otherAction->getClass(), $actions[1]->getClass());
 }
Ejemplo n.º 4
0
 /**
  * @param ActionRepresenter $representer
  * @param null|callable $predicate
  * @param null|callable $arguments
  * @return ActionRepresenter
  */
 public function add(ActionRepresenter $representer, $predicate = null, $arguments = null)
 {
     $this->registry->register($representer);
     $predicate = $predicate ?: function () {
         return true;
     };
     $arguments = $arguments ?: function ($entity) {
         $representer = $this->registry->getEntityRepresenter($entity);
         $key = $representer->keyProperty();
         $properties = $representer->getProperties($entity);
         if (!$properties->has($key)) {
             return [];
         }
         return [$key => (string) $properties[$key]->get($entity)];
     };
     $this->actions[$representer->getClass()] = [$predicate, $arguments];
     return $representer;
 }
Ejemplo n.º 5
0
 protected function urlOfAction(ActionLink $followUpAction)
 {
     $representer = $this->registry->getActionRepresenter($followUpAction->getClass());
     return $representer->getResourceUrl()->withParameter('action', $followUpAction->getClass())->withParameter('args', $followUpAction->getArguments());
 }