本文整理汇总了PHP中PHPCR\Util\PathHelper::absolutizePath方法的典型用法代码示例。如果您正苦于以下问题:PHP PathHelper::absolutizePath方法的具体用法?PHP PathHelper::absolutizePath怎么用?PHP PathHelper::absolutizePath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPCR\Util\PathHelper
的用法示例。
在下文中一共展示了PathHelper::absolutizePath方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: mapPathToId
/**
* {@inheritdoc}
*/
public function mapPathToId($path, $rootPath = null)
{
// The path is being the id
$id = PathHelper::absolutizePath($path, '/');
if (is_string($rootPath) && 0 !== strpos($id, $rootPath)) {
throw new \OutOfBoundsException(sprintf('The path "%s" is out of the root path "%s" were the file system is located.', $path, $rootPath));
}
return $id;
}
示例2: removeItem
/**
* Remove a node or a property.
*
* If this is a node, sets all cached items below this node to deleted as
* well.
*
* If property is set, the path denotes the node containing the property,
* otherwise the node at path is removed.
*
* @param string $absPath The absolute path to the node to be removed,
* including the node name.
* @param PropertyInterface $property optional, property instance to delete from the
* given node path. If set, absPath is the path to the node containing
* this property.
*
* @throws RepositoryException If node cannot be found at given path
*
* @see Item::remove()
*/
public function removeItem($absPath, PropertyInterface $property = null)
{
if (!$this->transport instanceof WritingInterface) {
throw new UnsupportedRepositoryOperationException('Transport does not support writing');
}
// the object is always cached as invocation flow goes through Item::remove() without exception
if (!isset($this->objectsByPath['Node'][$absPath])) {
throw new RepositoryException("Internal error: Item not found in local cache at {$absPath}");
}
if ($property) {
$absPath = PathHelper::absolutizePath($property->getName(), $absPath);
$this->performPropertyRemove($absPath, $property);
} else {
$node = $this->objectsByPath['Node'][$absPath];
$this->performNodeRemove($absPath, $node);
$this->cascadeDelete($absPath);
}
}
示例3: absolutizePath
private function absolutizePath($path, $context = null)
{
if (null !== $context) {
$context = $this->defaultRootPath . DIRECTORY_SEPARATOR . $context;
}
if (isset($path[0]) && '/' === $path[0]) {
$path = $context ?: $this->rootPath;
}
return (string) PathHelper::absolutizePath($path, $context ?: $this->rootPath);
}
示例4: getNodes
/**
* {@inheritDoc}
*
* @api
*/
public function getNodes($nameFilter = null, $typeFilter = null)
{
$this->checkState();
$names = self::filterNames($nameFilter, $this->nodes);
$result = array();
if (!empty($names)) {
$paths = array();
foreach ($names as $name) {
$paths[] = PathHelper::absolutizePath($name, $this->path);
}
$nodes = $this->objectManager->getNodesByPath($paths, 'Node', $typeFilter);
// OPTIMIZE if we lazy-load in ObjectManager we should not do this loop
foreach ($nodes as $node) {
$result[$node->getName()] = $node;
}
}
return new ArrayIterator($result);
}
示例5: getProperty
/**
* {@inheritDoc}
*
* @throws InvalidItemStateException
*
* @api
*/
public function getProperty()
{
$this->checkState();
$values = $this->isMultiple() ? $this->value : array($this->value);
$results = array();
switch ($this->type) {
case PropertyType::PATH:
case PropertyType::STRING:
case PropertyType::NAME:
foreach ($values as $value) {
$results[] = $this->objectManager->getPropertyByPath(PathHelper::absolutizePath($value, $this->parentPath));
}
break;
default:
throw new ValueFormatException('Property is not a PATH (or convertible to PATH)');
}
return $this->isMultiple() ? $results : $results[0];
}
示例6: find
/**
* @param string $name Name of the menu to load
* @param array $options
* @param boolean $throw Whether to throw an exception if the menu is not
* found or no valid menu. Returns false if $throw is false and there
* is no menu at $name.
*
* @return object|boolean The menu root found with $name or false if $throw
* is false and the menu was not found.
*
* @throws \InvalidArgumentException Only if $throw is true throws this
* exception if the name is empty or no menu found.
*/
protected function find($name, array $options, $throw)
{
if (empty($name)) {
if ($throw) {
throw new \InvalidArgumentException('The menu name may not be empty');
}
return false;
}
$path = PathHelper::absolutizePath($name, $this->getMenuRoot());
$dm = $this->getObjectManager();
$session = $dm->getPhpcrSession();
if ($this->getPrefetch() > 0) {
try {
if ($session instanceof Session && 0 < $session->getSessionOption(Session::OPTION_FETCH_DEPTH) && 0 === strncmp($path, $this->getMenuRoot(), strlen($this->getMenuRoot()))) {
// we have jackalope with a fetch depth. prefetch all menu
// nodes of all menues.
$session->getNode($this->getMenuRoot(), $this->getPrefetch() + 1);
} else {
$session->getNode($path, $this->getPrefetch());
}
} catch (PathNotFoundException $e) {
if ($throw) {
throw new \InvalidArgumentException(sprintf('The menu root "%s" does not exist.', $this->getMenuRoot()));
}
return false;
}
}
$menu = $dm->find(null, $path);
if (null === $menu) {
if ($throw) {
throw new \InvalidArgumentException(sprintf('The menu "%s" is not defined.', $name));
}
return false;
}
if (!$menu instanceof NodeInterface) {
if ($throw) {
throw new \InvalidArgumentException("Menu at '{$name}' is not a valid menu node");
}
return false;
}
return $menu;
}
示例7: getSubject
/**
* Get subject
*
* Overridden to allow a broader set of valid characters in the ID, and
* if the ID is not a UUID, to call absolutizePath on the ID.
*
* @return mixed
*/
public function getSubject()
{
if ($this->subject === null && $this->request) {
$id = $this->request->get($this->getIdParameter());
if (!preg_match('#^[0-9A-Za-z/\\-_]+$#', $id)) {
$this->subject = false;
} else {
if (!UUIDHelper::isUUID($id)) {
$id = PathHelper::absolutizePath($id, '/');
}
$this->subject = $this->getModelManager()->find($this->getClass(), $id);
}
}
return $this->subject;
}
示例8: mapUrlSafePathToId
protected function mapUrlSafePathToId($path)
{
// The path is being the id
return PathHelper::absolutizePath($path, '/');
}
示例9: testAbsolutizePathInvalidNoThrow
/**
* @dataProvider dataproviderAbsolutizePathInvalid
*/
public function testAbsolutizePathInvalidNoThrow($inputPath, $context, $target)
{
$this->assertFalse(PathHelper::absolutizePath($inputPath, $context, $target, false));
}
示例10: collectPrefetchHierarchy
/**
* Gather the parent and all child mappings so they can be fetched in one
* go.
*
* @param ClassMetadata $class The metadata about the document to know what to do.
* @param NodeInterface $node The node to prefetch parent and childs for.
* @param string|null $locale The locale to also prefetch the translation
* child if applicable.
*
* @return array List of absolute paths to nodes that should be prefetched.
*/
public function collectPrefetchHierarchy(ClassMetadata $class, NodeInterface $node, $locale = null)
{
$prefetch = array();
if ($class->parentMapping && $node->getDepth() > 0) {
$prefetch[] = PathHelper::getParentPath($node->getPath());
}
foreach ($class->childMappings as $fieldName) {
$childName = $class->mappings[$fieldName]['nodeName'];
$prefetch[] = PathHelper::absolutizePath($childName, $node->getPath());
}
if ($locale && count($prefetch) && 'child' === $class->translator) {
$prefetch[] = $node->getPath() . '/phpcr_locale:' . $locale;
}
return $prefetch;
}
示例11: assertValidProperty
/**
* Validation if all the data is correct before writing it into the database.
*
* @param PropertyInterface $property
*
* @throws RepositoryException
* @throws ValueFormatException
*/
private function assertValidProperty(PropertyInterface $property)
{
$type = $property->getType();
switch ($type) {
case PropertyType::NAME:
$values = $property->getValue();
if (!$property->isMultiple()) {
$values = array($values);
}
foreach ($values as $value) {
$pos = strpos($value, ':');
if (false !== $pos) {
$prefix = substr($value, 0, $pos);
if (!isset($this->namespaces[$prefix])) {
throw new ValueFormatException(sprintf('Invalid value for NAME property type at "%s", the namespace prefix "%s" does not exist.");', $property->getPath(), $prefix));
}
}
}
break;
case PropertyType::PATH:
$values = $property->getValue();
if (!$property->isMultiple()) {
$values = array($values);
}
foreach ($values as $value) {
try {
// making the path absolute also validates the result to be a valid path
PathHelper::absolutizePath($value, $property->getPath());
} catch (RepositoryException $e) {
throw new ValueFormatException(sprintf('Value "%s" for PATH property at "%s" is invalid', $value, $property->getPath()), 0, $e);
}
}
break;
case PropertyType::URI:
$values = $property->getValue();
if (!$property->isMultiple()) {
$values = array($values);
}
foreach ($values as $value) {
if (!preg_match(self::VALIDATE_URI_RFC3986, $value)) {
throw new ValueFormatException(sprintf('Invalid value "%s" for URI property at "%s". Value has to comply with RFC 3986.', $value, $property->getPath()));
}
}
break;
case PropertyType::DECIMAL:
case PropertyType::STRING:
$values = (array) $property->getValue();
foreach ($values as $value) {
if (0 !== preg_match(self::VALIDATE_STRING, $value)) {
throw new ValueFormatException(sprintf('Invalid character detected in value %s for STRING property at "%s".', json_encode($value), $property->getPath()));
}
}
break;
}
}