saxulum / saxulum-doctrine-orm-manager-registry-provider
Saxulum Doctrine ORM Manager Registry Provider
Installs: 729 437
Dependents: 10
Suggesters: 3
Security: 0
Stars: 20
Watchers: 2
Forks: 5
Open Issues: 0
Requires
- php: >=5.3.3,<8.0
- dflydev/doctrine-orm-service-provider: ~2.0
- pimple/pimple: >=2.1,<4
Requires (Dev)
- phpunit/phpunit: ~4.1
- saxulum/saxulum-console: ~3.1
- saxulum/saxulum-doctrine-orm-commands: ~1.2
- silex/api: 2.0.*@dev
- silex/providers: 2.0.*@dev
- symfony/doctrine-bridge: ~2.3|~3.0
- symfony/form: ~2.3|~3.0
- symfony/validator: ~2.3|~3.0
Suggests
- saxulum/saxulum-console: ~3.1
- saxulum/saxulum-doctrine-orm-commands: ~1.2
- symfony/doctrine-bridge: ~2.3|~3.0
- symfony/form: ~2.3|~3.0
- symfony/validator: ~2.3|~3.0
README
Features
- Leverages the core Doctrine Service Provider for either Silex or Cilex and the Doctrine ORM Service Provider
- The Registry manager registry can the used with the Doctrine Bridge from symfony, to use entity type in the Symfony Form Component
Requirements
- PHP 5.3+
- Doctrine ~2.3
- Pimple ~2.1
Currently requires both dbs and orm.ems services in order to work. These can be provided by a Doctrine Service Provider like the Silex or Cilex and the Doctrine ORM Service Provider like the dflydev-doctrine-orm-service-provider service providers. If you can or want to fake it, go for it. :)
Installation
Through Composer as saxulum/saxulum-doctrine-orm-manager-registry-provider.
composer require "saxulum/saxulum-doctrine-orm-manager-registry-provider": "~3.0"
<?php
use Saxulum\DoctrineOrmManagerRegistry\Provider\DoctrineOrmManagerRegistryProvider;
$app->register(new DoctrineOrmManagerRegistryProvider());
Form Entity Type
If you like to have Entity
Type Support within Symfony Form Component, install the Doctrine Bridge and register the form provider first.
{
"require": {
"symfony/doctrine-bridge": "~2.2",
"symfony/form": "~2.2"
}
}
<?php
use Saxulum\DoctrineOrmManagerRegistry\Provider\DoctrineOrmManagerRegistryProvider;
use Silex\Provider\FormServiceProvider;
$app->register(new FormServiceProvider());
$app->register(new DoctrineOrmManagerRegistryProvider());
Validator
If you like to have UniqueEntity
Constraint Support within Symfony Validator Component, install the Doctrine Bridge and register the validator provider first.
{
"require": {
"symfony/doctrine-bridge": "~2.2",
"symfony/validator": "~2.2"
}
}
<?php
use Saxulum\DoctrineOrmManagerRegistry\Provider\DoctrineOrmManagerRegistryProvider;
use Silex\Provider\ValidatorServiceProvider;
$app->register(new ValidatorServiceProvider());
$app->register(new DoctrineOrmManagerRegistryProvider());
<?php
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Mapping\ClassMetadata;
/**
* @ORM\Entity()
* @ORM\Table(name="sample")
*/
class Sample
{
/**
* @var string
* @ORM\Column(name="name", type="string")
*/
protected $name;
/**
* @param ClassMetadata $metadata
*/
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addConstraint(new UniqueEntity(array(
'fields' => 'name',
'message' => 'This name already exists.',
)));
}
}
Doctrine ORM Console
If you like to use Doctrine ORM Commands, install Doctrine ORM Commands and the Saxulum Console Provider and register the console provider.
{
"require": {
"saxulum/saxulum-doctrine-orm-commands": "~1.2,>=1.2.2",
"saxulum/saxulum-console": "~3.1",
}
}
<?php
use Saxulum\DoctrineOrmManagerRegistry\Provider\DoctrineOrmManagerRegistryProvider;
use Saxulum\Console\Silex\Provider\ConsoleProvider;
$app->register(new ConsoleProvider());
$app->register(new DoctrineOrmManagerRegistryProvider());
Usage
<?php
// get the default connection name
$app['doctrine']->getDefaultConnectionName();
// get the default connection
$app['doctrine']->getConnection();
// get a connection by name
$app['doctrine']->getConnection('name');
// all connections as array access (pimple)
$app['doctrine']->getConnections();
// all connection names as array
$app['doctrine']->getConnectionNames();
// get the default manager name
$app['doctrine']->getDefaultManagerName();
// get the default manager
$app['doctrine']->getManager();
// get a manager by name
$app['doctrine']->getManager('name');
// all manager as array access (pimple)
$app['doctrine']->getManagers();
// all manager names as array
$app['doctrine']->getManagerNames();
...