cekurte / resource-manager
A library to manage resources
Requires
- php: >=5.5
- cekurte/rql: ^0.0
- doctrine/orm: ^2.5
Requires (Dev)
- cekurte/tdd: ^1.0
- phpunit/phpunit: ^4.8
- sensiolabs/security-checker: ^3.0
- sjparkinson/static-review: ^5.1
- squizlabs/php_codesniffer: ^2.3
This package is auto-updated.
Last update: 2024-12-16 03:33:56 UTC
README
- 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 =).
Installation
- 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
Documentation
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', ]));
Getting resources
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();
Getting one resource
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) { // ... }
Creating a resource
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) { // ... }
Updating a resource
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) { // ... }
Removing a resource
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 =).
Contributing
- 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