- A Resource Manager to PHP (with all methods covered by php unit tests), with this library you can perform queries and manage resources using a unique interface. Now, you can increase the power of your resources, contribute with this project!.
If you liked of this library, give me a star =).
- The package is available on Packagist.
- The source files is PSR-2 compatible.
- Autoloading is PSR-4 compatible.
- RequestParser is PSR-7 compatible.
composer require cekurte/resource-manager
Currently is available one ResourceManager implementation that can be used with the Doctrine ORM.
So, to use this library you must create your entity class and implement the ResourceInterface:
<?php
namespace YourNamespace;
use Cekurte\ResourceManager\Contract\ResourceInterface;
class YourEntity implements ResourceInterface
{
// ...
}
After that, you must retrieve an instance of ResourceManagerInterface:
<?php
use Cekurte\ResourceManager\Driver\DoctrineDriver;
use Cekurte\ResourceManager\ResourceManager;
use Cekurte\ResourceManager\Service\DoctrineResourceManager;
$resourceManager = ResourceManager::create('doctrine', [
'em' => $entityManager,
'entity' => 'YourNamespace\YourEntity',
]);
// OR ...
$resourceManager = ResourceManager::create(new DoctrineDriver([
'em' => $entityManager,
'entity' => 'YourNamespace\YourEntity',
]));
// OR ...
$resourceManager = new DoctrineResourceManager(new DoctrineDriver([
'em' => $entityManager,
'entity' => 'YourNamespace\YourEntity',
]));
To retrieve the resources you must call the method findResources
passing as argument an implementation of ExprQueue. This method will return an array of resources.
<?php
use Cekurte\Resource\Query\Language\ExprQueue;
use Cekurte\Resource\Query\Language\Expr\EqExpr;
// ...
$queue = new ExprQueue();
$queue->enqueue(new EqExpr('alias.field', 'value'));
$resources = $resourceManager->findResources($queue);
// You can call this method without any expression
// to retrive all resources...
// $resources = $resourceManager->findResources();
To retrieve one resource you must call the method findResource
passing as argument an implementation of ExprQueue. This method will throw an exception if the resource can not be found.
<?php
use Cekurte\Resource\Query\Language\ExprQueue;
use Cekurte\Resource\Query\Language\Expr\EqExpr;
use Cekurte\ResourceManager\Exception\ResourceDataNotFoundException;
// ...
$queue = new ExprQueue();
$queue->enqueue(new EqExpr('alias.field', 'value'));
try {
$resource = $resourceManager->findResource($queue);
} catch (ResourceDataNotFoundException $e) {
// ...
}
To create one resource you must call the method writeResource
passing as argument an implementation of ResourceInterface.
<?php
use Cekurte\ResourceManager\Exception\ResourceManagerRefusedWriteException;
// ...
try {
$resourceManager->writeResource($resource);
} catch (ResourceManagerRefusedWriteException $e) {
// ...
}
To update one resource you must call the method updateResource
passing as argument an implementation of ResourceInterface.
<?php
use Cekurte\ResourceManager\Exception\ResourceManagerRefusedUpdateException;
// ...
try {
$resourceManager->updateResource($resource);
} catch (ResourceManagerRefusedUpdateException $e) {
// ...
}
To remove one resource you must call the method deleteResource
passing as argument an implementation of ResourceInterface.
<?php
use Cekurte\ResourceManager\Exception\ResourceManagerRefusedDeleteException;
// ...
try {
$resourceManager->deleteResource($resource);
} catch (ResourceManagerRefusedDeleteException $e) {
// ...
}
If you liked of this library, give me a star =).
- Give me a star =)
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Make your changes
- Run the tests, adding new ones for your own code if necessary (
vendor/bin/phpunit
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request