示例#1
0
 /**
  * @param \SimpleXMLElement $node
  * @param $structureExtensionId extension of structures.xml
  * @return static
  */
 public static function fromSimpleXMLElement(\SimpleXMLElement $node, $structureExtensionId)
 {
     $url = isset($node['url']) ? (string) $node['url'] : '#';
     if ($url == '#' || empty($url)) {
         $extension = null;
         $controller = null;
         $action = null;
     } else {
         $parts = explode('/', trim($url, '/'));
         $parts = array_replace(array_fill(0, 3, null), $parts);
         list($extension, $controller, $action) = $parts;
     }
     $data = array('id' => (string) $node['id'], 'name' => (string) $node['name'], 'url' => $url, 'extension' => $extension, 'controller' => $controller, 'action' => $action, 'binding' => isset($node['binding']) ? (string) $node['binding'] : null, 'policy' => isset($node['policy']) ? (string) $node['policy'] : self::POLICY_MERGE, 'disabled' => isset($node['disabled']) ? true : false);
     $trees = array();
     foreach ($node->xpath("trees/tree") as $treeNode) {
         $trees[] = Tree::fromSimpleXMLElement($treeNode, $structureExtensionId);
     }
     $actions = array();
     foreach ($node->xpath("actions/action") as $actionNode) {
         $actions[] = Action::fromSimpleXMLElement($actionNode, $structureExtensionId);
     }
     $includeClassActions = isset($node->actions) && isset($node->actions['allowClassActions']) && $node->actions['allowClassActions'] == 'true';
     if ($includeClassActions) {
         foreach ($trees as $tree) {
             $rootNodeUri = $tree->get('rootNode');
             if (!empty($rootNodeUri)) {
                 $rootNode = new \core_kernel_classes_Class($rootNodeUri);
                 foreach (ClassActionRegistry::getRegistry()->getClassActions($rootNode) as $action) {
                     $actions[] = $action;
                 }
             }
         }
     }
     return new static($data, $trees, $actions);
 }
 public static function fromSimpleXMLElement(\SimpleXMLElement $node)
 {
     $url = isset($node['url']) ? (string) $node['url'] : '#';
     if ($url == '#' || empty($url)) {
         $extension = null;
         $controller = null;
         $action = null;
     } else {
         list($extension, $controller, $action) = explode('/', trim($url, '/'));
     }
     $data = array('id' => (string) $node['id'], 'name' => (string) $node['name'], 'url' => $url, 'extension' => $extension, 'controller' => $controller, 'action' => $action, 'binding' => isset($node['binding']) ? (string) $node['binding'] : null, 'policy' => isset($node['policy']) ? (string) $node['policy'] : self::POLICY_MERGE, 'disabled' => isset($node['disabled']) ? true : false);
     $trees = array();
     foreach ($node->xpath("trees/tree") as $treeNode) {
         $trees[] = Tree::fromSimpleXMLElement($treeNode);
     }
     $actions = array();
     foreach ($node->xpath("actions/action") as $actionNode) {
         $actions[] = Action::fromSimpleXMLElement($actionNode);
     }
     return new static($data, $trees, $actions);
 }
示例#3
0
 /**
  * Test the xml produce the same object than the one expected by the provider. 
  * 
  * @dataProvider actionsProvider
  * 
  * @param string $xml the action node 
  * @param Action $expected the expected object to be produced
  */
 public function testActions($xml, $extensionId, $expected)
 {
     $result = Action::fromSimpleXMLElement(new \SimpleXMLElement($xml), $extensionId);
     $this->assertTrue($result instanceof Action);
     $this->assertEquals($expected, $result);
 }