01 | < jcr:root > |
02 | < cms > |
03 | < pages > |
04 | < home title = "Hello" > |
05 | < block title = "News" |
06 | content = "Today: PHPCR presentation" /> |
07 | </ home > |
08 | < contact title = "Contact" |
09 | content = "phpcr-users@groups.google.com" /> |
10 | </ pages > |
11 | </ cms > |
12 | </ jcr:root > |
Source: phpcr.github.com
* Not yet implemented in any PHP implementation
A test suite for PHPCR makes sure all implementations interpret the specification the same way.
Test results using Jackalope with the Jackrabbit backend.
......................................S.........S.....II..... 61 / 1222 ( 4%) ...........S.S............................................... 122 / 1222 ( 9%) ...........SS.......SS.S.......S............................. 183 / 1222 ( 14%) ............................................................. 244 / 1222 ( 19%) ............................................................. 305 / 1222 ( 24%) ............................................................. 366 / 1222 ( 29%) ............................................................. 427 / 1222 ( 34%) ..............................S.........SSS..............I.I. 488 / 1222 ( 39%) I.I.........................I...................I..I........S 549 / 1222 ( 44%) I............................................................ 610 / 1222 ( 49%) .....S.......I.....................S..S...................... 671 / 1222 ( 54%) .................SS...............SSSS..S.................... 732 / 1222 ( 59%) .......................................................SSSSS. 793 / 1222 ( 64%) ..........................S.............I......S...........I. 854 / 1222 ( 69%) .............................SS..................S........... 915 / 1222 ( 74%) ............................................................. 976 / 1222 ( 79%) ............................................................. 1037 / 1222 ( 84%) ...............................S............................. 1098 / 1222 ( 89%) ...........SSSS...........SSS................................ 1159 / 1222 ( 94%) ........................................SSSSSS............... 1220 / 1222 ( 99%) . Time: 03:23, Memory: 93.50Mb OK, but incomplete or skipped tests! Tests: 1212, Assertions: 6797, Incomplete: 17, Skipped: 49.
|
|
Please give me feedback:
@dbu on Twitter, or david@liip.ch
01 | use PHPCR\SimpleCredentials; |
02 |
03 | // start of implementation specific configuration // |
04 | $parameters = array ( |
05 | 'jackalope.jackrabbit_uri' |
06 | => 'http://localhost:8080/server' , |
07 | ); |
08 | $factory = new \Jackalope\RepositoryFactoryJackrabbit(); |
09 | $repository = $factory ->getRepository( $parameters ); |
10 | // end of implementation specific configuration // |
11 |
12 | $creds = new SimpleCredentials( 'admin' , 'admin' ); |
13 | $session = $repository ->login( $creds , 'default' ); |
01 | $root = $session ->getRootNode(); |
02 |
03 | // Nodes must be added as child of another node |
04 | $node = $root ->addNode( 'test' , 'nt:unstructured' ); |
05 |
06 | // New node is immediately available to this session |
07 | $node = $session ->getNode( '/test' ); |
08 |
09 | // Create/update a property |
10 | $node ->setProperty( 'prop' , 'value' ); |
11 |
12 | // New node is now available for all sessions |
13 | $session ->save(); |
14 |
15 | // Delete the node and all its children |
16 | $node ->remove(); |
17 |
18 | // Fails if a concurrent session also changed '/test' |
19 | $session ->save(); |
01 | $node = $session ->getNode( '/site/content' ); |
02 |
03 | foreach ( $node ->getNodes() as $child ) { |
04 | var_dump( $child ->getName()); |
05 | } |
06 |
07 | // or in short |
08 | foreach ( $node as $child ) { |
09 | var_dump( $child ->getName()); |
10 | } |
11 |
12 | // filter on node names |
13 | foreach ( $node ->getNodes( 'di*' ) as $child ) { |
14 | var_dump( $child ->getName()); |
15 | } |
01 | // make versionable |
02 | $node = $session ->getNode( '/site/content/about' ); |
03 | $node ->addMixin( 'mix:versionable' ); |
04 | $session ->save(); |
05 | // create initial version |
06 | $node ->setProperty( 'title' , 'About' ); |
07 | $session ->save(); |
08 |
09 | // check-in (create version) |
10 | // and check-out (prepare for further updates) |
11 | // persisted immediately without a save() call |
12 | $vm = $session ->getWorkspace()->getVersionManager(); |
13 | $vm ->checkpoint( $node ->getPath()); |
01 | // update node with some changes |
02 | $node ->setProperty( 'title' , 'Ups' ); |
03 | $session ->save(); |
04 |
05 | // create another version, leave in read only state |
06 | $vm ->checkin( $node ->getPath()); |
07 |
08 | $base = $vm ->getBaseVersion( $node ->getPath()); |
09 | $current = $base ->getLinearPredecessor(); |
10 | $previous = $current ->getLinearPredecessor(); |
11 |
12 | // get snapshot of old version to look around |
13 | $frozenNode = $previous ->getFrozenNode(); |
14 | echo $frozenNode ->getProperty( 'title' ); // About |
15 |
16 | // set the live data back to what is in this version |
17 | $vm ->restore(true, $previous ); |
18 |
19 | $node = $session ->getNode( '/site/content/about' ); |
20 | echo $node ->getProperty( 'title' ); // About |
01 | $qm = $workspace ->getQueryManager(); |
02 |
03 | // unlike SQL, in SQL2 "*" does not return all columns |
04 | // but at least the path and match score |
05 | $sql = "SELECT * FROM [nt:unstructured] |
06 | WHERE [nt:unstructured].type = 'nav' |
07 | AND ISDESCENDANTNODE( '/some/path' ) |
08 | ORDER BY score, [nt:unstructured].title"; |
09 | $query = $qm ->createQuery( $sql , 'JCR-SQL2' ); |
10 | $query ->setLimit( $limit ); |
11 | $query ->setOffset( $offset ); |
12 | $queryResult = $query ->execute(); |
13 |
14 | foreach ( $queryResult ->getNodes() as $node ) { |
15 | var_dump( $node ->getPath()); |
16 | } |
01 | $qm = $workspace ->getQueryManager(); |
02 | $factory = $qm ->getQOMFactory(); |
03 |
04 | // SELECT * FROM nt:file INNER JOIN nt:folder ON ISCHILDNODE(child, parent) |
05 | $factory ->createQuery( |
06 | $factory ->join( |
07 | $factory ->selector( 'nt:file' ), |
08 | $factory ->selector( 'nt:folder' ), |
09 | Constants::JCR_JOIN_TYPE_INNER, |
10 | $factory ->childNodeJoinCondition( |
11 | 'child' , 'parent' )), |
12 | null, |
13 | array (), |
14 | array () |
15 | ); |
(With phpcr-utils)
01 | $qm = $workspace ->getQueryManager(); |
02 | $factory = $qm ->getQOMFactory(); |
03 |
04 | // SELECT * FROM nt:unstructured |
05 | // WHERE name NOT IS NULL |
06 | // LIMIT 10 OFFSET 10 |
07 | $qb = new QueryBuilder( $factory ); |
08 | $qb ->select( $factory ->selector( 'nt:unstructured' )) |
09 | ->where( $factory ->propertyExistence( 'name' )) |
10 | ->setFirstResult(10) |
11 | ->setMaxResults(10) |
12 | ->execute(); |
01 | $test = $session ->getNode( '/test' ); |
02 | $test1 = $session1 ->getNode( '/test' ); |
03 |
04 | $test ->remove(); |
05 | $test1 ->setProperty( 'prop' , 'value' ); |
06 |
07 | $session ->save(); |
08 |
09 | // this will fail as the node is gone |
10 | $session1 ->save(); |
01 | // prepare |
02 | $test = $session ->getNode( '/test' ); |
03 | $test ->addMixin( 'mix:lockable' ); |
04 | $session ->save(); |
05 |
06 | // use |
07 | $lm = $session ->getWorkspace()->getLockManager(); |
08 | // lock node and children for 5 seconds |
09 | $lock = $lm ->lock( '/test' , true, true, 5); |
10 |
11 | $test1 = $session1 ->getNode( '/test' ); |
12 |
13 | // here you will get an exception that node is locked |
14 | $test1 ->setProperty( 'prop' , 'value' ); |