作者:phpc
项目:phpcr-shel
public function execute(InputInterface $input, OutputInterface $output)
{
$session = $this->get('phpcr.session');
$file = $input->getArgument('file');
$pretty = $input->getOption('pretty');
$exportDocument = $input->getOption('document');
$dialog = $this->get('helper.question');
if (file_exists($file)) {
$confirmed = true;
if (false === $input->getOption('no-interaction')) {
$confirmed = $dialog->ask($input, $output, new ConfirmationQuestion('File already exists, overwrite?'));
}
if (false === $confirmed) {
return;
}
}
$stream = fopen($file, 'w');
$absPath = $input->getArgument('absPath');
PathHelper::assertValidAbsolutePath($absPath);
if (true === $exportDocument) {
$session->exportDocumentView($absPath, $stream, $input->getOption('skip-binary'), $input->getOption('no-recurse'));
} else {
$session->exportSystemView($absPath, $stream, $input->getOption('skip-binary'), $input->getOption('no-recurse'));
}
fclose($stream);
if ($pretty) {
$xml = new \DOMDocument(1.0);
$xml->load($file);
$xml->preserveWhitespace = true;
$xml->formatOutput = true;
$xml->save($file);
}
}
作者:symfony-cm
项目:content-typ
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));
}
}
}
}
作者:frogriotco
项目:ResourceRestBundl
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;
}
作者:haso
项目:sulu-document-manage
/**
* @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);
}
作者:symfony-cm
项目:routing-bundl
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);
}
作者:vespolin
项目:medi
/**
* {@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;
}
作者:killerwol
项目:RoutingBundl
/**
* @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;
}
作者:jackalop
项目:jackalope-f
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);
}
作者:symfony-cm
项目:seo-bundl
/**
* 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();
}
作者:damonsso
项目:SeoBundl
/**
* {@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;
}
作者:jackalop
项目:jackalope-f
public function getNodePath($workspace, $path, $withFilename = true)
{
$path = PathHelper::normalizePath($path);
if (substr($path, 0, 1) == '/') {
$path = substr($path, 1);
}
if ($path) {
$path .= '/';
}
$nodeRecordPath = Storage::WORKSPACE_PATH . '/' . $workspace . '/' . $path . 'node.yml';
if ($withFilename === false) {
$nodeRecordPath = dirname($nodeRecordPath);
}
return $nodeRecordPath;
}
作者:creatiomb
项目:SimpleCmsBundl
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']);
}
作者:haso
项目:phpcr-shel
public function execute(InputInterface $input, OutputInterface $output)
{
$session = $this->get('phpcr.session');
$file = $input->getArgument('file');
$parentAbsPath = $input->getArgument('parentAbsPath');
$uuidBehavior = $input->getOption('uuid-behavior');
if (!in_array($uuidBehavior, $this->uuidBehaviors)) {
throw new \Exception(sprintf("The specified uuid behavior \"%s\" is invalid, you should use one of:\n%s", $uuidBehavior, ' - ' . implode("\n - ", $this->uuidBehaviors)));
}
if (!file_exists($file)) {
throw new \InvalidArgumentException(sprintf('The file "%s" does not exist', $file));
}
PathHelper::assertValidAbsolutePath($parentAbsPath);
$uuidBehavior = constant('\\PHPCR\\ImportUUIDBehaviorInterface::IMPORT_UUID_' . strtoupper(str_replace('-', '_', $uuidBehavior)));
$session->importXml($parentAbsPath, $file, $uuidBehavior);
}
作者:haso
项目:sulu-document-manage
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();
}
作者:2lene
项目:SimpleCmsBundl
/**
* {@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();
}
作者:sul
项目:sul
/**
* {@inheritdoc}
*/
public function getRouteCollectionForRequest(Request $request)
{
$collection = new RouteCollection();
$path = $request->getPathInfo();
$prefix = $this->requestAnalyzer->getResourceLocatorPrefix();
if (!empty($prefix) && strpos($path, $prefix) === 0) {
$path = PathHelper::relativizePath($path, $prefix);
}
$route = $this->findRouteByPath($path, $request->getLocale());
if ($route && array_key_exists($route->getId(), $this->symfonyRouteCache)) {
$collection->add(self::ROUTE_PREFIX . $route->getId(), $this->symfonyRouteCache[$route->getId()]);
return $collection;
}
if (!$route || !$this->routeDefaultsProvider->supports($route->getEntityClass()) || !$this->routeDefaultsProvider->isPublished($route->getEntityClass(), $route->getEntityId(), $route->getLocale())) {
return $collection;
}
$collection->add(self::ROUTE_PREFIX . $route->getId(), $this->createRoute($route, $request));
return $collection;
}
作者:symfony-cm
项目:symfony-cmf-websit
/**
* {@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();
}
作者:frogriotco
项目:phpcr-util
/**
* {@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;
}
作者:EmmanuelVell
项目:TreeBrowserBundl
/**
* 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();
}
作者:Silweret
项目:sul
/**
* Generates a content-tree with paths of given content array.
*
* @param Content[] $contents
*
* @return Content[]
*/
private function generateTreeByPath(array $contents)
{
$childrenByPath = [];
foreach ($contents as $content) {
$path = PathHelper::getParentPath($content->getPath());
if (!isset($childrenByPath[$path])) {
$childrenByPath[$path] = [];
}
$order = $content['order'];
while (isset($childrenByPath[$path][$order])) {
++$order;
}
$childrenByPath[$path][$order] = $content;
}
foreach ($contents as $content) {
if (!isset($childrenByPath[$content->getPath()])) {
continue;
}
ksort($childrenByPath[$content->getPath()]);
$content->setChildren(array_values($childrenByPath[$content->getPath()]));
}
ksort($childrenByPath['/']);
return array_values($childrenByPath['/']);
}