This repository has been archived by the owner on Oct 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from chubbyphp/chubbyphp-container
chubbyphp-container
- Loading branch information
Showing
20 changed files
with
3,254 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
# DoctrineDbalServiceFactory | ||
|
||
The *DoctrineDbalServiceFactory* provides integration with the [Doctrine Dbal][1]. | ||
|
||
## Parameters | ||
|
||
* **doctrine.dbal.db.options**: Array of Doctrine DBAL options. | ||
|
||
These options are available: | ||
|
||
* **configuration** | ||
|
||
* **auto_commit**: Auto commit. Defaults to `true` | ||
* **cache.result**: Array with the cache settings, defaults to `['type' => 'array']`. | ||
Can be any of: `apcu`, `array`. Add additional cache provider factories by adding new service: | ||
`$container['doctrine.dbal.db.cache_factory.<type>']` | ||
* **filter_schema_assets_expression**: An expression to filter for schema (tables) | ||
`deprecated, use schema_assets_filter instead` | ||
* **schema_assets_filter**: An filter callable for schema (tables) | ||
|
||
* **connection**: | ||
|
||
* **charset**: Specifies the charset used when connecting to the database. | ||
Only relevant for `pdo_mysql`, and `pdo_oci/oci8`, | ||
* **dbname**: The name of the database to connect to. | ||
* **driver**: The database driver to use, defaults to `pdo_mysql`. | ||
Can be any of: `pdo_mysql`, `pdo_sqlite`, `pdo_pgsql`, | ||
`pdo_oci`, `oci8`, `ibm_db2`, `pdo_ibm`, `pdo_sqlsrv`. | ||
* **host**: The host of the database to connect to. Defaults to localhost. | ||
* **password**: The password of the database to connect to. | ||
* **path**: Only relevant for `pdo_sqlite`, specifies the path to the SQLite database. | ||
* **port**: Only relevant for `pdo_mysql`, `pdo_pgsql`, and `pdo_oci/oci8`, | ||
* **user**: The user of the database to connect to. Defaults to root. | ||
|
||
These and additional options are described in detail in [Doctrine Dbal Configuration][2]. | ||
|
||
* **doctrine.dbal.types**: Array of dbal types (additional and/or override) | ||
Example: [Type::STRING => StringType::class] | ||
|
||
## Services | ||
|
||
* **doctrine.dbal.connection_registry**: The connection registry, instance of `Doctrine\Common\Persistence\ConnectionRegistry`. | ||
* **doctrine.dbal.db**: The database connection, instance of `Doctrine\DBAL\Connection`. | ||
* **doctrine.dbal.db.config**: The doctrine configuration, instance of `Doctrine\DBAL\Configuration`. | ||
* **doctrine.dbal.db.event_manager**: The doctrine event manager, instance of `Doctrine\Common\EventManager`. | ||
|
||
## Registering | ||
|
||
### Single connection | ||
|
||
```php | ||
$container = new Container(); | ||
|
||
$container->factories((new Chubbyphp\DoctrineDbServiceProvider\ServiceFactory\DoctrineDbalServiceFactory())()); | ||
|
||
$container->factory('doctrine.dbal.db.options', static function () { | ||
return [ | ||
'connection' => [ | ||
'dbname' => 'my_database', | ||
'host' => 'mysql.someplace.tld', | ||
'password' => 'my_password', | ||
'user' => 'my_username', | ||
], | ||
]; | ||
}); | ||
``` | ||
|
||
### Multiple connections | ||
|
||
```php | ||
$container = new Container(); | ||
|
||
$container->factories((new Chubbyphp\DoctrineDbServiceProvider\ServiceFactory\DoctrineDbalServiceFactory())()); | ||
|
||
$container->factory('doctrine.dbal.dbs.options', static function () { | ||
return [ | ||
'mysql_read' => [ | ||
'connection' => [ | ||
'dbname' => 'my_database', | ||
'host' => 'mysql.read.someplace.tld', | ||
'password' => 'my_password', | ||
'user' => 'my_username', | ||
], | ||
], | ||
'mysql_write' => [ | ||
'connection' => [ | ||
'dbname' => 'my_database', | ||
'host' => 'mysql.write.someplace.tld', | ||
'password' => 'my_password', | ||
'user' => 'my_username', | ||
], | ||
], | ||
]; | ||
}); | ||
``` | ||
|
||
## Usage | ||
|
||
### Single connection | ||
|
||
```php | ||
$container->get('doctrine.dbal.db') | ||
->createQueryBuilder() | ||
->select('u') | ||
->from('users', 'u') | ||
->where($qb->expr()->eq('u.username', ':username')) | ||
->setParameter('username', 'john.doe@domain.com') | ||
->execute() | ||
->fetch(\PDO::FETCH_ASSOC); | ||
``` | ||
|
||
### Multiple connections | ||
|
||
```php | ||
$container->get('doctrine.dbal.dbs')->get('name') | ||
->createQueryBuilder() | ||
->select('u') | ||
->from('users', 'u') | ||
->where($qb->expr()->eq('u.username', ':username')) | ||
->setParameter('username', 'john.doe@domain.com') | ||
->execute() | ||
->fetch(\PDO::FETCH_ASSOC); | ||
``` | ||
|
||
## Copyright | ||
|
||
Dominik Zogg <dominik.zogg@gmail.com> | ||
|
||
[1]: https://www.doctrine-project.org/projects/dbal | ||
[2]: https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
# DoctrineOrmServiceFactory | ||
|
||
The *DoctrineOrmServiceFactory* provides integration with the [Doctrine ORM][1]. | ||
|
||
## Install | ||
|
||
```sh | ||
composer require doctrine/orm "^2.5" | ||
``` | ||
|
||
## Parameters | ||
|
||
* **doctrine.orm.em.options**: Array of Doctrine ORM options. | ||
|
||
These options are available: | ||
|
||
* **cache.hydration**: Array with the cache settings, defaults to `['type' => 'array']`. | ||
Can be any of: `apcu`, `array`. Add additional cache provider factories by adding new service: | ||
`$container['doctrine.dbal.db.cache_factory.<type>']` | ||
* **cache.metadata**: Array with the cache settings, defaults to `['type' => 'array']`. | ||
Can be any of: `apcu`, `array`. Add additional cache provider factories by adding new service: | ||
`$container['doctrine.dbal.db.cache_factory.<type>']` | ||
* **cache.query**: Array with the cache settings, defaults to `['type' => 'array']`. | ||
Can be any of: `apcu`, `array`. Add additional cache provider factories by adding new service: | ||
`$container['doctrine.dbal.db.cache_factory.<type>']` | ||
* **class_metadata.factory.name**: String with class, defaults to `Doctrine\ORM\Mapping\ClassMetadataFactory`. | ||
* **connection**: The connection name of the Doctrine DBAL configuration. Defaults to `default`. | ||
* **custom.functions.datetime**: Array of datetime related [custom functions][2]. | ||
* **custom.functions.numeric**: Array of numeric related [custom functions][2]. | ||
* **custom.functions.string**: Array of string related [custom functions][2]. | ||
* **custom.hydration_modes**: Array of [hydration modes][3]. | ||
* **entity.listener_resolver**: String with the resolver type, defaults to `default`. | ||
Add additional resolvers by adding new service: | ||
`$container['doctrine.orm.entity.listener_resolver.<type>']`. | ||
* **mappings**: Array of Mappings. | ||
* **type**: The mapping driver to use. | ||
Can be any of: `annotation`, `class_map`, `php`, `simple_yaml`, `simple_xml`, `static_php`, `yaml` or `xml`. | ||
Add additional mapping driver factories by adding new service: | ||
`$container['doctrine.orm.mapping_driver.factory.<type>']` | ||
* **namespace**: The entity namespace. Example: `One\Entity` | ||
* **path**: The path to the entities. Example: `/path/to/project/One/Entity` | ||
* **alias**: The entity alias to the namespace. Example: `Alias\Entity` | ||
* **extension**: The file extension to search for mappings. Example: `.dcm.xml` | ||
* **proxies.auto_generate**: Enable or disable the auto generation of proxies. Defaults to `true`. | ||
* **proxies.dir**: The directory where generated proxies get saved. Example: `var/cache/doctrine/orm/proxies`. | ||
* **proxies.namespace**: The namespace of generated proxies. Defaults to `DoctrineProxy`. | ||
* **query_hints**: Array of [query hints][4]. | ||
* **repository.default.class**: String with class, defaults to `Doctrine\ORM\EntityRepository`. | ||
* **repository.factory**: String with the repository factory type, defaults to `default`. | ||
Add additional repository factories by adding new service: `$container['doctrine.orm.repository.factory.<type>']`. | ||
* **second_level_cache.enabled**: Enable or disable second level cache, defaults to `false`. | ||
* **second_level_cache**: Array with the cache settings, defaults to `['type' => 'array']`. | ||
Can be any of: `apcu`, `array`. Add additional cache provider factories by adding new service: | ||
`$container['doctrine.dbal.db.cache_factory.<type>']` | ||
* **strategy.naming**: String with the naming strategy type, defaults to `default`. | ||
Add additional naming stratigies by adding new service: `$container['doctrine.orm.strategy.naming.<type>']`. | ||
* **strategy.quote**: String with the quote strategy type, defaults to `default`. | ||
Add additional quote stratigies by adding new service: `$container['doctrine.orm.strategy.quote.<type>']`. | ||
|
||
## Services | ||
|
||
* **doctrine.orm.em**: The entity manager, instance of `Doctrine\ORM\EntityManager`. | ||
* **doctrine.orm.em.config**: Configuration object for Doctrine. Defaults to an empty `Doctrine\ORM\Configuration`. | ||
* **doctrine.orm.manager_registry**: The manager registry, instance of `Doctrine\Common\Persistence\ManagerRegistry`. | ||
|
||
## Registering | ||
|
||
### Single connection | ||
|
||
```php | ||
$container = new Container(); | ||
|
||
$container->factories((new Chubbyphp\DoctrineDbServiceProvider\ServiceFactory\DoctrineDbalServiceFactory())()); | ||
$container->factories((new Chubbyphp\DoctrineDbServiceProvider\ServiceFactory\DoctrineOrmServiceFactory())()); | ||
|
||
$container->factory('doctrine.dbal.db.options', static function () { | ||
return [ | ||
'connection' => [ | ||
'driver' => 'pdo_mysql', | ||
'host' => 'mysql.someplace.tld', | ||
'dbname' => 'my_database', | ||
'user' => 'my_username', | ||
'password' => 'my_password', | ||
'charset' => 'utf8mb4', | ||
], | ||
]; | ||
}); | ||
|
||
$container->factory('doctrine.orm.em.options', static function () { | ||
return [ | ||
'mappings' => [ | ||
[ | ||
'type' => 'annotation', | ||
'namespace' => 'One\Entity', | ||
'path' => __DIR__.'/src/One/Entity', | ||
] | ||
], | ||
]; | ||
}); | ||
``` | ||
|
||
### Multiple connections | ||
|
||
```php | ||
$container = new Container(); | ||
|
||
$container->factories((new Chubbyphp\DoctrineDbServiceProvider\ServiceFactory\DoctrineDbalServiceFactory())()); | ||
$container->factories((new Chubbyphp\DoctrineDbServiceProvider\ServiceFactory\DoctrineOrmServiceFactory())()); | ||
|
||
$container->factory('doctrine.dbal.dbs.options', static function () { | ||
return [ | ||
'mysql_read' => [ | ||
'connection' => [ | ||
'driver' => 'pdo_mysql', | ||
'host' => 'mysql_read.someplace.tld', | ||
'dbname' => 'my_database', | ||
'user' => 'my_username', | ||
'password' => 'my_password', | ||
'charset' => 'utf8mb4', | ||
], | ||
], | ||
'mysql_write' => [ | ||
'connection' => [ | ||
'driver' => 'pdo_mysql', | ||
'host' => 'mysql_write.someplace.tld', | ||
'dbname' => 'my_database', | ||
'user' => 'my_username', | ||
'password' => 'my_password', | ||
'charset' => 'utf8mb4', | ||
], | ||
], | ||
]; | ||
}); | ||
|
||
$container->factory('doctrine.orm.ems.options', static function () { | ||
return [ | ||
'mysql_read' => [ | ||
'connection' => 'mysql_read', | ||
'mappings' => [ | ||
[ | ||
'type' => 'annotation', | ||
'namespace' => 'One\Entity', | ||
'alias' => 'One', | ||
'path' => __DIR__.'/src/One/Entity', | ||
'use_simple_annotation_reader' => false, | ||
], | ||
], | ||
], | ||
'mysql_write' => [ | ||
'connection' => 'mysql_write', | ||
'mappings' => [ | ||
[ | ||
'type' => 'annotation', | ||
'namespace' => 'One\Entity', | ||
'path' => __DIR__.'/src/One/Entity', | ||
'use_simple_annotation_reader' => false, | ||
], | ||
], | ||
], | ||
]; | ||
}); | ||
``` | ||
|
||
## Usage | ||
|
||
### Single connection | ||
|
||
```php | ||
$container->get('doctrine.orm.em') | ||
->getRepository(User::class) | ||
->findOneBy(['username' => 'john.doe@domain.com']); | ||
``` | ||
|
||
### Multiple connections | ||
|
||
```php | ||
$container->get('doctrine.orm.ems')->get('name') | ||
->getRepository(User::class) | ||
->findOneBy(['username' => 'john.doe@domain.com']); | ||
``` | ||
|
||
## Copyright | ||
|
||
Dominik Zogg <dominik.zogg@gmail.com> | ||
|
||
[1]: https://www.doctrine-project.org/projects/orm | ||
[2]: https://www.doctrine-project.org/projects/doctrine-orm/en/latest/cookbook/dql-user-defined-functions.html | ||
[3]: https://www.doctrine-project.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html#custom-hydration-modes | ||
[4]: https://www.doctrine-project.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html#query-hints | ||
|
Oops, something went wrong.