Jackalope\Property::getNode PHP Метод

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

{@inheritDoc}
public getNode ( )
    public function getNode()
    {
        $this->checkState();
        $values = $this->isMultiple() ? $this->value : array($this->value);
        $results = array();
        switch ($this->type) {
            case PropertyType::REFERENCE:
                $results = $this->getReferencedNodes($values, false);
                break;
            case PropertyType::WEAKREFERENCE:
                $results = $this->getReferencedNodes($values, true);
                break;
            case PropertyType::STRING:
                foreach ($values as $value) {
                    if (UUIDHelper::isUUID($value)) {
                        $results[] = $this->objectManager->getNodeByIdentifier($value);
                    } else {
                        $results[] = $this->objectManager->getNode($value, $this->parentPath);
                    }
                }
                break;
            case PropertyType::PATH:
            case PropertyType::NAME:
                foreach ($values as $value) {
                    // OPTIMIZE: use objectManager->getNodes instead of looping (but paths need to be absolute then)
                    $results[] = $this->objectManager->getNode($value, $this->parentPath);
                }
                break;
            default:
                throw new ValueFormatException('Property is not a REFERENCE, WEAKREFERENCE or PATH (or convertible to PATH)');
        }
        return $this->isMultiple() ? $results : reset($results);
    }

Usage Example

Пример #1
0
 /**
  * @dataProvider provideGetNode
  */
 public function testGetNode($values, $nodeUuids, $exceptionMessage = null)
 {
     if ($exceptionMessage) {
         $this->setExpectedException('PHPCR\\RepositoryException', $exceptionMessage);
     }
     $nodes = new \ArrayObject();
     foreach ($nodeUuids as $nodeUuid) {
         $nodes[$nodeUuid] = $this->getNodeMock();
         $nodes[$nodeUuid]->expects($this->any())->method('getIdentifier')->will($this->returnValue($nodeUuid));
     }
     $data = array('type' => PropertyType::REFERENCE, 'value' => $values);
     $factory = new Factory();
     $session = $this->getSessionMock();
     $objectManager = $this->getObjectManagerMock(array('getNodesByIdentifier' => $nodes));
     $property = new Property($factory, $data, '/path/to', $session, $objectManager);
     $property->getNode();
 }