dev-master
9999999-dev https://github.com/zeliard91/DynamoDBConnectorBundleSymfony 2 DynamoDB connexion service designed to work with cpliakas/dynamo-db-odm
MIT
The Requires
sf2 connector dynamodb zeliard91
Symfony 2 DynamoDB connexion service designed to work with cpliakas/dynamo-db-odm
This bundle provides a symfony 2 service to interact with cpliakas/dynamo-db-odm., (*1)
Installation is a quick 3 step process:, (*2)
Add Zeliard91DynamoDBConnectorBundle in your composer.json:, (*3)
{ "require": { "zeliard91/dynamodb-connector-bundle": "dev-master" } }
Now tell composer to download the bundle by running the command:, (*4)
``` bash $ php composer.phar update zeliard91/dynamodb-connector-bundle, (*5)
Composer will install the bundle to your project's `vendor/zeliard91/dynamodb-connector-bundle` directory. ### Step 2: Enable the bundle Enable the bundle in the kernel: ``` php <?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Zeliard91\Bundle\DynamoDBConnectorBundle\Zeliard91DynamoDBConnectorBundle(), ); }
``` yaml, (*6)
zeliard91_dynamo_db_connector: # get the values from parameters.yml key: "%dynamodb_key%" secret: "%dynamodb_secret%" region: "eu-west-1" # optional : for dev, you can specify base url base_url: "%dynamodb_url%" # optional : location of your entities entity_namespaces: - Foo\BarBundle\Entity, (*7)
## Usage ### Access to service objects You can get DynamoDB client and document manager in your application by calling the service. ``` php <?php $document_manager = $this->get('zeliard91_dynamo_db_connector')->getManager(); $dynamo_client = $this->get('zeliard91_dynamo_db_connector')->getDynamoDb(); $schema_manager = $this->get('zeliard91_dynamo_db_connector')->getSchemaManager();
If you have register entity namespace, you can also create repositories classes in order to define queries., (*8)
Let's assume you have created the entity Foo\BarBundle\Entity\Book.php
, (*9)
Now define the repository class, it has to be in the same directory and must end by 'Repository' :, (*10)
``` php <?php // Foo/BarBundle/Entity/BookRepository.php, (*11)
namespace Foo\BarBundle\Entity;, (*12)
use Zeliard91\Bundle\DynamoDBConnectorBundle\Repository\DefaultRepository as Repository; use Cpliakas\DynamoDb\ODM\Conditions; use Aws\DynamoDb\Enum\ComparisonOperator;, (*13)
class BookRepository extends Repository { /** * Find all books from an author * @param string $author * @return array */ public function findByAuthor($author) { $conditions = Conditions::factory() ->addCondition('author', $author, ComparisonOperator::EQ) ; return $this->scan($conditions); } }, (*14)
You can now call the method in your controller : ``` php <?php $book_repository = $this->get('zeliard91_dynamo_db_connector')->getRepository('Book'); $books = $book_repository->findByAuthor($author); // Here are some methods from the extended DefaultRepository $book = $book_repository->find($id); $book = $book_repository->find($id, $range); // if you have defined a range attribute $books = $book_repository->findAll();
By using this object, you can create, check or delete the table linked to your entity, (*15)
``` php <?php, (*16)
$schema_manager = $this->get('zeliard91_dynamo_db_connector')->getSchemaManager();, (*17)
$schema_manager->isTableExists('Book'); // returns true or false $schema_manager->createTable('Book'); // throws exception if table already exists $schema_manager->deleteTable('Book'); // throws exception if table does not exist, (*18)
```, (*19)
Symfony 2 DynamoDB connexion service designed to work with cpliakas/dynamo-db-odm
MIT
sf2 connector dynamodb zeliard91