/** * add service to services.xml * * @param \DOMDocument $dom services.xml dom * @param string $id id of new service * @param string $parent parent for service * @param string $scope scope of service * @param array $calls methodCalls to add * @param string $tag tag name or empty if no tag needed * @param array $arguments service arguments * @param string $factoryService factory service id * @param string $factoryMethod factory method name * * @return \DOMDocument */ protected function addService($dom, $id, $parent = null, $scope = null, array $calls = array(), $tag = null, array $arguments = array(), $factoryService = null, $factoryMethod = null) { $servicesNode = $this->addNodeIfMissing($dom, 'services'); $xpath = new \DomXpath($dom); // add controller to services $nodes = $xpath->query('//services/service[@id="' . $id . '"]'); if ($nodes->length < 1) { $attrNode = $dom->createElement('service'); $this->addAttributeToNode('id', $id, $dom, $attrNode); $this->addAttributeToNode('class', '%' . $id . '.class%', $dom, $attrNode); $this->addAttributeToNode('parent', $parent, $dom, $attrNode); $this->addAttributeToNode('scope', $scope, $dom, $attrNode); $this->addAttributeToNode('factory-service', $factoryService, $dom, $attrNode); $this->addAttributeToNode('factory-method', $factoryMethod, $dom, $attrNode); $this->addCallsToService($calls, $dom, $attrNode); if ($tag) { $tagNode = $dom->createElement('tag'); $this->addAttributeToNode('name', $tag, $dom, $tagNode); // get stuff from json definition if ($this->json instanceof JsonDefinition) { // id is also name of collection in mongodb $this->addAttributeToNode('collection', $this->json->getId(), $dom, $tagNode); // is this read only? if ($this->json->isReadOnlyService()) { $this->addAttributeToNode('read-only', 'true', $dom, $tagNode); } // router base defined? $routerBase = $this->json->getRouterBase(); if ($routerBase !== false) { $this->addAttributeToNode('router-base', $routerBase, $dom, $tagNode); } } $attrNode->appendChild($tagNode); } $this->addArgumentsToService($arguments, $dom, $attrNode); $servicesNode->appendChild($attrNode); } return $dom; }
/** * Generate the actual Bundle * * @param OutputInterface $output Instance to sent text to be displayed on stout. * @param JsonDefinition $jsonDef Configuration to be generated the entity from. * @param string $bundleName Name of the bundle the entity shall be generated for. * * @return void */ protected function generateMainResource(OutputInterface $output, JsonDefinition $jsonDef, $bundleName) { $fields = $jsonDef->getFields(); if (!empty($fields)) { $arguments = array('graviton:generate:resource', '--entity' => $bundleName . ':' . $jsonDef->getId(), '--json' => $this->serializer->serialize($jsonDef->getDef(), 'json'), '--format' => 'xml', '--fields' => $this->getFieldString($jsonDef), '--with-repository' => null); $this->generateResource($arguments, $output, $jsonDef); } }