Exemplo n.º 1
0
 /**
  * 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;
 }
 /**
  * Gathers data for the command to run.
  *
  * @param array           $arguments Set of cli arguments passed to the command
  * @param OutputInterface $output    Output channel to send messages to.
  * @param JsonDefinition  $jsonDef   Configuration of the service
  *
  * @return void
  * @throws \LogicException
  */
 private function generateResource(array $arguments, OutputInterface $output, JsonDefinition $jsonDef)
 {
     // controller?
     $routerBase = $jsonDef->getRouterBase();
     if ($routerBase === false || $this->isNotWhitelistedController($routerBase)) {
         $arguments['--no-controller'] = 'true';
     }
     $this->runner->executeCommand($arguments, $output, 'Create resource call failed, see above. Exiting.');
 }