Repository pattern for PHP
Code information:
Package information:
<?php
$storage = new \Koine\Repository\Storage\MySql($pdo, 'users');
$repository = new \Koine\Repository\Repository($storage);
$respository->setHydrator($hydrator)
->setEntityPrototype(new User());
// all
$users = $respository->findAll();
// first foo
$foo = $respository->findOneBy(array(
'name' => 'foo',
));
// by name foo
$foos = $respository->findAllBy(array(
'name' => 'foo',
));
// creating
$repository->persist(new User('bar'));
// changing
$foo->setName('bar');
$repository->persist($foo);
// removing
$repository->remove($foo);
<?php
// sorting foos
$youngToOldFoos = $foos->sort(new MethodSorter('getBirthday'));
Append the lib to your requirements key in your composer.json.
{
// composer.json
// [..]
require: {
// append this line to your requirements
"koine/repository": "*"
}
}
- Learn composer. You should not be looking for an alternative install. It is worth the time. Trust me ;-)
- Follow this set of instructions
Here is the issue tracker.