本文整理汇总了PHP中PHPCR\Util\PathHelper::getParentPath方法的典型用法代码示例。如果您正苦于以下问题:PHP PathHelper::getParentPath方法的具体用法?PHP PathHelper::getParentPath怎么用?PHP PathHelper::getParentPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPCR\Util\PathHelper
的用法示例。
在下文中一共展示了PathHelper::getParentPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setDefaults
/**
* {@inheritdoc}
*/
public function setDefaults(MediaInterface $media, $parentPath = null)
{
$class = ClassUtils::getClass($media);
// check and add name if possible
if (!$media->getName()) {
if ($media->getId()) {
$media->setName(PathHelper::getNodeName($media->getId()));
} else {
throw new \RuntimeException(sprintf('Unable to set defaults, Media of type "%s" does not have a name or id.', $class));
}
}
$rootPath = is_null($parentPath) ? $this->rootPath : $parentPath;
$path = ($rootPath === '/' ? $rootPath : $rootPath . '/') . $media->getName();
/** @var DocumentManager $dm */
$dm = $this->getObjectManager();
// TODO use PHPCR autoname once this is done: http://www.doctrine-project.org/jira/browse/PHPCR-103
if ($dm->find($class, $path)) {
// path already exists
$media->setName($media->getName() . '_' . time() . '_' . rand());
}
if (!$media->getParent()) {
$parent = $dm->find(null, PathHelper::getParentPath($path));
$media->setParent($parent);
}
}
示例2: handlePersist
/**
* @param PersistEvent $event
*
* @throws DocumentManagerException
*/
public function handlePersist(PersistEvent $event)
{
$options = $event->getOptions();
$this->validateOptions($options);
$document = $event->getDocument();
$parentPath = null;
$nodeName = null;
if ($options['path']) {
$parentPath = PathHelper::getParentPath($options['path']);
$nodeName = PathHelper::getNodeName($options['path']);
}
if ($options['parent_path']) {
$parentPath = $options['parent_path'];
}
if ($parentPath) {
$event->setParentNode($this->resolveParent($parentPath, $options));
}
if ($options['node_name']) {
if (!$event->hasParentNode()) {
throw new DocumentManagerException(sprintf('The "node_name" option can only be used either with the "parent_path" option ' . 'or when a parent node has been established by a previous subscriber. ' . 'When persisting document: %s', DocumentHelper::getDebugTitle($document)));
}
$nodeName = $options['node_name'];
}
if (!$nodeName) {
return;
}
if ($event->hasNode()) {
$this->renameNode($event->getNode(), $nodeName);
return;
}
$node = $this->strategy->createNodeForDocument($document, $event->getParentNode(), $nodeName);
$event->setNode($node);
}
示例3: setRouteRoot
public function setRouteRoot($routeRoot)
{
// make limitation on base path work
parent::setRootPath($routeRoot);
// TODO: fix widget to show root node when root is selectable
// https://github.com/sonata-project/SonataDoctrinePhpcrAdminBundle/issues/148
$this->routeRoot = PathHelper::getParentPath($routeRoot);
}
示例4: createRoute
/**
* @param string $path
*
* @return Route
*/
protected function createRoute($path)
{
$parentPath = PathHelper::getParentPath($path);
$parent = $this->getDm()->find(null, $parentPath);
$name = PathHelper::getNodeName($path);
$route = new Route();
$route->setPosition($parent, $name);
$this->getDm()->persist($route);
$this->getDm()->flush();
return $route;
}
示例5: removeProperty
public function removeProperty($workspace, $path)
{
$propertyName = PathHelper::getNodeName($path);
$nodePath = PathHelper::getParentPath($path);
$node = $this->nodeReader->readNode($workspace, $nodePath);
$property = $node->getProperty($propertyName);
if (in_array($property['type'], array('Reference', 'WeakReference'))) {
$this->index->deindexReferrer($node->getPropertyValue(Storage::INTERNAL_UUID), $propertyName, $property['type'] === 'Reference' ? false : true);
}
$node->removeProperty($propertyName);
$this->nodeWriter->writeNode($workspace, $nodePath, $node);
}
示例6: findParentRoute
/**
* Finds the parent route document by concatenating the basepaths with the
* requested path.
*
* @return null|object
*/
protected function findParentRoute($requestedPath)
{
$manager = $this->getManagerForClass('Symfony\\Cmf\\Bundle\\RoutingBundle\\Doctrine\\Phpcr\\Route');
$parentPaths = array();
foreach ($this->routeBasePaths as $basepath) {
$parentPaths[] = PathHelper::getParentPath($basepath . $requestedPath);
}
$parentRoutes = $manager->findMany(null, $parentPaths);
if (0 === count($parentRoutes)) {
return;
}
return $parentRoutes->first();
}
示例7: create
/**
* {@inheritdoc}
*/
public function create(Request $request)
{
$routes = array();
$manager = $this->getManagerForClass('Symfony\\Cmf\\Bundle\\RoutingBundle\\Doctrine\\Phpcr\\Route');
$parentPath = PathHelper::getParentPath($this->routeBasePath . $request->getPathInfo());
$parentRoute = $manager->find(null, $parentPath);
if (!$parentRoute) {
return $routes;
}
if ($parentRoute instanceof Route) {
$routes[$parentRoute->getName()] = $parentRoute;
}
return $routes;
}
示例8: loadPhpcr
protected function loadPhpcr($config, XmlFileLoader $loader, ContainerBuilder $container)
{
$loader->load('services-phpcr.xml');
$loader->load('migrator-phpcr.xml');
$prefix = $this->getAlias() . '.persistence.phpcr';
$container->setParameter($prefix . '.basepath', $config['basepath']);
$container->setParameter($prefix . '.menu_basepath', PathHelper::getParentPath($config['basepath']));
if ($config['use_sonata_admin']) {
$this->loadSonataAdmin($config, $loader, $container);
} elseif (isset($config['sonata_admin'])) {
throw new InvalidConfigurationException('Do not define sonata_admin options when use_sonata_admin is set to false');
}
$container->setParameter($prefix . '.manager_name', $config['manager_name']);
$container->setParameter($prefix . '.document.class', $config['document_class']);
}
示例9: resolveSiblingName
private function resolveSiblingName($siblingId, NodeInterface $parentNode, NodeInterface $node)
{
if (null === $siblingId) {
return;
}
$siblingPath = $siblingId;
if (UUIDHelper::isUUID($siblingId)) {
$siblingPath = $this->nodeManager->find($siblingId)->getPath();
}
if ($siblingPath !== null && PathHelper::getParentPath($siblingPath) !== $parentNode->getPath()) {
throw new DocumentManagerException(sprintf('Cannot reorder documents which are not siblings. Trying to reorder "%s" to "%s"', $node->getPath(), $siblingPath));
}
if (null !== $siblingPath) {
return PathHelper::getNodeName($siblingPath);
}
return $node->getName();
}
示例10: init
/**
* {@inheritDoc}
*/
public function init(ManagerRegistry $registry)
{
/** @var $dm DocumentManager */
$dm = $registry->getManagerForClass('Symfony\\Cmf\\Bundle\\SimpleCmsBundle\\Doctrine\\Phpcr\\Page');
if ($dm->find(null, $this->basePath)) {
return;
}
$session = $dm->getPhpcrSession();
NodeHelper::createPath($session, PathHelper::getParentPath($this->basePath));
$page = new $this->documentClass();
$page->setId($this->basePath);
$page->setLabel('Home');
$page->setTitle('Homepage');
$page->setBody('Autocreated Homepage');
$dm->persist($page);
$dm->flush();
}
示例11: init
/**
* {@inheritdoc}
*/
public function init(ManagerRegistry $registry)
{
/** @var $dm DocumentManager */
$dm = $registry->getManagerForClass('AppBundle\\Document\\SeoPage');
if ($dm->find(null, $this->basePath)) {
return;
}
$session = $dm->getPhpcrSession();
NodeHelper::createPath($session, PathHelper::getParentPath($this->basePath));
/** @var \AppBundle\Document\SeoPage $page */
$page = new $this->documentClass();
$page->setId($this->basePath);
$page->setLabel('Home');
$page->setTitle('Homepage');
$page->setBody('Autocreated Homepage');
$page->setIsVisibleForSitemap(true);
$dm->persist($page);
$dm->flush();
}
示例12: execute
/**
* {@inheritDoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$helper = $this->getPhpcrHelper();
$session = $this->getPhpcrSession();
$path = $input->getArgument('path');
$type = $input->getOption('type');
$dump = $input->getOption('dump');
$setProp = $input->getOption('set-prop');
$removeProp = $input->getOption('remove-prop');
$addMixins = $input->getOption('add-mixin');
$removeMixins = $input->getOption('remove-mixin');
try {
$node = $session->getNode($path);
} catch (PathNotFoundException $e) {
$node = null;
}
if ($node) {
$nodeType = $node->getPrimaryNodeType()->getName();
$output->writeln(sprintf('<info>Node at path </info>%s <info>already exists and has primary type</info> %s.', $path, $nodeType));
if ($nodeType != $type) {
$output->writeln(sprintf('<error>You have specified node type "%s" but the existing node is of type "%s"</error>', $type, $nodeType));
return 1;
}
} else {
$nodeName = PathHelper::getNodeName($path);
$parentPath = PathHelper::getParentPath($path);
try {
$parentNode = $session->getNode($parentPath);
} catch (PathNotFoundException $e) {
$output->writeln(sprintf('<error>Parent path "%s" does not exist</error>', $parentPath));
return 2;
}
$output->writeln(sprintf('<info>Creating node: </info> %s [%s]', $path, $type));
$node = $parentNode->addNode($nodeName, $type);
}
$helper->processNode($output, $node, array('setProp' => $setProp, 'removeProp' => $removeProp, 'addMixins' => $addMixins, 'removeMixins' => $removeMixins, 'dump' => $dump));
$session->save();
return 0;
}
示例13: getBinaryStream
/**
* {@inheritDoc}
* @throws RepositoryException when no binary data found
*/
public function getBinaryStream($path)
{
$this->assertLoggedIn();
$nodePath = PathHelper::getParentPath($path);
$nodeId = $this->getSystemIdForNode($nodePath);
$propertyName = PathHelper::getNodeName($path);
$data = $this->getConnection()->fetchAll('SELECT data, idx FROM phpcr_binarydata WHERE node_id = ? AND property_name = ? AND workspace_name = ?', array($nodeId, $propertyName, $this->workspaceName));
if (count($data) === 0) {
throw new RepositoryException('No binary data found in stream');
}
$streams = array();
foreach ($data as $row) {
if (is_resource($row['data'])) {
$stream = $row['data'];
} else {
$stream = fopen('php://memory', 'rwb+');
fwrite($stream, $row['data']);
rewind($stream);
}
$streams[] = $stream;
}
if (count($data) === 1) {
// we don't know if this is a multivalue property or not.
// TODO we should have something more efficient to know this. a flag in the database?
// TODO use self::getProperty()->isMultiple() once implemented
$node = $this->getNode($nodePath);
if (!is_array($node->{':' . $propertyName})) {
return reset($streams);
}
}
return $streams;
}
示例14: restore
/**
* {@inheritDoc}
*
* @api
*/
public function restore($removeExisting, $version, $absPath = null)
{
if ($this->objectManager->hasPendingChanges()) {
throw new InvalidItemStateException('You may not call restore when there pending unsaved changes');
}
if (is_string($version)) {
if (!is_string($absPath)) {
throw new InvalidArgumentException('To restore version by version name you need to specify the path to the node you want to restore to this name');
}
$vh = $this->getVersionHistory($absPath);
$version = $vh->getVersion($version);
$versionPath = $version->getPath();
$nodePath = $absPath;
} elseif (is_array($version)) {
// @codeCoverageIgnoreStart
throw new NotImplementedException('TODO: implement restoring a list of versions');
// @codeCoverageIgnoreEnd
} elseif ($version instanceof VersionInterface && is_string($absPath)) {
// @codeCoverageIgnoreStart
throw new NotImplementedException('TODO: implement restoring a version to a specified path');
// @codeCoverageIgnoreEnd
} elseif ($version instanceof VersionInterface) {
$versionPath = $version->getPath();
$nodePath = $this->objectManager->getNodeByIdentifier($version->getContainingHistory()->getVersionableIdentifier())->getPath();
} else {
throw new InvalidArgumentException();
}
$this->objectManager->restore($removeExisting, $versionPath, $nodePath);
$version->setCachedPredecessorsDirty();
if ($history = $this->objectManager->getCachedNode(PathHelper::getParentPath($version->getPath()), 'Version\\VersionHistory')) {
$history->notifyHistoryChanged();
}
}
示例15: getBinaryStream
/**
* {@inheritDoc}
*/
public function getBinaryStream($path)
{
$this->assertLoggedIn();
$nodePath = PathHelper::getParentPath($path);
$nodeId = $this->pathExists($nodePath);
$propertyName = PathHelper::getNodeName($path);
$data = $this->conn->fetchAll(
'SELECT data, idx FROM phpcr_binarydata WHERE node_id = ? AND property_name = ? AND workspace_name = ?',
array($nodeId, $propertyName, $this->workspaceName)
);
$streams = array();
foreach ($data as $row) {
if (is_resource($row['data'])) {
$stream = $row['data'];
} else {
$stream = fopen('php://memory', 'rwb+');
fwrite($stream, $row['data']);
rewind($stream);
}
$streams[] = $stream;
}
// TODO even a multi value field could have only one value stored
// we need to also fetch if the property is multi valued instead of this count() check
if (count($data) > 1) {
return $streams;
}
return reset($streams);
}