当前位置: 首页>>代码示例>>PHP>>正文


PHP PathHelper::getNodeName方法代码示例

本文整理汇总了PHP中PHPCR\Util\PathHelper::getNodeName方法的典型用法代码示例。如果您正苦于以下问题:PHP PathHelper::getNodeName方法的具体用法?PHP PathHelper::getNodeName怎么用?PHP PathHelper::getNodeName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PHPCR\Util\PathHelper的用法示例。


在下文中一共展示了PathHelper::getNodeName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: doSerializeResource

 private function doSerializeResource(Resource $resource, $depth = 0)
 {
     $data = array();
     $repositoryAlias = $this->registry->getRepositoryAlias($resource->getRepository());
     $data['repository_alias'] = $repositoryAlias;
     $data['repository_type'] = $this->registry->getRepositoryType($resource->getRepository());
     $data['payload_alias'] = $this->payloadAliasRegistry->getPayloadAlias($resource);
     $data['payload_type'] = null;
     if ($resource instanceof CmfResource) {
         $data['payload_type'] = $resource->getPayloadType();
     }
     $data['path'] = $resource->getPath();
     $data['label'] = $data['node_name'] = PathHelper::getNodeName($data['path']);
     $data['repository_path'] = $resource->getRepositoryPath();
     $enhancers = $this->enhancerRegistry->getEnhancers($repositoryAlias);
     $children = array();
     foreach ($resource->listChildren() as $name => $childResource) {
         $children[$name] = array();
         if ($depth < 2) {
             $children[$name] = $this->doSerializeResource($childResource, $depth + 1);
         }
     }
     $data['children'] = $children;
     if ($resource instanceof BodyResource) {
         $data['body'] = $resource->getBody();
     }
     foreach ($enhancers as $enhancer) {
         $data = $enhancer->enhance($data, $resource);
     }
     return $data;
 }
开发者ID:frogriotcom,项目名称:ResourceRestBundle,代码行数:31,代码来源:ResourceHandler.php

示例2: 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);
     }
 }
开发者ID:vespolina,项目名称:media,代码行数:28,代码来源:MediaManager.php

示例3: 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);
 }
开发者ID:hason,项目名称:sulu-document-manager,代码行数:38,代码来源:ExplicitSubscriber.php

示例4: preFlush

 public function preFlush(ManagerEventArgs $args)
 {
     if (empty($this->stack)) {
         return;
     }
     $metadataFactory = $args->getObjectManager()->getMetadataFactory();
     foreach ($this->stack as $data) {
         $children = $data['children'];
         $ctMetadata = $data['ct_metadata'];
         $childrenField = $data['field'];
         $index = 0;
         foreach ($children as $child) {
             $childMetadata = $metadataFactory->getMetadataFor(ClassUtils::getRealClass(get_class($child)));
             $expectedId = $this->encoder->encode($childrenField, $index++);
             $identifier = $childMetadata->getIdentifierValue($child);
             $idGenerator = $childMetadata->idGenerator;
             if ($idGenerator !== ClassMetadata::GENERATOR_TYPE_ASSIGNED) {
                 throw new \InvalidArgumentException(sprintf('Currently, all documents which belong to a mapped collection must use the ' . 'assigned ID generator strategy, "%s" is using "%s".', $childMetadata->getName(), $idGenerator));
             }
             if (!$identifier || PathHelper::getNodeName($identifier) !== $expectedId) {
                 throw new \InvalidArgumentException(sprintf('Child mapped to content type "%s" on field "%s" has an unexpected ID "%s". ' . 'It is currently necessary to envoke the CollectionIdentifierUpdater on all ' . 'documents (at least those which have collections) before they are persisted.', $ctMetadata->getType(), $childrenField, $identifier));
             }
         }
     }
 }
开发者ID:symfony-cmf,项目名称:content-type,代码行数:25,代码来源:CollectionSubscriber.php

示例5: 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;
 }
开发者ID:killerwolf,项目名称:RoutingBundle,代码行数:16,代码来源:BaseTestCase.php

示例6: 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);
 }
开发者ID:jackalope,项目名称:jackalope-fs,代码行数:12,代码来源:Storage.php

示例7: 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();
 }
开发者ID:hason,项目名称:sulu-document-manager,代码行数:17,代码来源:ReorderSubscriber.php

示例8: 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;
 }
