public function givenIRegisteredAnEntityRepresenterFor($class) { if (array_key_exists($class, $this->representers)) { return; } $this->representers[$class] = new GenericEntityRepresenter($class); $this->registry->register($this->representers[$class]); }
/** * @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; }