Jackalope\Item::findItemDefinition PHP Method

findItemDefinition() protected method

Find the matching item definition for this item.
protected findItemDefinition ( callable $definitions ) : PHPCR\NodeType\ItemDefinitionInterface
$definitions callable Function that extracts the ItemDefinitions from a NodeType
return PHPCR\NodeType\ItemDefinitionInterface The definition for this item.
    protected function findItemDefinition($definitions)
    {
        $fallbackDefinition = null;
        $types = $this->getParent()->getMixinNodeTypes();
        array_push($types, $this->getParent()->getPrimaryNodeType());
        /** @var $nt NodeTypeInterface */
        foreach ($types as $nt) {
            /** @var $candidate ItemDefinitionInterface */
            foreach ($definitions($nt) as $candidate) {
                if ($candidate->getName() === $this->name) {
                    return $candidate;
                }
                if ('*' === $candidate->getName()) {
                    // if we have multiple wildcard definitions, they are hopefully equivalent
                    $fallbackDefinition = $candidate;
                    // do not abort loop, in case we hit an exactly matching definition
                }
            }
        }
        // sanity check. theoretically, the item should not be able to
        // exist if there is no definition for it
        if (!$fallbackDefinition) {
            throw new RepositoryException(sprintf('Found no definition for item %s, this should not be possible', $this->path));
        }
        return $fallbackDefinition;
    }