本文整理汇总了PHP中PHPCR\NodeInterface类的典型用法代码示例。如果您正苦于以下问题:PHP NodeInterface类的具体用法?PHP NodeInterface怎么用?PHP NodeInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NodeInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getUrl
/**
* Gets a relative filesystem path based on the repository path, AND
* creates the file on the filesystem if it's in the repository
* and not yet on the filesystem.
* The repository path points to a nt-resource node, whose title
* should be the filename, and which has a child+property
* jcr:content/jcr:data where the file data is stored.
*
* @param string $path path to the nt-resource node.
* @return string with a path to the file, relative to the web directory.
*/
public function getUrl(NodeInterface $node)
{
$hasData = false;
if ($node->hasNode('jcr:content')) {
$contentNode = $node->getNode('jcr:content');
if ($contentNode->hasProperty('jcr:data')) {
$hasData = true;
}
}
if (!$hasData) {
//TODO: notfound exception is not appropriate ... how to best do this?
//throw new NotFoundHttpException('no picture found at ' . $node->getPath());
return 'notfound';
}
$path = $node->getPath();
$relativePath = $this->pathMapper->getUrl($path);
$fullPath = $this->fileBasePath . $relativePath . $this->getExtension($contentNode);
if (!file_exists($fullPath)) {
try {
$this->saveData($contentNode, $fullPath);
} catch (Imagine\Exception\Exception $e) {
//TODO: notfound exception is not appropriate ... how to best do this?
//throw new NotFoundHttpException('image save to filesystem failed: ' . $e->getMessage());
return 'notfound';
}
}
return $this->webRelativePath . $relativePath . $this->getExtension($contentNode);
}
示例2: toJsonLD
protected function toJsonLD(NodeInterface $node)
{
$data = $node->getPropertiesValues(null, false);
$data['@'] = $node->getPath();
$data['a'] = $node->getPrimaryNodeType();
return $data;
}
示例3: traverse
/**
* Traverse the node
*
* @param NodeInterface|null $node The node to traverse, if it exists yet
* @param array $segments The element => token stack
* @param array $result The result
*
* @return null
*/
private function traverse(array $segments, &$result = array(), $node = null)
{
$path = array();
if (null !== $node) {
$path = explode('/', substr($node->getPath(), 1));
}
do {
list($element, $bitmask) = array_shift($segments);
if ($bitmask & SelectorParser::T_STATIC) {
$path[] = $element;
if ($bitmask & SelectorParser::T_LAST) {
if ($node = $this->getNode($path)) {
$result[] = $node;
break;
}
}
}
if ($bitmask & SelectorParser::T_PATTERN) {
if (null === ($parentNode = $this->getNode($path))) {
return;
}
$children = $this->getChildren($parentNode, $element);
foreach ($children as $child) {
if ($bitmask & SelectorParser::T_LAST) {
$result[] = $child;
} else {
$this->traverse($segments, $result, $child);
}
}
return;
}
} while ($segments);
}
示例4: remove
/**
* {@inheritdoc}
*/
public function remove(NodeInterface $node, PropertyInterface $property, $webspaceKey, $languageCode, $segmentKey)
{
// if exist remove property of node
if ($node->hasProperty($property->getName())) {
$node->getProperty($property->getName())->remove();
}
}
示例5: serializePhpcrNode
/**
* @param JsonSerializationVisitor $visitor
* @param NodeInterface $nodeInterface
* @param array $type
* @param Context $context
*/
public function serializePhpcrNode(JsonSerializationVisitor $visitor, NodeInterface $node, array $type, Context $context)
{
$res = array();
foreach ($node->getProperties() as $name => $property) {
$res[$name] = $property->getValue();
}
return $res;
}
示例6: saveData
/**
*
*
* @param NodeInterface $contentNode
* @param string $filesystemPath
* @return Boolean
*/
protected function saveData($contentNode, $filesystemPath)
{
$data = $contentNode->getProperty('jcr:data')->getString();
$dirname = dirname($filesystemPath);
if (!file_exists($dirname)) {
mkdir($dirname, 0755, true);
}
return file_put_contents($filesystemPath, $data);
}
示例7: upgradeNode
/**
* Removes non translated properties.
*
* @param NodeInterface $node
*/
private function upgradeNode(NodeInterface $node)
{
foreach ($node->getProperties('i18n:-*') as $property) {
$property->remove();
}
foreach ($node->getNodes() as $childNode) {
$this->upgradeNode($childNode);
}
}
示例8: writeMetadata
/**
* {@inheritDoc}
*/
public function writeMetadata(DocumentManagerInterface $dm, NodeInterface $node, $className)
{
$className = $this->expandClassName($dm, $className);
if ('Doctrine\\ODM\\PHPCR\\Document\\Generic' !== $className) {
$node->setProperty('phpcr:class', $className, PropertyType::STRING);
$class = $dm->getClassMetadata($className);
$node->setProperty('phpcr:classparents', $class->getParentClasses(), PropertyType::STRING);
}
}
示例9: write
/**
* {@inheritdoc}
*/
public function write(NodeInterface $node, PropertyInterface $property, $userId, $webspaceKey, $languageCode, $segmentKey)
{
$value = $property->getValue();
if ($value !== null) {
$node->setProperty($property->getName(), $this->removeValidation($this->removeIllegalCharacters($value)));
} else {
$this->remove($node, $property, $webspaceKey, $languageCode, $segmentKey);
}
}
示例10: write
/**
* {@inheritdoc}
*/
public function write(NodeInterface $node, PropertyInterface $property, $userId, $webspaceKey, $languageCode, $segmentKey)
{
$value = $property->getValue();
if ($value !== null && $value !== false && $value !== 'false' && $value !== '') {
$node->setProperty($property->getName(), true);
} else {
$node->setProperty($property->getName(), false);
}
}
示例11: createNodes
protected function createNodes(NodeInterface $parentNode, $number, $properties = array(), $offset = 0)
{
$number = $number + $offset;
for ($i = $offset; $i < $number; $i++) {
$node = $parentNode->addNode('node-' . $i);
foreach ($properties as $property => $value) {
$node->setProperty($property, $value);
}
}
}
示例12: traverse
private function traverse(NodeInterface $node)
{
$i = 10;
foreach ($node->getNodes() as $childNode) {
$childNode->setProperty(NodeOrderSubscriber::SULU_ORDER, $i);
$this->context->getOutput()->writeln(sprintf('<info>[+]</info> Setting order "<comment>%s</comment>" on <comment>%s</comment>', $i, $childNode->getPath()));
$this->traverse($childNode);
$i += 10;
}
}
示例13: transform
/**
* Transform a node into a uuid
*
* @param \PHPCR\NodeInterface|null $node
*
* @return string|null the uuid to the node or null if $node is null
*
* @throws UnexpectedTypeException if given value is not a PHPCR\NodeInterface
*/
public function transform($node)
{
if (null === $node) {
return null;
}
if (!$node instanceof NodeInterface) {
throw new UnexpectedTypeException($node, 'PHPCR\\NodeInterface');
}
return $node->getIdentifier();
}
示例14: getTranslationNode
protected function getTranslationNode(NodeInterface $parentNode, $locale)
{
$name = Translation::LOCALE_NAMESPACE . ":{$locale}";
if (!$parentNode->hasNode($name)) {
$node = $parentNode->addNode($name);
} else {
$node = $parentNode->getNode($name);
}
return $node;
}
示例15: read
/**
* {@inheritdoc}
*/
public function read(NodeInterface $node, PropertyInterface $property, $webspaceKey, $languageCode, $segmentKey)
{
$value = '';
if ($node->hasProperty($property->getName())) {
/** @var \DateTime $propertyValue */
$propertyValue = $node->getPropertyValue($property->getName());
$value = $propertyValue->format('Y-m-d');
}
$property->setValue($value);
return $value;
}