作者:ralf5
项目:CoreBundl
/**
* 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);
}
作者:richardmille
项目:LiipVieBundl
protected function toJsonLD(NodeInterface $node)
{
$data = $node->getPropertiesValues(null, false);
$data['@'] = $node->getPath();
$data['a'] = $node->getPrimaryNodeType();
return $data;
}
作者:frogriotco
项目:glo
/**
* 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);
}
作者:sul
项目:sul
/**
* {@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();
}
}
作者:frogriotco
项目:ResourceRestBundl
/**
* @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;
}
作者:richardmille
项目:symfony-cm
/**
*
*
* @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);
}
作者:sul
项目:sul
/**
* 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);
}
}
作者:steffenbre
项目:phpcr-od
/**
* {@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);
}
}
作者:sul
项目:sul
/**
* {@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);
}
}
作者:Silweret
项目:sul
/**
* {@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);
}
}
作者:phpc
项目:phpcr-benchmark
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);
}
}
}
作者:Silweret
项目:sul
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;
}
}
作者:nikophi
项目:cmf-test
/**
* 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();
}
作者:nica
项目:phpcr-od
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;
}
作者:olliet
项目:sul
/**
* {@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;
}
作者:haso
项目:phpcr-shel
public function it_should_provide_a_method_to_determine_if_a_node_is_versionable(NodeInterface $nodeVersionable, NodeInterface $nodeNotVersionable, NodeTypeInterface $mixin1, NodeTypeInterface $mixin2)
{
$nodeVersionable->getMixinNodeTypes()->willReturn(array($mixin1, $mixin2));
$nodeNotVersionable->getMixinNodeTypes()->willReturn(array($mixin2));
$nodeNotVersionable->getPath()->willReturn('foobar');
$mixin1->getName()->willReturn('mix:versionable');
$this->assertNodeIsVersionable($nodeVersionable)->shouldReturn(null);
try {
$this->assertNodeIsVersionable($nodeNotVersionable);
} catch (\OutOfBoundsException $e) {
}
}
作者:nica
项目:phpcr-od
/**
* {@inheritdoc}
*/
public function getLocalesFor($document, NodeInterface $node, ClassMetadata $metadata)
{
$locales = array();
foreach ($node->getProperties("*{$this->prefix}*") as $prop) {
$matches = null;
if (preg_match('/' . $this->prefix . ':(..)-[^-]*/', $prop->getName(), $matches)) {
if (is_array($matches) && count($matches) > 1 && !in_array($matches[1], $locales)) {
$locales[] = $matches[1];
}
}
}
return $locales;
}
作者:Silweret
项目:sul
/**
* {@inheritdoc}
*/
public function read(NodeInterface $node, PropertyInterface $property, $webspaceKey, $languageCode, $segmentKey)
{
$value = $this->defaultValue;
if ($node->hasProperty($property->getName())) {
$value = $node->getPropertyValue($property->getName());
}
// the RedirectType subscriber sets the internal link as a reference
if ($value instanceof NodeInterface) {
$value = $value->getIdentifier();
}
$property->setValue($value);
return $value;
}
作者:haso
项目:sulu-document-manage
/**
* {@inheritdoc}
*/
public function resolveMetadataForNode(NodeInterface $node)
{
if (false === $node->hasProperty('jcr:mixinTypes')) {
return;
}
$mixinTypes = (array) $node->getPropertyValue('jcr:mixinTypes');
foreach ($mixinTypes as $mixinType) {
if (true == $this->metadataFactory->hasMetadataForPhpcrType($mixinType)) {
return $this->metadataFactory->getMetadataForPhpcrType($mixinType);
}
}
return;
}
作者:phpc
项目:phpcr-benchmark
private function traverse(NodeInterface $node, $readProperties = false)
{
if ($readProperties) {
foreach ($node->getProperties() as $property) {
try {
$property->getValue();
} catch (\PHPCR\RepositoryException $e) {
}
}
}
foreach ($node->getNodes() as $child) {
$this->traverse($child, $readProperties);
}
}