A content repository is a store of digital content with an associated set of data management, search and access methods allowing application-independent access to the content with the ability to store and modify content in addition to searching and retrieving.
Or: A bunch of data that is easy accessible
No implementation
A big tree of nodes
For example: a webpage with images or documents as child nodes
Any questions so far?
Jackalope is a PHPCR implementation
Jackrabbit is the storage
jackalope-jackrabbit is the transport layer
Goal: Creating your first content with PHPCR-Shell
and serving it based on the REQUEST_URI
Starting Jackrabbit and playing with PHPCR-shell
$ cd /var/www/html/workshops/phpcr
$ ./util/jackrabbit.sh start
# Wait for it....
$ phpcrsh -t jackrabbit
PHPCR >
Basic commands to remember
aliases
shows you a useful list with shortcuts
list
shows all available commands
node:create /cms
node:property:set /cms/homepage/title <title>
file:import /cms/press/media/image1 files/anvil.gif
Don't forget to session:save
!
Bootstrapping your application
Documentroot is set at /var/www/html/workshops/phpcr/cms/web
$factory = new Jackalope\RepositoryFactoryJackrabbit();
$repository = $factory->getRepository(array(
'jackalope.jackrabbit_uri' => 'http://localhost:8080/server'
));
$credentials = new \PHPCR\SimpleCredentials('admin', 'admin');
$session = $repository->login($credentials, 'default');
Disclaimer: We are not here to write pretty code :-)
Retrieving a node based on the path of a node
http://phpcr.ezsc/<path>
$rootNode = $session->getRootNode(); // Jackalope\Node
$cmsNode = $rootNode->getNode('cms'); // Jackalope\Node
$currentNode = $cmsNode->getNode($path); // Jackalope\Node
$cmsNode->hasNode($path); // true / false
$currentNode->isNodeType('nt:file'); // true / false
Make sure to handle unexisting nodes
Goal: Creating and using mixins and access files from our browser
Stuck on part 1? Run git checkout -f part2 && ./util/reset.sh part2
$ export EDITOR=<vim|nano>
PHPCRSH > node-type:edit mix:simple_page
<mix = 'http://www.jcp.org/jcr/mix/1.0'>
[mix:simple_page] > nt:unstructured
orderable query mixin
- title (string)
mandatory
- content (string)
mandatory
PHPCRSH > node:mixin:add /cms/homepage mix:simple_page
When you haven't created title and content properties yet, you will get an error when saving the session
All nodes with mix:simple_page
now
have a title and content property
$node->isNodeType('mix:simple_page');
$node->isNodeType('nt:file');
$resource = $node->getNode('jcr:resource');
$content = $resource->getProperty('jcr:data')->getString();
$mimeType = $resource->getPropertyValue('jcr:mimeType');
header('Content-Type: ' . $mimeType);
echo $content;
http://phpcr.ezsc/press/media/image1
Goal: Using references to create a custom URL and create a menu
mix:referenceable
to /cms/press/media
/routes/gallery
node
" to /routes/gallery./cms/press/media
.reference
PHPCRSH > node:property:set --type=reference /routes/gallery/node <UUID>
$routesNode = $rootNode->getNode('routes');
// ..
if ($routesNode->hasNode($path)) {
$route = $routesNode->getNode($path);
$node = $route->getPropertyValue('node'); // Jackalope\Node
} elseif ($cmsNode->hasNode($path)) {
// .. load node from $cmsNode
}
Create a new mixin: mix:menuItem
node-type:edit mix:menuItem
<mix = 'http://www.jcp.org/jcr/mix/1.0'>
[mix:menuItem] > nt:unstructured
orderable query mixin
- label (string)
mandatory
- path (string)
mandatory
+ nt:unstructured (mix:menuItem)
$menuNode = $rootNode->getNode('menu');
function renderMenu($menuNode) {
foreach ($menuNode as $childNode) {
$path = $childeNode->getPropertyValue('path');
$label = $childNode->getPropertyValue('label');
echo '<a href="' . $path .'">' . $label . '</a>';
if ($childNode->hasNodes()) renderMenu($childNode);
}
}
renderMenu($menuNode);
Goal: Implement versioning and switch between versions with a dropdown
mix:versionable
to the nodes you want to version/cms/homepage
/cms/homepage
// Get the version manager
$versionManager = $session->getWorkspace()
->getVersionManager();
// retrieve version history for a node
$versionHistory = $versionManager
->getVersionHistory($node->getPath());
// Retrieve the latest version
$currentVersion = $versionManager
->getBaseVersion($node->getPath());
// retrieve all versions
$versions = $versionHistory->getAllVersions();
// retrieve a specific version
$specificVersion = $versionHistory->getVersion('1.0');
// Retrieve the node of the version
$node = $version->getFrozenNode();
<form method="GET">
<select name="version" onchange="this.form.submit();">
<?php foreach ($versions as $version): ?>
<option value="<?php echo $version->getName(); ?>">
<?php echo $version->getName(); ?>
</option>
</select>
Don't forget to vote to increase your chances at the raffle!
http://vote.netgenlabs.com/