On Github dantleech / phpcr-presentation
Par Daniel Leech / @dantleech
C'est:
Il y a les chaptitres concernant les suivantes:
// chaque implementation doit fournir une repository factory
$factory = new \Jackalope\RepositoryFactoryDoctrineDBAL();
$repository = $factory->getRepository();
$credentials = new \PHPCR\SimpleCredentials('admin', 'mypassword');
$session = $repository->login($credentials);
$node = $session->getNode('/hello');
// profit
$children = $node->getNodes(); // return children nodes
foreach ($children as $child) {
$string = $child->getProperty('world');
echo $string;
}
// chaque implementation doit fournir une repository factory
$factory = new \Jackalope\RepositoryFactoryJackrabbit();
$repository = $factory->getRepository();
$credentials = new \PHPCR\SimpleCredentials('admin', 'mypassword');
$session = $repository->login($credentials);
$node = $session->getNode('/hello');
// encore de profit
$children = $node->getNodes(); // return children nodes
foreach ($children as $child) {
$string = $child->getProperty('world');
echo $string;
}
RepositoryFactoryJackDoctrineDbal
vs
RepositoryFactoryJackrabbit
Tout le reste est pareil!
$session = // obtenir le session
$rootNode = $session->getNode('/'); // recuperer le "root node"
$newNode = $rootNode->addNode('foobar'); // creer une nouveau node avec le nom "foobar"
// rename a node\a
$session->move('/foobar', '/barfoo');
// a cet point les changements sont pas encore fait dans la engin de stockage
$session->save(); // pop! c'est fait
/ (:root)
node1/ (nt:unstructured)
| - foobar = barfoo (STRING)
| - barfoo = foobar (STRING)
| ChildNode1/ (nt:folder)
| ChildNode2/ (nt:folder)
article/ (mycms:article)
- title: Titre de mon article (STRING)
- content: Ceci est le contenu de mon article (STRING)
- tags: [ tag1, tag2, tag3 ] (STRING[])
comments/ (mycms:comment))
comment1/ (mycms:comment)
/ (rep:root)
node1/ (nt:unstructured)
| - jcr:primaryType = nt:unstructured
| - jcr:uuid = 842e61c0-09ab-42a9-87c0-308ccc90e6f4 (REFERENCE)
| - jcr:mixinTypes = [ mix:referenceable ] (REFERENCE[])
| - foobar = barfoo
| - barfoo = foobar
article/ (mycms:article)
- jcr:primaryType = mon_type_article (NAME)
- jcr:mixinTypes = [ mix:versionable, mix:lastModified ] (NAME[])
- title: Titre de mon article (STRING)
- content: Ceci est le contenu de mon article (STRING)
- tags: [ tag1, tag2, tag3 ] (STRING[])
comments/ (mycms:comment))
comment1/ (mycms:comment)
Le type du moins permissif
[nt:base]
- jcr:primaryType (NAME) autocreated mandatory protected COMPUTE
- jcr:mixinTypes (NAME) autocreated mandatory protected multiple COMPUTE
Le type le plus permissif
[nt:unstructured] > nt:base
orderable
- * (UNDEFINED)
- * (UNDEFINED) multiple
+ * = nt:unstructured multiple VERSION
Pour stocker les binaires avec le metadata ..
[nt:resource] > mix:referenceable
- jcr:encoding (STRING)
- jcr:mimeType (STRING) mandatory
- jcr:data (BINARY) mandatory primary
- jcr:lastModified (DATE) mandatory IGNORE
$session = // we get the session
$workspace = $session->getWorkspace();
$queryManager = $workspace->getQueryManager();
$qom = $queryManager->getQOMFactory();
// START OF QUERY
$source = $qom->selector('s', '[nt:unstructured]');
$constraint = $qom->comparison(
$qom->nodeLocalName('s'),
QOMConstants::JCR_OPERATOR_NOT_EQUAL_TO,
$qom->literal('foobar')
);
$query = $qom->createQuery($source, $constraint, array(), array());
$queryResult = $query->execute();
Heuresement il est possible aussi de faire les queries en mode string
// JCR-SQL2
$sql = "SELECT * FROM [nt:unstructured] AS s WHERE LOCALNAME('s') = 'foobar'";
$query = $queryManager->createQuery($sql, 'JCR-SQL2');
$queryResult = $query->execute();
Versioning est activé pour une node avec le mixin "mix:versionable"
$node->addMixin('mix:versionable');
// FIX ME!!
$vm = $session->getWorkspace()->getVersionManager();
$node = $session->getNode('/this/is/a/versionable/node');
$node->setProperty('title', 'Hello World!');
$session->save();
$vm->checkpoint($node->getPath();
$vm->setProperty('title', 'Foobar');
$version = $vm->checkin($node->getPath());
$previous = $version->getLinearPredecessor();
$frozenNode = $previous->getFrozenNode();
echo $previous->getProperty('title');
// OUTPUT: Hello World!
$stream = fopen('my_content.xml', 'w');
$session->exportDocumentView(
'/path/to/what/i/want',
$stream,
);
$session->importXml('/import/to/here', 'my_content.xml');
Welcome to the PHPCR shell (1.0-pre-alpha).
PHPCR > ls
+--------------+-----------------+-------+
| Node / Prop | Type | Value |
+--------------+-----------------+-------+
| / | rep:root | |
| propriétés/ | nt:unstructured | |
+--------------+-----------------+-------+
2 node(s)
PHPCR > select * from [nt:unstructured] where localname() = 'propriétés';
| Row: #0 Score: 2
| Sel: nt:unstructured Path: /propriétés UID: none
+-----------------+---------------+----------+--------------------------------------+
| Name | Type | Multiple | Value |
+-----------------+---------------+----------+--------------------------------------+
| uri | URI | no | thisisuri |
| double | Long | no | 10 |
| binary | Binary | no | (binary data) |
| long | Long | no | 1234 |
| reference | Reference | no | 13543fc6-1abf-4708-bfcc-e49511754b40 |
| date | Date | no | 2011-04-21T14:34:20+01:00 |
| multivalue | String | yes | [0] thisisstring |
| | | | [1] thisisstring |
| string | String | no | thisisstring |
| boolean | Boolean | no | true |
| jcr:primaryType | Name | no | nt:unstructured |
+-----------------+---------------+----------+--------------------------------------+
1 rows in set (0.23 sec)
Jackalope