Skip to content
This repository was archived by the owner on Oct 3, 2021. It is now read-only.

Commit 1680f35

Browse files
author
Dominik Zogg
authored
Merge pull request #2 from chubbyphp/chubbyphp-container
chubbyphp-container
2 parents b5ac9d9 + 86e039c commit 1680f35

20 files changed

+3254
-82
lines changed

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ matrix:
1414
- php: 7.4snapshot
1515
env: dependencies=lowest
1616
- php: 7.4snapshot
17-
allow_failures:
18-
- php: 7.4snapshot
1917

2018
before_script:
2119
- echo "USE mysql;\nUPDATE user SET authentication_string=PASSWORD('root') WHERE user='root';\nFLUSH PRIVILEGES;\n" | mysql -u root

README.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,31 @@ Doctrine database service providers for doctrine dbal and orm.
2626
Through [Composer](http://getcomposer.org) as [chubbyphp/chubbyphp-doctrine-db-service-provider][1].
2727

2828
```sh
29-
composer require chubbyphp/chubbyphp-doctrine-db-service-provider "^1.4"
29+
composer require chubbyphp/chubbyphp-doctrine-db-service-provider "^1.5"
3030
```
3131

32-
## Providers
32+
## Usage
3333

34-
* [DoctrineDbalServiceProvider][2]
35-
* [DoctrineOrmServiceProvider][3]
34+
### ServiceFactory (chubbyphp/chubbyphp-container)
35+
36+
* [DoctrineDbalServiceFactory][2]
37+
* [DoctrineOrmServiceFactory][3]
38+
39+
### ServiceProvider (pimple/pimple)
40+
41+
* [DoctrineDbalServiceProvider][4]
42+
* [DoctrineOrmServiceProvider][5]
3643

3744
## Copyright
3845

39-
Dominik Zogg 2018
46+
Dominik Zogg 2019
4047

41-
There is some code with @see, copied with small modifications by from thirdparties.
48+
*There is some code with @see, copied with small modifications by from thirdparties.*
4249

4350
[1]: https://packagist.org/packages/chubbyphp/chubbyphp-doctrine-db-service-provider
4451

45-
[2]: doc/ServiceProvider/DoctrineDbalServiceProvider.md
46-
[3]: doc/ServiceProvider/DoctrineOrmServiceProvider.md
52+
[2]: doc/ServiceFactory/DoctrineDbalServiceFactory.md
53+
[3]: doc/ServiceFactory/DoctrineOrmServiceFactory.md
54+
55+
[4]: doc/ServiceProvider/DoctrineDbalServiceProvider.md
56+
[5]: doc/ServiceProvider/DoctrineOrmServiceProvider.md

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"doctrine/orm": "<2.6.3,>=3.0"
2020
},
2121
"require-dev": {
22+
"chubbyphp/chubbyphp-container": "^1.0",
2223
"chubbyphp/chubbyphp-mock": "^1.4.2",
2324
"doctrine/orm": "^2.6.3",
2425
"friendsofphp/php-cs-fixer": "^2.16.1",
@@ -45,7 +46,7 @@
4546
},
4647
"extra": {
4748
"branch-alias": {
48-
"dev-master": "1.4-dev"
49+
"dev-master": "1.5-dev"
4950
}
5051
},
5152
"scripts": {
@@ -61,8 +62,8 @@
6162
"@test:insights"
6263
],
6364
"test:cs": "mkdir -p build && vendor/bin/php-cs-fixer fix --dry-run --stop-on-violation --cache-file=build/phpcs.cache",
64-
"test:infection": "vendor/bin/infection --threads=$(nproc) --min-msi=87 --verbose --coverage=build/phpunit",
65-
"test:insights": "mkdir -p build && bash -c 'vendor/bin/phpinsights analyse -v --no-interaction --min-quality=92 --disable-security-check | tee build/phpinsights.log; if [ ${PIPESTATUS[0]} -ne \"0\" ]; then exit 1; fi'",
65+
"test:infection": "vendor/bin/infection --threads=$(nproc) --min-msi=86 --verbose --coverage=build/phpunit",
66+
"test:insights": "mkdir -p build && bash -c 'vendor/bin/phpinsights analyse -v --no-interaction --min-quality=94 --disable-security-check | tee build/phpinsights.log; if [ ${PIPESTATUS[0]} -ne \"0\" ]; then exit 1; fi'",
6667
"test:integration": "vendor/bin/phpunit --testsuite=Integration --cache-result-file=build/phpunit/phpunit.result.cache",
6768
"test:lint": "mkdir -p build && find src tests -name '*.php' -print0 | xargs -0 -n1 -P$(nproc) php -l | tee build/phplint.log",
6869
"test:loc": "mkdir -p build && vendor/bin/phploc src --verbose | tee build/phploc.log",
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# DoctrineDbalServiceFactory
2+
3+
The *DoctrineDbalServiceFactory* provides integration with the [Doctrine Dbal][1].
4+
5+
## Parameters
6+
7+
* **doctrine.dbal.db.options**: Array of Doctrine DBAL options.
8+
9+
These options are available:
10+
11+
* **configuration**
12+
13+
* **auto_commit**: Auto commit. Defaults to `true`
14+
* **cache.result**: Array with the cache settings, defaults to `['type' => 'array']`.
15+
Can be any of: `apcu`, `array`. Add additional cache provider factories by adding new service:
16+
`$container['doctrine.dbal.db.cache_factory.<type>']`
17+
* **filter_schema_assets_expression**: An expression to filter for schema (tables)
18+
`deprecated, use schema_assets_filter instead`
19+
* **schema_assets_filter**: An filter callable for schema (tables)
20+
21+
* **connection**:
22+
23+
* **charset**: Specifies the charset used when connecting to the database.
24+
Only relevant for `pdo_mysql`, and `pdo_oci/oci8`,
25+
* **dbname**: The name of the database to connect to.
26+
* **driver**: The database driver to use, defaults to `pdo_mysql`.
27+
Can be any of: `pdo_mysql`, `pdo_sqlite`, `pdo_pgsql`,
28+
`pdo_oci`, `oci8`, `ibm_db2`, `pdo_ibm`, `pdo_sqlsrv`.
29+
* **host**: The host of the database to connect to. Defaults to localhost.
30+
* **password**: The password of the database to connect to.
31+
* **path**: Only relevant for `pdo_sqlite`, specifies the path to the SQLite database.
32+
* **port**: Only relevant for `pdo_mysql`, `pdo_pgsql`, and `pdo_oci/oci8`,
33+
* **user**: The user of the database to connect to. Defaults to root.
34+
35+
These and additional options are described in detail in [Doctrine Dbal Configuration][2].
36+
37+
* **doctrine.dbal.types**: Array of dbal types (additional and/or override)
38+
Example: [Type::STRING => StringType::class]
39+
40+
## Services
41+
42+
* **doctrine.dbal.connection_registry**: The connection registry, instance of `Doctrine\Common\Persistence\ConnectionRegistry`.
43+
* **doctrine.dbal.db**: The database connection, instance of `Doctrine\DBAL\Connection`.
44+
* **doctrine.dbal.db.config**: The doctrine configuration, instance of `Doctrine\DBAL\Configuration`.
45+
* **doctrine.dbal.db.event_manager**: The doctrine event manager, instance of `Doctrine\Common\EventManager`.
46+
47+
## Registering
48+
49+
### Single connection
50+
51+
```php
52+
$container = new Container();
53+
54+
$container->factories((new Chubbyphp\DoctrineDbServiceProvider\ServiceFactory\DoctrineDbalServiceFactory())());
55+
56+
$container->factory('doctrine.dbal.db.options', static function () {
57+
return [
58+
'connection' => [
59+
'dbname' => 'my_database',
60+
'host' => 'mysql.someplace.tld',
61+
'password' => 'my_password',
62+
'user' => 'my_username',
63+
],
64+
];
65+
});
66+
```
67+
68+
### Multiple connections
69+
70+
```php
71+
$container = new Container();
72+
73+
$container->factories((new Chubbyphp\DoctrineDbServiceProvider\ServiceFactory\DoctrineDbalServiceFactory())());
74+
75+
$container->factory('doctrine.dbal.dbs.options', static function () {
76+
return [
77+
'mysql_read' => [
78+
'connection' => [
79+
'dbname' => 'my_database',
80+
'host' => 'mysql.read.someplace.tld',
81+
'password' => 'my_password',
82+
'user' => 'my_username',
83+
],
84+
],
85+
'mysql_write' => [
86+
'connection' => [
87+
'dbname' => 'my_database',
88+
'host' => 'mysql.write.someplace.tld',
89+
'password' => 'my_password',
90+
'user' => 'my_username',
91+
],
92+
],
93+
];
94+
});
95+
```
96+
97+
## Usage
98+
99+
### Single connection
100+
101+
```php
102+
$container->get('doctrine.dbal.db')
103+
->createQueryBuilder()
104+
->select('u')
105+
->from('users', 'u')
106+
->where($qb->expr()->eq('u.username', ':username'))
107+
->setParameter('username', 'john.doe@domain.com')
108+
->execute()
109+
->fetch(\PDO::FETCH_ASSOC);
110+
```
111+
112+
### Multiple connections
113+
114+
```php
115+
$container->get('doctrine.dbal.dbs')->get('name')
116+
->createQueryBuilder()
117+
->select('u')
118+
->from('users', 'u')
119+
->where($qb->expr()->eq('u.username', ':username'))
120+
->setParameter('username', 'john.doe@domain.com')
121+
->execute()
122+
->fetch(\PDO::FETCH_ASSOC);
123+
```
124+
125+
## Copyright
126+
127+
Dominik Zogg <dominik.zogg@gmail.com>
128+
129+
[1]: https://www.doctrine-project.org/projects/dbal
130+
[2]: https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
# DoctrineOrmServiceFactory
2+
3+
The *DoctrineOrmServiceFactory* provides integration with the [Doctrine ORM][1].
4+
5+
## Install
6+
7+
```sh
8+
composer require doctrine/orm "^2.5"
9+
```
10+
11+
## Parameters
12+
13+
* **doctrine.orm.em.options**: Array of Doctrine ORM options.
14+
15+
These options are available:
16+
17+
* **cache.hydration**: Array with the cache settings, defaults to `['type' => 'array']`.
18+
Can be any of: `apcu`, `array`. Add additional cache provider factories by adding new service:
19+
`$container['doctrine.dbal.db.cache_factory.<type>']`
20+
* **cache.metadata**: Array with the cache settings, defaults to `['type' => 'array']`.
21+
Can be any of: `apcu`, `array`. Add additional cache provider factories by adding new service:
22+
`$container['doctrine.dbal.db.cache_factory.<type>']`
23+
* **cache.query**: Array with the cache settings, defaults to `['type' => 'array']`.
24+
Can be any of: `apcu`, `array`. Add additional cache provider factories by adding new service:
25+
`$container['doctrine.dbal.db.cache_factory.<type>']`
26+
* **class_metadata.factory.name**: String with class, defaults to `Doctrine\ORM\Mapping\ClassMetadataFactory`.
27+
* **connection**: The connection name of the Doctrine DBAL configuration. Defaults to `default`.
28+
* **custom.functions.datetime**: Array of datetime related [custom functions][2].
29+
* **custom.functions.numeric**: Array of numeric related [custom functions][2].
30+
* **custom.functions.string**: Array of string related [custom functions][2].
31+
* **custom.hydration_modes**: Array of [hydration modes][3].
32+
* **entity.listener_resolver**: String with the resolver type, defaults to `default`.
33+
Add additional resolvers by adding new service:
34+
`$container['doctrine.orm.entity.listener_resolver.<type>']`.
35+
* **mappings**: Array of Mappings.
36+
* **type**: The mapping driver to use.
37+
Can be any of: `annotation`, `class_map`, `php`, `simple_yaml`, `simple_xml`, `static_php`, `yaml` or `xml`.
38+
Add additional mapping driver factories by adding new service:
39+
`$container['doctrine.orm.mapping_driver.factory.<type>']`
40+
* **namespace**: The entity namespace. Example: `One\Entity`
41+
* **path**: The path to the entities. Example: `/path/to/project/One/Entity`
42+
* **alias**: The entity alias to the namespace. Example: `Alias\Entity`
43+
* **extension**: The file extension to search for mappings. Example: `.dcm.xml`
44+
* **proxies.auto_generate**: Enable or disable the auto generation of proxies. Defaults to `true`.
45+
* **proxies.dir**: The directory where generated proxies get saved. Example: `var/cache/doctrine/orm/proxies`.
46+
* **proxies.namespace**: The namespace of generated proxies. Defaults to `DoctrineProxy`.
47+
* **query_hints**: Array of [query hints][4].
48+
* **repository.default.class**: String with class, defaults to `Doctrine\ORM\EntityRepository`.
49+
* **repository.factory**: String with the repository factory type, defaults to `default`.
50+
Add additional repository factories by adding new service: `$container['doctrine.orm.repository.factory.<type>']`.
51+
* **second_level_cache.enabled**: Enable or disable second level cache, defaults to `false`.
52+
* **second_level_cache**: Array with the cache settings, defaults to `['type' => 'array']`.
53+
Can be any of: `apcu`, `array`. Add additional cache provider factories by adding new service:
54+
`$container['doctrine.dbal.db.cache_factory.<type>']`
55+
* **strategy.naming**: String with the naming strategy type, defaults to `default`.
56+
Add additional naming stratigies by adding new service: `$container['doctrine.orm.strategy.naming.<type>']`.
57+
* **strategy.quote**: String with the quote strategy type, defaults to `default`.
58+
Add additional quote stratigies by adding new service: `$container['doctrine.orm.strategy.quote.<type>']`.
59+
60+
## Services
61+
62+
* **doctrine.orm.em**: The entity manager, instance of `Doctrine\ORM\EntityManager`.
63+
* **doctrine.orm.em.config**: Configuration object for Doctrine. Defaults to an empty `Doctrine\ORM\Configuration`.
64+
* **doctrine.orm.manager_registry**: The manager registry, instance of `Doctrine\Common\Persistence\ManagerRegistry`.
65+
66+
## Registering
67+
68+
### Single connection
69+
70+
```php
71+
$container = new Container();
72+
73+
$container->factories((new Chubbyphp\DoctrineDbServiceProvider\ServiceFactory\DoctrineDbalServiceFactory())());
74+
$container->factories((new Chubbyphp\DoctrineDbServiceProvider\ServiceFactory\DoctrineOrmServiceFactory())());
75+
76+
$container->factory('doctrine.dbal.db.options', static function () {
77+
return [
78+
'connection' => [
79+
'driver' => 'pdo_mysql',
80+
'host' => 'mysql.someplace.tld',
81+
'dbname' => 'my_database',
82+
'user' => 'my_username',
83+
'password' => 'my_password',
84+
'charset' => 'utf8mb4',
85+
],
86+
];
87+
});
88+
89+
$container->factory('doctrine.orm.em.options', static function () {
90+
return [
91+
'mappings' => [
92+
[
93+
'type' => 'annotation',
94+
'namespace' => 'One\Entity',
95+
'path' => __DIR__.'/src/One/Entity',
96+
]
97+
],
98+
];
99+
});
100+
```
101+
102+
### Multiple connections
103+
104+
```php
105+
$container = new Container();
106+
107+
$container->factories((new Chubbyphp\DoctrineDbServiceProvider\ServiceFactory\DoctrineDbalServiceFactory())());
108+
$container->factories((new Chubbyphp\DoctrineDbServiceProvider\ServiceFactory\DoctrineOrmServiceFactory())());
109+
110+
$container->factory('doctrine.dbal.dbs.options', static function () {
111+
return [
112+
'mysql_read' => [
113+
'connection' => [
114+
'driver' => 'pdo_mysql',
115+
'host' => 'mysql_read.someplace.tld',
116+
'dbname' => 'my_database',
117+
'user' => 'my_username',
118+
'password' => 'my_password',
119+
'charset' => 'utf8mb4',
120+
],
121+
],
122+
'mysql_write' => [
123+
'connection' => [
124+
'driver' => 'pdo_mysql',
125+
'host' => 'mysql_write.someplace.tld',
126+
'dbname' => 'my_database',
127+
'user' => 'my_username',
128+
'password' => 'my_password',
129+
'charset' => 'utf8mb4',
130+
],
131+
],
132+
];
133+
});
134+
135+
$container->factory('doctrine.orm.ems.options', static function () {
136+
return [
137+
'mysql_read' => [
138+
'connection' => 'mysql_read',
139+
'mappings' => [
140+
[
141+
'type' => 'annotation',
142+
'namespace' => 'One\Entity',
143+
'alias' => 'One',
144+
'path' => __DIR__.'/src/One/Entity',
145+
'use_simple_annotation_reader' => false,
146+
],
147+
],
148+
],
149+
'mysql_write' => [
150+
'connection' => 'mysql_write',
151+
'mappings' => [
152+
[
153+
'type' => 'annotation',
154+
'namespace' => 'One\Entity',
155+
'path' => __DIR__.'/src/One/Entity',
156+
'use_simple_annotation_reader' => false,
157+
],
158+
],
159+
],
160+
];
161+
});
162+
```
163+
164+
## Usage
165+
166+
### Single connection
167+
168+
```php
169+
$container->get('doctrine.orm.em')
170+
->getRepository(User::class)
171+
->findOneBy(['username' => 'john.doe@domain.com']);
172+
```
173+
174+
### Multiple connections
175+
176+
```php
177+
$container->get('doctrine.orm.ems')->get('name')
178+
->getRepository(User::class)
179+
->findOneBy(['username' => 'john.doe@domain.com']);
180+
```
181+
182+
## Copyright
183+
184+
Dominik Zogg <dominik.zogg@gmail.com>
185+
186+
[1]: https://www.doctrine-project.org/projects/orm
187+
[2]: https://www.doctrine-project.org/projects/doctrine-orm/en/latest/cookbook/dql-user-defined-functions.html
188+
[3]: https://www.doctrine-project.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html#custom-hydration-modes
189+
[4]: https://www.doctrine-project.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html#query-hints
190+

0 commit comments

Comments
 (0)