开发者ID:frogriotcom,项目名称:phpcr-utils,代码行数:42,代码来源:NodeTouchCommand.php

示例9: rewriteItemPaths

 /**
  * Rewrites the path of a node for the movement operation, also updating
  * all cached children.
  *
  * This applies both to the cache and to the items themselves so
  * they return the correct value on getPath calls.
  *
  * @param string  $curPath Absolute path of the node to rewrite
  * @param string  $newPath The new absolute path
  */
 protected function rewriteItemPaths($curPath, $newPath)
 {
     // update internal references in parent
     $parentCurPath = PathHelper::getParentPath($curPath);
     $parentNewPath = PathHelper::getParentPath($newPath);
     if (isset($this->objectsByPath['Node'][$parentCurPath])) {
         /** @var $node Node */
         $node = $this->objectsByPath['Node'][$parentCurPath];
         if (!$node->hasNode(PathHelper::getNodeName($curPath))) {
             throw new PathNotFoundException("Source path can not be found: {$curPath}");
         }
         $node->unsetChildNode(PathHelper::getNodeName($curPath), true);
     }
     if (isset($this->objectsByPath['Node'][$parentNewPath])) {
         /** @var $node Node */
         $node = $this->objectsByPath['Node'][$parentNewPath];
         $node->addChildNode($this->getNodeByPath($curPath), true, PathHelper::getNodeName($newPath));
     }
     // propagate to current and children items of $curPath, updating internal path
     /** @var $node Node */
     foreach ($this->objectsByPath['Node'] as $path => $node) {
         // is it current or child?
         if (strpos($path, $curPath . '/') === 0 || $path == $curPath) {
             // curPath = /foo
             // newPath = /mo
             // path    = /foo/bar
             // newItemPath= /mo/bar
             $newItemPath = substr_replace($path, $newPath, 0, strlen($curPath));
             if (isset($this->objectsByPath['Node'][$path])) {
                 $node = $this->objectsByPath['Node'][$path];
                 $this->objectsByPath['Node'][$newItemPath] = $node;
                 unset($this->objectsByPath['Node'][$path]);
                 $node->setPath($newItemPath, true);
             }
             // update uuid cache
             $this->objectsByUuid[$node->getIdentifier()] = $node->getPath();
         }
     }
 }
开发者ID:nikophil,项目名称:cmf-tests,代码行数:49,代码来源:ObjectManager.php

示例10: testOrder

 /**
  * @dataProvider provideOrder
  */
 public function testOrder($nodes, $orderBy, $expectedOrder)
 {
     $rootNode = $this->session->getNode('/');
     foreach ($nodes as $nodeName => $nodeProperties) {
         $node = $rootNode->addNode($nodeName);
         foreach ($nodeProperties as $name => $value) {
             $node->setProperty($name, $value);
         }
     }
     $this->session->save();
     $qm = $this->session->getWorkspace()->getQueryManager();
     $query = $qm->createQuery('SELECT * FROM [nt:unstructured] WHERE value IS NOT NULL ORDER BY ' . $orderBy, \PHPCR\Query\QueryInterface::JCR_SQL2);
     $result = $query->execute();
     $rows = $result->getRows();
     $this->assertGreaterThan(0, count($rows));
     foreach ($rows as $index => $row) {
         $path = $row->getNode()->getPath();
         $name = PathHelper::getNodeName($path);
         $expectedName = $expectedOrder[$index];
         $this->assertEquals($expectedName, $name);
     }
 }
开发者ID:frogriotcom,项目名称:jackalope-doctrine-dbal,代码行数:25,代码来源:ClientTest.php

示例11: _basename

 /**
  * Return file name
  *
  * @param  string $path file path
  * @return string
  * @author Dmitry (dio) Levashov
  **/
 protected function _basename($path)
 {
     return PathHelper::getNodeName($path);
 }
开发者ID:Aerendir,项目名称:MediaBundle,代码行数:11,代码来源:PhpcrDriver.php

示例12: setPath

 /**
  * Set or update the path, depth, name and parent reference
  *
  * @param string  $path the new path this item lives at
  * @param boolean $move whether this item is being moved in session context
  *      and should store the current path until the next save operation.
  *
  * @private
  */
 public function setPath($path, $move = false)
 {
     if ($move && is_null($this->oldPath)) {
         try {
             $this->checkState();
         } catch (InvalidItemStateException $e) {
             // do not break if object manager tells the move to a child that was removed in backend
             return;
         }
         $this->oldPath = $this->path;
     }
     $this->path = $path;
     $this->depth = '/' === $path ? 0 : substr_count($path, '/');
     $this->name = PathHelper::getNodeName($path);
     $this->parentPath = 0 === $this->depth ? null : PathHelper::getParentPath($path);
 }
