cekurte/resource-manager

A library to manage resources

v0.0.5 2016-04-29 16:25 UTC

This package is auto-updated.

Last update: 2024-04-16 02:00:39 UTC


README

Build Status Code Climate Coverage Status Latest Stable Version License SensioLabsInsight

  • 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

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

  1. Give me a star =)
  2. Fork it
  3. Create your feature branch (git checkout -b my-new-feature)
  4. Make your changes
  5. Run the tests, adding new ones for your own code if necessary (vendor/bin/phpunit)
  6. Commit your changes (git commit -am 'Added some feature')
  7. Push to the branch (git push origin my-new-feature)
  8. Create new Pull Request