PHP code example of cekurte / resource-manager

1. Go to this page and download the library: Download cekurte/resource-manager library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cekurte / resource-manager example snippets




namespace YourNamespace;

use Cekurte\ResourceManager\Contract\ResourceInterface;

class YourEntity implements ResourceInterface
{
    // ...
}



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',
]));



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();



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) {
    // ...
}



use Cekurte\ResourceManager\Exception\ResourceManagerRefusedWriteException;

// ...

try {
    $resourceManager->writeResource($resource);
} catch (ResourceManagerRefusedWriteException $e) {
    // ...
}



use Cekurte\ResourceManager\Exception\ResourceManagerRefusedUpdateException;

// ...

try {
    $resourceManager->updateResource($resource);
} catch (ResourceManagerRefusedUpdateException $e) {
    // ...
}



use Cekurte\ResourceManager\Exception\ResourceManagerRefusedDeleteException;

// ...

try {
    $resourceManager->deleteResource($resource);
} catch (ResourceManagerRefusedDeleteException $e) {
    // ...
}