开发者ID:frogriotcom,项目名称:jackalope,代码行数:25,代码来源:Item.php

示例13: reorder

 /**
  * Reorder $moved (child of $parent) before or after $target
  *
  * @param string $parent the id of the parent
  * @param string $moved the id of the child being moved
  * @param string $target the id of the target node
  * @param bool $before insert before or after the target
  * 
  * @return void
  */
 public function reorder($parent, $moved, $target, $before)
 {
     $parentNode = $this->session->getNode($parent);
     $targetName = PathHelper::getNodeName($target);
     if (!$before) {
         $nodesIterator = $parentNode->getNodes();
         $nodesIterator->rewind();
         while ($nodesIterator->valid()) {
             if ($nodesIterator->key() == $targetName) {
                 break;
             }
             $nodesIterator->next();
         }
         $targetName = null;
         if ($nodesIterator->valid()) {
             $nodesIterator->next();
             if ($nodesIterator->valid()) {
                 $targetName = $nodesIterator->key();
             }
         }
     }
     $parentNode->orderBefore(PathHelper::getNodeName($moved), $targetName);
     $this->session->save();
 }
开发者ID:EmmanuelVella,项目名称:TreeBrowserBundle,代码行数:34,代码来源:PHPCRTree.php

示例14: copyOrMove

 /**
  * Copy or move a node by UUID to a detination parent.
  *
  * Note that the bulk of this method is about the resource locator and can
  * be removed if we integrate the RoutingAuto component.
  *
  * @param string $webspaceKey
  * @param string $locale
  * @param bool $move
  *
  * @return StructureInterface
  */
 private function copyOrMove($uuid, $destParentUuid, $userId, $webspaceKey, $locale, $move = true)
 {
     // find localizations
     $webspace = $this->webspaceManager->findWebspaceByKey($webspaceKey);
     $localizations = $webspace->getAllLocalizations();
     // load from phpcr
     $document = $this->documentManager->find($uuid, $locale);
     $parentDocument = $this->documentManager->find($destParentUuid, $locale);
     if ($move) {
         // move node
         $this->documentManager->move($document, $destParentUuid);
     } else {
         // copy node
         $copiedPath = $this->documentManager->copy($document, $destParentUuid);
         $document = $this->documentManager->find($copiedPath, $locale);
         $this->documentManager->refresh($parentDocument);
     }
     $originalLocale = $locale;
     // modifiy the resource locators -- note this can be removed once the routing auto
     // system is implemented.
     foreach ($localizations as $locale) {
         $locale = $locale->getLocalization();
         if (!$document instanceof ResourceSegmentBehavior) {
             break;
         }
         // prepare parent content node
         // finding the document will update the locale without reloading from PHPCR
         $this->documentManager->find($document->getUuid(), $locale);
         $this->documentManager->find($parentDocument->getUuid(), $locale);
         $parentResourceLocator = '/';
         if ($parentDocument instanceof ResourceSegmentBehavior) {
             $parentResourceLocator = $parentDocument->getResourceSegment();
         }
         // TODO: This could be optimized
         $localizationState = $this->inspector->getLocalizationState($document);
         if ($localizationState !== LocalizationState::LOCALIZED) {
             continue;
         }
         if ($document->getRedirectType() !== RedirectType::NONE) {
             continue;
         }
         $strategy = $this->getResourceLocator()->getStrategy();
         $nodeName = PathHelper::getNodeName($document->getResourceSegment());
         $newResourceLocator = $strategy->generate($nodeName, $parentDocument->getResourceSegment(), $webspaceKey, $locale);
         $document->setResourceSegment($newResourceLocator);
         $this->documentManager->persist($document, $locale, array('user' => $userId));
     }
     $this->documentManager->flush();
     //
     $this->documentManager->find($document->getUuid(), $originalLocale);
     return $this->documentToStructure($document);
 }
开发者ID:kriswillis,项目名称:sulu,代码行数:64,代码来源:ContentMapper.php

