本文整理汇总了PHP中PHPCR\NodeInterface::addNode方法的典型用法代码示例。如果您正苦于以下问题:PHP NodeInterface::addNode方法的具体用法?PHP NodeInterface::addNode怎么用?PHP NodeInterface::addNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPCR\NodeInterface
的用法示例。
在下文中一共展示了NodeInterface::addNode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
public function setUp()
{
$this->typeReference = 'Doctrine\\Tests\\ODM\\PHPCR\\Functional\\Versioning\\ReferenceTestObj';
$this->dm = $this->createDocumentManager();
// Check that the repository supports versioning
$repository = $this->dm->getPhpcrSession()->getRepository();
if (!$repository->getDescriptor('option.versioning.supported')) {
$this->markTestSkipped('PHPCR repository does not support versioning');
}
$this->node = $this->resetFunctionalNode($this->dm);
$versionNode = $this->node->addNode('versionTestObj');
$versionNode->setProperty('username', 'lsmith');
$versionNode->setProperty('numbers', array(3, 1, 2));
$versionNode->setProperty('phpcr:class', $this->typeVersion);
$versionNode->addMixin("mix:versionable");
$referenceNode = $this->node->addNode('referenceTestObj');
$referenceNode->setProperty('content', 'reference test');
$referenceNode->setProperty('phpcr:class', $this->typeReference);
$referenceNode->addMixin("mix:referenceable");
$this->dm->getPhpcrSession()->save();
$versionNodeWithReference = $this->node->addNode('versionTestObjWithReference');
$versionNodeWithReference->setProperty('username', 'laupifrpar');
$versionNodeWithReference->setProperty('numbers', array(6, 4, 5));
$versionNodeWithReference->setProperty('reference', $referenceNode);
$versionNodeWithReference->addMixin("mix:versionable");
$this->dm->getPhpcrSession()->save();
$this->dm = $this->createDocumentManager();
}
示例2: testFindByClass
public function testFindByClass()
{
$user = $this->node->addNode('userWithAlias');
$user->setProperty('username', 'dbu');
$user->setProperty('numbers', array(3, 1, 2));
$user->setProperty('phpcr:class', $this->type, \PHPCR\PropertyType::STRING);
$this->dm->getPhpcrSession()->save();
$userWithAlias = $this->dm->find(null, '/functional/userWithAlias');
$this->assertEquals('dbu', $userWithAlias->username);
}
示例3: setUp
public function setUp()
{
$this->type = 'Doctrine\\Tests\\Models\\CMS\\CmsUser';
$this->dm = $this->createDocumentManager(array(__DIR__));
$this->node = $this->resetFunctionalNode($this->dm);
$user = $this->node->addNode('lsmith');
$user->setProperty('username', 'lsmith');
$user->setProperty('numbers', array(3, 1, 2));
$user->setProperty('phpcr:class', $this->type, \PHPCR\PropertyType::STRING);
$this->dm->getPhpcrSession()->save();
}
示例4: setUp
public function setUp()
{
$this->type = 'Doctrine\\Tests\\ODM\\PHPCR\\Functional\\Hierarchy\\NameDoc';
$this->dm = $this->createDocumentManager();
$this->node = $this->resetFunctionalNode($this->dm);
$root = $this->dm->getPhpcrSession()->getNode('/');
if ($root->hasNode('childOfRoot')) {
$root->getNode('childOfRoot')->remove();
}
$user = $this->node->addNode('thename');
$user->setProperty('phpcr:class', $this->type, \PHPCR\PropertyType::STRING);
$this->dm->getPhpcrSession()->save();
}
示例5: setUp
public function setUp()
{
$this->type = 'Doctrine\\Tests\\ODM\\PHPCR\\Functional\\TypeUser';
$this->dm = $this->createDocumentManager(array(__DIR__));
$this->node = $this->resetFunctionalNode($this->dm);
$user = $this->node->addNode('user');
$user->setProperty('username', 'lsmith');
$user->setProperty('note', 'test');
$user->setProperty('numbers', array(3, 1, 2));
$user->setProperty('parameters', array('bar', 'dong'));
$user->setProperty('parameterKey', array('foo', 'ding'));
$user->setProperty('phpcr:class', $this->type, PropertyType::STRING);
$this->dm->getPhpcrSession()->save();
}
示例6: setUp
public function setUp()
{
$this->type = 'Doctrine\\Tests\\Models\\CMS\\CmsTeamUser';
$this->dm = $this->createDocumentManager(array(__DIR__));
$this->node = $this->resetFunctionalNode($this->dm);
$user = $this->node->addNode('dbu');
$user->setProperty('username', 'dbu');
$user->setProperty('status', 'created');
$user->setProperty('phpcr:class', $this->type, PropertyType::STRING);
$user = $this->node->addNode('team');
$user->setProperty('username', 'team');
$user->setProperty('phpcr:class', $this->type, PropertyType::STRING);
$this->dm->getPhpcrSession()->save();
}
示例7: setUp
public function setUp()
{
$this->type = 'Doctrine\\Tests\\Models\\Translation\\Article';
$this->dm = $this->createDocumentManager();
$this->dm->setLocaleChooserStrategy(new LocaleChooser(array('en' => array('fr'), 'fr' => array('en')), 'en'));
$this->node = $this->resetFunctionalNode($this->dm);
$user = $this->node->addNode('thename');
$user->setProperty('phpcr:class', $this->type, \PHPCR\PropertyType::STRING);
$user->setProperty('phpcr_locale:fr-topic', 'french', \PHPCR\PropertyType::STRING);
$user->setProperty('phpcr_locale:fr-text', 'french text', \PHPCR\PropertyType::STRING);
$user->setProperty('phpcr_locale:frnullfields', array('nullable'), \PHPCR\PropertyType::STRING);
$user->setProperty('phpcr_locale:en-topic', 'english', \PHPCR\PropertyType::STRING);
$user->setProperty('phpcr_locale:en-text', 'english text', \PHPCR\PropertyType::STRING);
$user->setProperty('phpcr_locale:ennullfields', array('nullable'), \PHPCR\PropertyType::STRING);
$this->dm->getPhpcrSession()->save();
}
示例8: createNodeForDocument
/**
* {@inheritdoc}
*/
public function createNodeForDocument($document, NodeInterface $parentNode, $name)
{
$metadata = $this->metadataFactory->getMetadataForClass(get_class($document));
$node = $parentNode->addNode($name);
$node->addMixin($metadata->getPhpcrType());
$node->setProperty('jcr:uuid', UUIDHelper::generateUUID());
return $node;
}
示例9: 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;
}
示例10: 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);
}
}
}
示例11: testFindNullableFieldNone
/**
* No translation whatsoever is available. All translated fields have to be
* null as we do not validate on loading.
*/
public function testFindNullableFieldNone()
{
$node = $this->node->addNode('find');
$node->setProperty('phpcr:class', 'Doctrine\\Tests\\Models\\Translation\\Article');
$this->dm->getPhpcrSession()->save();
$this->dm->clear();
/** @var $doc Article */
$doc = $this->dm->find(null, $this->node->getPath() . '/find');
$this->assertEquals('en', $doc->locale);
$this->assertNull($doc->topic);
$this->assertNull($doc->text);
}
示例12: setUp
public function setUp()
{
$this->type = 'Doctrine\\Tests\\ODM\\PHPCR\\Functional\\QuerySql2TestObj';
$this->dm = $this->createDocumentManager();
$this->node = $this->resetFunctionalNode($this->dm);
$versionNode = $this->node->addNode('node1', 'nt:unstructured');
$versionNode->setProperty('username', 'dbu');
$versionNode->setProperty('numbers', array(3, 1, 2));
$versionNode->setProperty('phpcr:class', $this->type);
$versionNode = $this->node->addNode('node2', 'nt:unstructured');
$versionNode->setProperty('username', 'johannes');
$versionNode->setProperty('numbers', array(3, 1, 2));
$versionNode->setProperty('phpcr:class', $this->type);
$versionNode = $this->node->addNode('node3', 'nt:unstructured');
$versionNode->setProperty('username', 'lsmith');
$versionNode->setProperty('numbers', array(3, 1, 2));
$versionNode->setProperty('phpcr:class', $this->type);
$versionNode = $this->node->addNode('node4', 'nt:unstructured');
$versionNode->setProperty('username', 'uwe');
$versionNode->setProperty('numbers', array(3, 1, 2));
$versionNode->setProperty('phpcr:class', $this->type);
$versionNode = $this->node->addNode('node5', 'nt:unstructured');
$versionNode->setProperty('numbers', array(3, 1, 2));
$this->dm->getPhpcrSession()->save();
$this->dm = $this->createDocumentManager();
}
示例13: walkNode
private function walkNode(NodeBuilder $builder, NodeInterface $parentNode)
{
for ($i = $builder->getRangeStart(); $i <= $builder->getRangeEnd(); $i++) {
$name = str_replace(NodeBuilder::ITERATION_TOKEN, $i, $builder->getName());
$this->count++;
$node = $parentNode->addNode($name, $builder->getNodeTypeName());
foreach ($builder->getProperties() as $property) {
list($name, $value, $type) = $property;
$node->setProperty($name, $value, PropertyType::valueFromName($type));
}
foreach ($builder->getNodes() as $childNodeBuilder) {
$this->walkNode($childNodeBuilder, $node);
}
}
}
示例14: addNode
/**
* {@inheritdoc}
*/
public function addNode($relPath, $primaryNodeTypeName = null)
{
return $this->node->addNode($relPath, $primaryNodeTypeName);
}
示例15: processNodeWithType
/**
* Validate this node with the nodetype and generate not yet existing
* autogenerated properties as necessary.
*
* @param NodeInterface $node
* @param NodeType $nodeTypeDefinition
*
* @return AddNodeOperation[] Additional operations to handle autocreated nodes.
*
* @throws \InvalidArgumentException
* @throws RepositoryException
* @throws ItemExistsException
* @throws LockException
* @throws ConstraintViolationException
* @throws PathNotFoundException
* @throws VersionException
* @throws ValueFormatException
*/
private function processNodeWithType(NodeInterface $node, NodeType $nodeTypeDefinition)
{
$additionalOperations = array();
foreach ($nodeTypeDefinition->getDeclaredChildNodeDefinitions() as $childDef) {
/* @var $childDef NodeDefinitionInterface */
if (!$node->hasNode($childDef->getName())) {
if ('*' === $childDef->getName()) {
continue;
}
if ($childDef->isMandatory() && !$childDef->isAutoCreated()) {
throw new RepositoryException(sprintf('Child "%s" is mandatory, but is not present while saving "%s" at path "%s"', $childDef->getName(), $nodeTypeDefinition->getName(), $node->getPath()));
}
if ($childDef->isAutoCreated()) {
$requiredPrimaryTypeNames = $childDef->getRequiredPrimaryTypeNames();
$primaryType = count($requiredPrimaryTypeNames) ? current($requiredPrimaryTypeNames) : null;
$newNode = $node->addNode($childDef->getName(), $primaryType);
$absPath = $node->getPath() . '/' . $childDef->getName();
$operation = new AddNodeOperation($absPath, $newNode);
$additionalOperations[] = $operation;
}
}
}
foreach ($nodeTypeDefinition->getDeclaredPropertyDefinitions() as $propertyDef) {
/* @var $propertyDef PropertyDefinitionInterface */
if ('*' === $propertyDef->getName()) {
continue;
}
if (!$node->hasProperty($propertyDef->getName())) {
if ($propertyDef->isMandatory() && !$propertyDef->isAutoCreated()) {
throw new RepositoryException(sprintf('Property "%s" is mandatory, but is not present while saving "%s" at "%s"', $propertyDef->getName(), $nodeTypeDefinition->getName(), $node->getPath()));
}
if ($propertyDef->isAutoCreated()) {
switch ($propertyDef->getName()) {
case 'jcr:uuid':
$value = UUIDHelper::generateUUID();
break;
case 'jcr:createdBy':
case 'jcr:lastModifiedBy':
$value = $this->userId;
break;
case 'jcr:created':
case 'jcr:lastModified':
$value = new \DateTime();
break;
case 'jcr:etag':
// TODO: http://www.day.com/specs/jcr/2.0/3_Repository_Model.html#3.7.12.1%20mix:etag
$value = 'TODO: generate from binary properties of this node';
break;
default:
$defaultValues = $propertyDef->getDefaultValues();
if ($propertyDef->isMultiple()) {
$value = $defaultValues;
} elseif (isset($defaultValues[0])) {
$value = $defaultValues[0];
} else {
// When implementing versionable or activity, we need to handle more properties explicitly
throw new RepositoryException(sprintf('No default value for autocreated property "%s" at "%s"', $propertyDef->getName(), $node->getPath()));
}
}
$node->setProperty($propertyDef->getName(), $value, $propertyDef->getRequiredType());
}
} elseif ($propertyDef->isAutoCreated()) {
$prop = $node->getProperty($propertyDef->getName());
if (!$prop->isModified() && !$prop->isNew()) {
switch ($propertyDef->getName()) {
case 'jcr:lastModified':
if ($this->autoLastModified) {
$prop->setValue(new \DateTime());
}
break;
case 'jcr:lastModifiedBy':
if ($this->autoLastModified) {
$prop->setValue($this->userId);
}
break;
case 'jcr:etag':
// TODO: update etag if needed
break;
}
}
}
}
//.........这里部分代码省略.........