コード例 #1
0
ファイル: ServerModule.php プロジェクト: kohkimakimoto/altax
 /**
  * Set node
  */
 public function node()
 {
     $args = func_get_args();
     if (count($args) < 1) {
         throw new \RuntimeException("Missing argument. Must 1 arguments at minimum.");
     }
     $node = new Node();
     if (count($args) === 1) {
         // When it's passed 1 argument, register node with name only.
         $node->setName($args[0]);
     } elseif (count($args) === 2) {
         // When it's passed 2 arguments, register node with roles and some options.
         $node->setName($args[0]);
         if (is_string($args[1]) || Arr::isVector($args[1])) {
             $node->setReferenceRoles($args[1]);
         } else {
             if (isset($args[1]['roles'])) {
                 $node->setReferenceRoles($args[1]['roles']);
                 unset($args[1]['roles']);
             }
             $node->setOptions($args[1]);
         }
     } else {
         // When it's passed more than 3 arguments, register node with roles and some options.
         $node->setName($args[0]);
         $node->setOptions($args[1]);
         $node->setReferenceRoles($args[2]);
     }
     $this->container->set("nodes/" . $node->getName(), $node);
     $roles = $node->getReferenceRoles();
     if ($roles) {
         if (is_string($roles)) {
             $this->role($roles, $node->getName());
         } else {
             if (is_array($roles)) {
                 foreach ($roles as $role) {
                     $this->role($role, $node->getName());
                 }
             }
         }
     }
     return $node;
 }
コード例 #2
0
ファイル: NodeTest.php プロジェクト: kohkimakimoto/altax
 public function testReplaceTilda()
 {
     $node = new Node();
     Env::set("homedir", "/home/your");
     $node->setKey("~/path/to/private_key");
     $this->assertEquals("~/path/to/private_key", $node->getKey());
     $this->assertEquals("/home/your/path/to/private_key", $node->getKeyOrDefault());
     $node->setKey("~user/path/to/private_key");
     $this->assertEquals("~user/path/to/private_key", $node->getKey());
     $this->assertEquals("~user/path/to/private_key", $node->getKeyOrDefault());
     $node->setKey("~");
     $this->assertEquals("~", $node->getKey());
     $this->assertEquals("/home/your", $node->getKeyOrDefault());
     Env::set("homedir", "/home/your\\0");
     $node->setKey("~/path/to/private_key");
     $this->assertEquals("~/path/to/private_key", $node->getKey());
     $this->assertEquals("/home/your\\0/path/to/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());
 }
コード例 #3
0
ファイル: Executor.php プロジェクト: kohkimakimoto/altax
 /**
  * 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;
 }
コード例 #4
0
ファイル: ProcessTest.php プロジェクト: kohkimakimoto/altax
 public function testPutString2()
 {
     $srcPath = "/NotExistsFile/gettest.txt";
     $this->runtimeTask->getOutput()->setVerbosity(3);
     $node = new Node();
     $node->setName("127.0.0.1");
     $process = new Process($this->runtimeTask, $node);
     try {
         $process->putString($srcPath, "putstring contents");
         $this->assertEquals(false, true);
     } catch (\RuntimeException $e) {
         $this->assertEquals(true, true);
     }
 }