示例15: autoCompleteAction

 /**
  * @param Request $request
  *
  * @return Response
  *
  * @throws AccessDeniedException
  */
 public function autoCompleteAction(Request $request)
 {
     /** @var Admin $admin */
     $admin = $this->pool->getInstance($request->get('code'));
     $admin->setRequest($request);
     // check user permission
     if (false === $admin->isGranted('LIST')) {
         throw new AccessDeniedException();
     }
     // subject will be empty to avoid unnecessary database requests and keep auto-complete function fast
     $admin->setSubject($admin->getNewInstance());
     $fieldDescription = $this->retrieveFieldDescription($admin, $request->get('field'));
     $formAutocomplete = $admin->getForm()->get($fieldDescription->getName());
     if ($formAutocomplete->getConfig()->getAttribute('disabled')) {
         throw new AccessDeniedException('Autocomplete list can`t be retrieved because the form element is disabled or read_only.');
     }
     $class = $formAutocomplete->getConfig()->getOption('class');
     $property = $formAutocomplete->getConfig()->getAttribute('property');
     $minimumInputLength = $formAutocomplete->getConfig()->getAttribute('minimum_input_length');
     $itemsPerPage = $formAutocomplete->getConfig()->getAttribute('items_per_page');
     $reqParamPageNumber = $formAutocomplete->getConfig()->getAttribute('req_param_name_page_number');
     $toStringCallback = $formAutocomplete->getConfig()->getAttribute('to_string_callback');
     $searchText = $request->get('q');
     if (mb_strlen($searchText, 'UTF-8') < $minimumInputLength) {
         return new JsonResponse(array('status' => 'KO', 'message' => 'Too short search string.'), 403);
     }
     $page = $request->get($reqParamPageNumber);
     $offset = ($page - 1) * $itemsPerPage;
     /** @var ModelManager $modelManager */
     $modelManager = $formAutocomplete->getConfig()->getOption('model_manager');
     $dm = $modelManager->getDocumentManager();
     if ($class) {
         /** @var $qb \Doctrine\ODM\PHPCR\Query\Builder\QueryBuilder */
         $qb = $dm->getRepository($class)->createQueryBuilder('a');
         $qb->where()->fullTextSearch("a.{$property}", '*' . $searchText . '*');
         $qb->setFirstResult($offset);
         //fetch one more to determine if there are more pages
         $qb->setMaxResults($itemsPerPage + 1);
         $query = $qb->getQuery();
         $results = $query->execute();
     } else {
         /** @var $qb \PHPCR\Util\QOM\QueryBuilder */
         $qb = $dm->createPhpcrQueryBuilder();
         // TODO: node type should probably be configurable
         $qb->from($qb->getQOMFactory()->selector('a', 'nt:unstructured'));
         $qb->where($qb->getQOMFactory()->fullTextSearch('a', $property, '*' . $searchText . '*'));
         // handle attribute translation
         $qb->orWhere($qb->getQOMFactory()->fullTextSearch('a', $dm->getTranslationStrategy('attribute')->getTranslatedPropertyName($request->getLocale(), $property), '*' . $searchText . '*'));
         $qb->setFirstResult($offset);
         //fetch one more to determine if there are more pages
         $qb->setMaxResults($itemsPerPage + 1);
         $results = $dm->getDocumentsByPhpcrQuery($qb->getQuery());
     }
     //did we max out x+1
     $more = count($results) == $itemsPerPage + 1;
     $method = $request->get('_method_name');
     $items = array();
     foreach ($results as $path => $document) {
         // handle child translation
         if (strpos(PathHelper::getNodeName($path), Translation::LOCALE_NAMESPACE . ':') === 0) {
             $document = $dm->find(null, PathHelper::getParentPath($path));
         }
         if (!method_exists($document, $method)) {
             continue;
         }
         $label = $document->{$method}();
         if ($toStringCallback !== null) {
             if (!is_callable($toStringCallback)) {
                 throw new \RuntimeException('Option "to_string_callback" does not contain callable function.');
             }
             $label = call_user_func($toStringCallback, $document, $property);
         }
         $items[] = array('id' => $admin->id($document), 'label' => $label);
     }
     return new JsonResponse(array('status' => 'OK', 'more' => $more, 'items' => $items));
 }
开发者ID:jmontoyaa,项目名称:SonataDoctrinePhpcrAdminBundle,代码行数:83,代码来源:AutocompleteController.php


注:本文中的PHPCR\Util\PathHelper::getNodeName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。