williancarminato/respect-relational-silex-provider

Respect Relational Service Provider to use with Silex microframework

dev-master 2013-09-19 16:37 UTC

This package is not auto-updated.

Last update: 2024-05-21 03:56:08 UTC


README

Provides Respect Relational Mapper to use as services on Silex applications.

Features

  • Awesome Relational database persistence tool, see Respect/Relational
  • Multiple databases connections

Requirements

  • PHP 5.3+
  • Respect/Relational

Instalation

Package available on Composer. Autoloading with composer is PSR-0 compatible.

Usage

To use the provider, register RespectRelationalServiceProvider and specify at least one connection.

<?php 
    use Silex\Application;
    use Carminato\Silex\Provider\Respect\RespectRelationalServiceProvider;

    $app = new Application;
    
    $app->register(new RespectRelationalServiceProvider(), array(
            'respect.pdo.instances' => array(new \PDO('sqlite::memory:'))
        )
    );

The default Mapper will now be accessible with respect.mapper in the app container.

<?php
    $mapper = $app['respect.mapper'];

You can pass as many respect.pdo.instances as you want.

<?php 
    use Silex\Application;
    use Carminato\Silex\Provider\Respect\RespectRelationalServiceProvider;

    $app = new Application;
    
    $app->register(new RespectRelationalServiceProvider(), array(
            'respect.pdo.instances' => array(
                'mymapper1' => new \PDO('sqlite::memory:'),
                'mymapper2' => new \PDO('sqlite::memory:')
            )
        )
    );

And then access each one with his respective array key using the respect.mappers.

<?php
    $mapper1 = $app['respect.mappers']['mymapper1']
    $mapper2 = $app['respect.mappers']['mymapper2']

Enjoy!