public function testSetGetAncestors() { $item = new ContainerItem(); $this->assertSame(array(), $item->getAncestors()); $ancestors = array('t' => array('test')); $item->setAncestors($ancestors); $this->assertSame($ancestors, $item->getAncestors()); }
/** * @param array $letters * @param string $token * @param $namespace * @param bool $createIfNotExists * @return array|ContainerItem * @TODO Split this method */ protected function &getFinalDestination(array $letters, $token, $namespace, $createIfNotExists = false) { $destination =& $this->getCurrentNamespaceData($namespace); foreach ($letters as $letter) { if ($destination instanceof ContainerItem) { $destination =& $destination->getAncestors(); } $letter = mb_strtolower($letter); if (!isset($destination[$letter])) { $destination[$letter] = array(); } if (is_integer($destination[$letter])) { continue; } $destination =& $destination[$letter]; if ($createIfNotExists && is_array($destination) && key($destination) == $letter && is_integer($popularity = current($destination))) { $destination = new ContainerItem(); $destination->setValue($letter); $destination->setPopularity($popularity); $destination =& $destination->getAncestors(); } } if ($destination instanceof ContainerItem) { if (!$createIfNotExists) { $result = array($destination); return $result; } $destination =& $destination->getAncestors(); } if ($createIfNotExists && !isset($destination[$token])) { $destination[$token] = 0; } return $destination; }