Beispiel #1
0
 protected function processAnonymousServices(SimpleXMLElement $xml, $file)
 {
     $definitions = array();
     $count = 0;
     // find anonymous service definitions
     $xml->registerXPathNamespace('container', 'http://www.symfony-project.org/schema/dic/services');
     // anonymous services as arguments
     $nodes = $xml->xpath('//container:argument[@type="service"][not(@id)]');
     foreach ($nodes as $node) {
         // give it a unique name
         $node['id'] = sprintf('%s_%d', md5($file), ++$count);
         $definitions[(string) $node['id']] = array($node->service, $file, false);
         $node->service['id'] = (string) $node['id'];
     }
     // anonymous services "in the wild"
     $nodes = $xml->xpath('//container:service[not(@id)]');
     foreach ($nodes as $node) {
         // give it a unique name
         $node['id'] = sprintf('%s_%d', md5($file), ++$count);
         $definitions[(string) $node['id']] = array($node, $file, true);
         $node->service['id'] = (string) $node['id'];
     }
     // resolve definitions
     krsort($definitions);
     foreach ($definitions as $id => $def) {
         $this->parseDefinition($id, $def[0], $def[1]);
         $oNode = dom_import_simplexml($def[0]);
         if (true === $def[2]) {
             $nNode = new \DOMElement('_services');
             $oNode->parentNode->replaceChild($nNode, $oNode);
             $nNode->setAttribute('id', $id);
         } else {
             $oNode->parentNode->removeChild($oNode);
         }
     }
     return $xml;
 }
 public static function registerNamespace(SimpleXMLElement $xml)
 {
     $xml->registerXPathNamespace("routes", "http://symfony.com/schema/routing");
 }
 /**
  * Handles form for RPC method call
  *
  * @param $key    Identifier of connection (connected device ID)
  * @param $configParams
  * @param $postVals
  *
  * @return int
  * @throws \ErrorException
  */
 public function handleRPCMethodForm($key, $configParams, $postVals)
 {
     $name = $postVals['rootElemName'];
     $namespace = $postVals['rootElemNamespace'];
     $res = 0;
     $xmlTree = new \SimpleXMLElement('<' . $name . '></' . $name . '>');
     $xmlTree->registerXPathNamespace('xc', 'urn:ietf:params:xml:ns:netconf:base:1.0');
     if ($namespace !== 'false' && $namespace !== '') {
         $xmlTree->registerXPathNamespace('rpcMod', $namespace);
         $xmlTree->addAttribute('xmlns', $namespace);
     }
     // we will go through all post values
     $skipArray = array('rootElemName', 'rootElemNamespace');
     foreach ($postVals as $labelKey => $labelVal) {
         if (in_array($labelKey, $skipArray)) {
             continue;
         }
         $label = $this->divideInputName($labelKey);
         // values[0] - label
         // values[1] - encoded xPath
         if (count($label) != 2) {
             $this->logger->err('RPCMethodForm must contain exactly 2 params, example container_-*-*?1!-*?2!-*?1!', array('values' => $label, 'postKey' => $labelKey));
             throw new \ErrorException("Could not proccess all form fields.");
         } else {
             $xpath = $this->decodeXPath($label[1]);
             $xpath = substr($xpath, 1);
             $node = $this->insertNewElemIntoXMLTree($xmlTree, $xpath, $label[0], $labelVal, '', $addCreateNS = false);
             array_push($skipArray, $labelKey);
         }
     }
     $createString = "\n" . str_replace('<?xml version="1.0"?' . '>', '', $xmlTree->asXML());
     try {
         $res = $this->dataModel->handle("userrpc", array('key' => $key, 'content' => $createString), false, $result);
         /* RPC can return output data in $result */
         if ($res == 0) {
             $this->container->get('request')->getSession()->getFlashBag()->add('success', "RPC method invocation was successful.");
         }
     } catch (\ErrorException $e) {
         $this->logger->warn('Could not invocate RPC method.', array('error' => $e->getMessage(), 'xml' => $createString));
         $this->container->get('request')->getSession()->getFlashBag()->add('error', "Could not invocate RPC method. Error: " . $e->getMessage());
     }
     return $res;
 }
Beispiel #4
0
 public static function registerNamespace(SimpleXMLElement $xml)
 {
     $xml->registerXPathNamespace('config', 'http://thelia.net/schema/dic/config');
 }