Exemplo n.º 1
0
 /**
  * This method checks module name, loads mapping info from ModuleController
  * entity, and calls specified controller from custom ModuleBundle
  *
  * @param GetResponseEvent $event
  */
 public function onKernelController(GetResponseEvent $event)
 {
     if ($this->em) {
         $attributes = $event->getRequest()->attributes;
         if (in_array($attributes->get("_route"), array("module", "subsection"))) {
             // get available namespaces for this connection
             $namespace = $this->dataModel->getNamespaceForModule($attributes->get('key'), $attributes->get('module'));
             if ($namespace !== false) {
                 $record = $this->dataModel->getModuleControllers($attributes->get('module'), $namespace);
                 if ($record) {
                     // get all saved controllers from DB
                     $controllers = $record->getControllerActions();
                     /**
                      * @var ConnectionSession $conn
                      */
                     $conn = $this->dataModel->getConnectionSessionForKey($attributes->get('key'));
                     $activeController = $conn->getActiveControllersForNS($namespace);
                     // if we don't have any saved (preferred) controller, we will use first from DB
                     if (!$activeController) {
                         $activeController = $controllers[0];
                     }
                     $event->getRequest()->attributes->set("_controller", $activeController);
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
    public function testCompleteRequestTree2()
    {
        // mocking class method loadModel to return model with choices
        $stub = $this->getMockWithModel('wrapped_ofconfig.wyin');
        // add resources port into switch. It is important do add all necessary key elements of all parents (here ID in switch)
        $emptyRootModule = '<?xml version="1.0"?><capable-switch xmlns="urn:onf:config:yang">
    <id>openvswitch</id>
    <resources/>
    <logical-switches>
      <switch>
        <id>ofc-bridge</id>
        <datapath-id>00:01:02:03:04:05:06:07</datapath-id>
        <lost-connection-behavior>failSecureMode</lost-connection-behavior>
        <resources/>
      </switch>
    </logical-switches>
  </capable-switch>';
        $createString = '<resources><port xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0" xc:operation="create">ofc-server</port></resources>';
        $expectedString = '<?xml version="1.0"?>
<capable-switch xmlns="urn:onf:config:yang" xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0">
<logical-switches>
<switch>
<id>ofc-bridge</id><resources><port xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0" xc:operation="create">ofc-server</port></resources></switch>
</logical-switches>
</capable-switch>
';
        $emptyRootModule = $stub->mergeXMLWithModel($emptyRootModule);
        $node = simplexml_load_string($emptyRootModule);
        $node->registerXPathNamespace("xmlns", "urn:onf:config:yang");
        $parent = $node->xpath('/xmlns:*/*[3]/*[1]/*[4]');
        $res = $stub->completeRequestTree($parent[0], $createString, $this->dataModel->getPathToModels() . 'wrapped_ofconfig.wyin');
        $this->assertEquals($expectedString, $res->asXML(), 'complete request2 1 failed');
        $parent = $node->xpath('/xmlns:*/*[3]/*[1]/*[4]');
        $res = $stub->completeRequestTree($parent[0], $createString, $this->dataModel->getPathToModels() . 'wrapped_ofconfig.wyin');
        $this->assertEquals($expectedString, $res->asXML(), 'complete request2 1 failed');
    }