An open API service indexing awesome lists of open source software.

https://github.com/dantleech/phpcr-decorator

Decorator for PHPCR
https://github.com/dantleech/phpcr-decorator

Last synced: over 1 year ago
JSON representation

Decorator for PHPCR

Awesome Lists containing this project

README

          

PHPCR Decorator
===============

Proxy implementation of PHPCR which enables you to decorate (a.k.a wrap) all
classes returned by a PHPCR implementation.

For example, you can use this library to decorate all `NodeInterface` classes
with a custom class.

The library can be used as a basis for expanding the functionality of PHPCR
in the application layer.

For example:

- Using a custom class in place of the implementations default class
- Map nodes to domain classes via. node types.
- Add logging

Decorating
----------

To use this library you will need to manually instantiate one of the decorator
objects. It is recommended that you wrap the `Session` object.

You will also need to pass a decorator which will handle any further
instantiations that happen inside the object. For example, when you call
`$session->getNode()` the DecoratorFactory will be called and the value it returns
will be the value returned from the decorator.

For the purpose of demonstration the `PassthruDecoratorFactory` will
be used, and it will transparently return the original node.

````php
$decoratorFactory = new Sulu\Component\PhpcrDecorator\PHPCR\PassthruDecoratorFactory();
$originalSession = // original PHPCR session
$session = new Sulu\Component\PhpcrDecorator\PHPCR\Session(
$originalSession, $decoratorFactory
);

// will return the implementation node because we use the passthru factory
$session->getNode('/foo');
````

So, thats pretty pointless. But now we can create a custom decorator:

````php
getPropertyValue('some:cool:property');
}
}
````

Code Generation
---------------

The contents `lib/PHPCR` and `tests/PHPCR` were generated by the
`/bin/generate.php` script. If you find a bug you will need to
modify this script.

Why not modify the implementations factory?
-------------------------------------------

It is possible to achieve the benefits enabled in this library by
substituting the Factory used by your implementation (i.e.
`Jackalope\Factory`). This, however, has a big drawback.

The drawback is that you are bound to a single implementation, by the
fact that you have modified the factory of a single implementation and,
more importantly, by the fact that all of your custom classes will need
to extend the implementations classes.

So with that in mind, using this library provides a perfect abstraction
between the PHPCR implementation and your application.