Download
Ready to integrate with any PHP project.
Note: Shard uses some components from the zf2 framework, but it does not need to be used inside the zf2 mvc. Shard is compatible with any php framework or system. However, if you are using the zf2 mvc, you'll probably want the ShardModule which handles installation and configuration for you.
Shard requires php 5.4
Source with Composer
Get the source, and easily manage versioning. This is the recommended way to install.
Add the following to your root composer.json
:
require: [ "zoopcommerce/shard": "~3.0" ]
Source from Github
Once downloaded, you'll need to run composer in Shard's root directory to install dependencies.
or gittish people:
git clone http://github.com/zoopcommerce/shard
What's Included
Shard is two things. First it is a system for creating, registering and using extentions that add behaviors to Documented managed by Doctrine Mongo ORM. Secondly, it is has over a dozen rich extensions already bundled to make your development fast, solid, and fun.
Docs sections
Doctrine Config
Detailed information about how configure Doctrine and Shard to work together.
PHP
How the Manifest works, which is the core of the extensions system.
Extensions
The bundled extensions and how they work.
Spec
A guide to writing your own Shard extensions for Doctrine Mongo ODM.
Examples
Most Shard extensions use annotations to add behaviors to documents.
Update Timestamp
Add the following annotation to a field. Whenever the document is updated, the field will be updated with a timestamp. Eg:
/** * @ODM\Timestamp * @Shard\Stamp\UpdatedOn */ protected $updatedOn;
Soft Delete
To make a document soft deletable, add the following annotation to a field:
/** * @ODM\Boolean * @Shard\SoftDelete * ) */ protected $softDeleted = false;
Then to Soft delete the document, use the SoftDeleter service:
$softDeleter = $manifest->getServiceManager()->get('softDeleter'); $softDeleter->softDelete($myDocument);
The SoftDeleter service can also be used to restore a document:
$softDeleter->restore($myDocument);
Data validation
Use annotations to add a validator to a field. Whenever the document is created or updated, the validators will be checked before the data is persisted.
/** * @ODM\String * @Shard\Validator\Email * ) */ protected $email;
All the validators in the Mystique validator library are supported, including validator chains. Eg:
/** * @ODM\String * @Shard\Validator\Chain({ * @Shard\Validator\Required, * @Shard\Validator\Email * }) * ) */ protected $email;
Access Control
Shard supports adding fine grained role based access control to documents. Eg, give all guest users read access, and admins complete control:
/** * @ODM\Document * @Shard\AccessControl({ * @Shard\Permission\Basic(roles="guest", allow="read") * @Shard\Permission\Basic(roles="admin", allow="*") * }) */ class Simple {...}
What next?
Dive into the docs for detailed instructions...