/** * @param ResourceInterface $resource * @param string|null $name * * @return ArrayNodeDefinition */ private function createResourceNode(ResourceInterface $resource, $name = null) { $resourceNode = $this->createNode($name ?: $resource->getName())->addDefaultsIfNotSet(); $childrenNode = $resourceNode->children()->append($this->createDriverNode($resource))->append($this->createClassNode('model', $resource->getModel(), $resource->getInterfaces()))->append($this->createClassNode('controller', $resource->getController(), [ControllerInterface::class]))->append($this->createClassNode('factory', $resource->getFactory(), [FactoryInterface::class]))->append($this->createClassNode('repository', $resource->getRepository(), [RepositoryInterface::class]))->append($this->createClassNode('domain_manager', $resource->getDomainManager(), [DomainManagerInterface::class]))->append($this->createClassNode('form', $resource->getForm(), [FormTypeInterface::class]))->append($this->createClassNode('choice_form', $resource->getChoiceForm(), [FormTypeInterface::class]))->append($this->createNode('id_property_path', 'scalar', $resource->getIdPropertyPath()))->append($this->createNode('label_property_path', 'scalar', $resource->getLabelPropertyPath())); if ($resource->getTranslation() !== null) { $childrenNode->append($this->createResourceNode($resource->getTranslation(), 'translation')); } return $resourceNode; }
/** * @param DomainEvent $event * @param string $action * @param string $state * @param \Exception|null $exception */ private function dispatchEvent(DomainEvent $event, $action, $state, \Exception $exception = null) { if ($state === self::STATE_ERROR) { $event->setStopped(true); } $this->eventDispatcher->dispatch('lug.' . $this->resource->getName() . '.' . $state . '_' . $action, $event); if ($event->isStopped()) { throw new DomainException($event->getStatusCode(), $event->getMessage(), 0, $exception); } }
/** * @param ResourceInterface $resource * * @return Definition */ private function createControllerDefinition(ResourceInterface $resource) { $definition = new Definition($resource->getController(), [new Reference('lug.resource.' . $resource->getName())]); $definition->addMethodCall('setContainer', [new Reference('service_container')]); $definition->addTag('lug.controller', ['resource' => $resource->getName()]); return $definition; }
/** * @return string */ private function getAlias() { return $this->resource->getName(); }
/** * @return DomainManagerInterface */ protected function getDomainManager() { return $this->get('lug.resource.registry.domain_manager')[$this->resource->getName()]; }
/** * @param ResourceInterface $resource * * @return Definition */ private function createDomainManagerDefinition(ResourceInterface $resource) { $definition = new Definition($resource->getDomainManager(), [new Reference('lug.resource.' . $resource->getName()), new Reference('event_dispatcher'), new Reference('lug.manager.' . $resource->getName()), new Reference('lug.repository.' . $resource->getName())]); $definition->addTag('lug.domain_manager', ['resource' => $resource->getName()]); return $definition; }