getName() публичный Метод

public getName ( )
Пример #1
0
 public function testAccessors()
 {
     $node = new Node();
     $node->setName("test_node_name");
     $this->assertEquals("test_node_name", $node->getName());
     $this->assertEquals("test_node_name", $node->getHostOrDefault());
     $node->setHost("test.node.exsample.com");
     $this->assertEquals("test.node.exsample.com", $node->getHost());
     $this->assertEquals("test.node.exsample.com", $node->getHostOrDefault());
     $this->assertEquals(22, $node->getPortOrDefault());
     $node->setPort(2022);
     $this->assertEquals(2022, $node->getPort());
     $this->assertEquals(2022, $node->getPortOrDefault());
     $node->setDefaultKey("/path/to/default/private_key");
     $this->assertEquals("/path/to/default/private_key", $node->getDefaultKey());
     $this->assertEquals("/path/to/default/private_key", $node->getKeyOrDefault());
     $node->setKey("/path/to/private_key");
     $this->assertEquals("/path/to/private_key", $node->getKey());
     $this->assertEquals("/path/to/private_key", $node->getKeyOrDefault());
     $node->setDefaultUsername("default_ssh_connection_user");
     $this->assertEquals("default_ssh_connection_user", $node->getDefaultUsername());
     $this->assertEquals("default_ssh_connection_user", $node->getUsernameOrDefault());
     $node->setUsername("ssh_connection_user");
     $this->assertEquals("ssh_connection_user", $node->getUsername());
     $this->assertEquals("ssh_connection_user", $node->getUsernameOrDefault());
     try {
         $node->setOptions("aaa");
         $this->assertEquals(fales, true);
     } catch (\RuntimeException $e) {
         $this->assertEquals(true, true);
     }
 }
Пример #2
0
 /**
  * Load nods from variable length argument lists same 'on' and 'for' method.
  * @return array Array of Altax\Module\Server\Resource\Node
  */
 protected function loadNodes(array $args)
 {
     $candidateNodeNames = array();
     $concreteNodes = array();
     if (Arr::isVector($args)) {
         foreach ($args as $arg) {
             if (is_string($arg)) {
                 $candidateNodeNames[] = array("type" => null, "name" => $arg);
             }
         }
     } else {
         foreach ($args as $key => $value) {
             if ($key == "nodes" || $key == "node") {
                 $nodes = array();
                 if (is_string($value)) {
                     $nodes[] = $value;
                 } elseif (is_array($value)) {
                     $nodes = $value;
                 }
                 foreach ($nodes as $node) {
                     $candidateNodeNames[] = array("type" => "node", "name" => $node);
                 }
             }
             if ($key == "roles" || $key == "role") {
                 $roles = array();
                 if (is_string($value)) {
                     $roles[] = $value;
                 } elseif (is_array($value)) {
                     $roles = $value;
                 }
                 foreach ($roles as $role) {
                     $candidateNodeNames[] = array("type" => "role", "name" => $role);
                 }
             }
         }
     }
     foreach ($candidateNodeNames as $candidateNodeName) {
         $node = null;
         $role = null;
         if ($candidateNodeName["type"] === null || $candidateNodeName["type"] == "node") {
             $node = Server::getNode($candidateNodeName["name"]);
         }
         if ($candidateNodeName["type"] === null || $candidateNodeName["type"] == "role") {
             $role = Server::getRole($candidateNodeName["name"]);
         }
         if ($node && $role) {
             throw new \RuntimeException("The key '" . $candidateNodeName["name"] . "' was found in both nodes and roles. So It couldn't identify to unique node.");
         }
         if (!$node && !$role && ($candidateNodeName["type"] === null || $candidateNodeName["type"] == "node")) {
             // Passed unregistered node name. Create node instance.
             $node = new Node();
             $node->setName($candidateNodeName["name"]);
         }
         if ($node) {
             $concreteNodes[$node->getName()] = $node;
         }
         if ($role) {
             foreach ($role as $nodeName) {
                 $concreteNodes[$nodeName] = Server::getNode($nodeName);
             }
         }
     }
     return $concreteNodes;
 }