|
| 1 | +Introduction and Getting Stated |
| 2 | +=============================== |
| 3 | + |
| 4 | +This is an introduction into the PHP content repository. You will mostly see code examples. It should work with any PHPCR implementation. We propose using [Jackalope Jackrabbit](https://github.com/jackalope/jackalope-jackrabbit) to get started as it supports all features described here. |
| 5 | + |
| 6 | +Installing Jackalope |
| 7 | +-------------------- |
| 8 | + |
| 9 | +Just follow the README of the [jackalope-jackrabbit](https://github.com/jackalope/jackalope-jackrabbit/blob/master/README.md) repository. |
| 10 | + |
| 11 | +Browser to see what is in the repository |
| 12 | +---------------------------------------- |
| 13 | + |
| 14 | +There are currently two options for browsing and modifying the contents of the PHPCR repository. |
| 15 | + |
| 16 | +- <a href="/documentation/phpcr-shell">PHPCR Shell</a>: Aims to provide a full command line shell interface to PHPCR content repositories. A pre-compiled PHAR archive is available on the github homepage. |
| 17 | +- <a href="https://github.com/marmelab/phpcr-browser">Marmelab PHPCR Browser</a>: A web based PHPCR browser. |
| 18 | + |
| 19 | +In a nutshell |
| 20 | +------------- |
| 21 | + |
| 22 | +The shortest self-contained example should output a line with 'value': |
| 23 | + |
| 24 | +.. code-block:: php |
| 25 | +
|
| 26 | + <?php |
| 27 | + require("/path/to/jackalope-jackrabbit/vendor/autoload.php"); |
| 28 | +
|
| 29 | + $factoryclass = '\Jackalope\RepositoryFactoryJackrabbit'; |
| 30 | + $parameters = array('jackalope.jackrabbit_uri' => 'http://localhost:8080/server'); |
| 31 | + // end of implementation specific configuration |
| 32 | +
|
| 33 | + $factory = new $factoryclass(); |
| 34 | + $repository = $factory->getRepository($parameters); |
| 35 | + $credentials = new \PHPCR\SimpleCredentials('admin','admin'); |
| 36 | + $session = $repository->login($credentials, 'default'); |
| 37 | + $root = $session->getRootNode(); |
| 38 | + $node = $root->addNode('test', 'nt:unstructured'); |
| 39 | + $node->setProperty('prop', 'value'); |
| 40 | + $session->save(); |
| 41 | +
|
| 42 | + // data is stored now. in a follow-up request you can do |
| 43 | + $node = $session->getNode('/test'); |
| 44 | + echo $node->getPropertyValue('prop'); // outputs "value" |
| 45 | +
|
| 46 | +Still with us? Good, lets get in a bit deeper... |
| 47 | + |
| 48 | +Get some data into the repository |
| 49 | +--------------------------------- |
| 50 | + |
| 51 | +We will discuss the import feature in more detail later, but to have some data, we just import something here. Create an XML file test.xml like this: |
| 52 | + |
| 53 | +.. code-block:: xml |
| 54 | +
|
| 55 | + <data xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"> |
| 56 | + <node title="Test" content="This is some test content" /> |
| 57 | + <sibling title="Test" content="This is another test content"> |
| 58 | + <child1 title="Child1 title" /> |
| 59 | + <child2 title="Child2 title" /> |
| 60 | + <otherchild title="Otherchild title"/> |
| 61 | + <yetanother title="Yetanother title"> |
| 62 | + <child title="Child title" /> |
| 63 | + </yetanother> |
| 64 | + </sibling> |
| 65 | + </data> |
| 66 | +
|
| 67 | +Now import this into the repository: |
| 68 | + |
| 69 | +.. code-block:: php |
| 70 | +
|
| 71 | + <?php |
| 72 | + $session->importXML('/', 'test.xml', \PHPCR\ImportUUIDBehaviorInterface::IMPORT_UUID_CREATE_NEW); |
| 73 | + $session->save(); |
| 74 | +
|
0 commit comments