public function testIsVector() { $this->assertEquals(true, Arr::isVector(array("1", "3", "aaaa"))); $this->assertEquals(true, Arr::isVector(array(1, 2, 3))); $this->assertEquals(true, Arr::isVector(array(1, 2, "aaaa"))); $this->assertEquals(true, Arr::isVector(array())); $this->assertEquals(false, Arr::isVector(array("a" => "bb", "c" => "dd"))); }
/** * 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; }
public function setReferenceRoles($roles) { if (is_string($roles)) { $roles = array($roles => $roles); } elseif (Arr::isVector($roles)) { $vrs = $roles; $roles = array(); foreach ($vrs as $r) { $roles[$r] = $r; } } $this->referenceRoles = $roles; }
public function after() { $args = func_get_args(); foreach ($args as $arg) { if (is_string($arg)) { $this->afterTaskNames[] = $arg; } elseif (\Altax\Util\Arr::isVector($arg)) { $this->afterTaskNames = array_merge($this->afterTaskNames, $arg); } } return $this; }
/** * 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; }