| 148 |
lars |
1 |
Introduction
|
|
|
2 |
============
|
|
|
3 |
|
|
|
4 |
This library provides a way of avoiding usage of constructors when instantiating PHP classes.
|
|
|
5 |
|
|
|
6 |
Installation
|
|
|
7 |
============
|
|
|
8 |
|
|
|
9 |
The suggested installation method is via `composer`_:
|
|
|
10 |
|
|
|
11 |
.. code-block:: console
|
|
|
12 |
|
|
|
13 |
$ composer require doctrine/instantiator
|
|
|
14 |
|
|
|
15 |
Usage
|
|
|
16 |
=====
|
|
|
17 |
|
|
|
18 |
The instantiator is able to create new instances of any class without
|
|
|
19 |
using the constructor or any API of the class itself:
|
|
|
20 |
|
|
|
21 |
.. code-block:: php
|
|
|
22 |
|
|
|
23 |
<?php
|
|
|
24 |
|
|
|
25 |
use Doctrine\Instantiator\Instantiator;
|
|
|
26 |
use App\Entities\User;
|
|
|
27 |
|
|
|
28 |
$instantiator = new Instantiator();
|
|
|
29 |
|
|
|
30 |
$user = $instantiator->instantiate(User::class);
|
|
|
31 |
|
|
|
32 |
Contributing
|
|
|
33 |
============
|
|
|
34 |
|
|
|
35 |
- Follow the `Doctrine Coding Standard`_
|
|
|
36 |
- The project will follow strict `object calisthenics`_
|
|
|
37 |
- Any contribution must provide tests for additional introduced
|
|
|
38 |
conditions
|
|
|
39 |
- Any un-confirmed issue needs a failing test case before being
|
|
|
40 |
accepted
|
|
|
41 |
- Pull requests must be sent from a new hotfix/feature branch, not from
|
|
|
42 |
``master``.
|
|
|
43 |
|
|
|
44 |
Testing
|
|
|
45 |
=======
|
|
|
46 |
|
|
|
47 |
The PHPUnit version to be used is the one installed as a dev- dependency
|
|
|
48 |
via composer:
|
|
|
49 |
|
|
|
50 |
.. code-block:: console
|
|
|
51 |
|
|
|
52 |
$ ./vendor/bin/phpunit
|
|
|
53 |
|
|
|
54 |
Accepted coverage for new contributions is 80%. Any contribution not
|
|
|
55 |
satisfying this requirement won’t be merged.
|
|
|
56 |
|
|
|
57 |
Credits
|
|
|
58 |
=======
|
|
|
59 |
|
|
|
60 |
This library was migrated from `ocramius/instantiator`_, which has been
|
|
|
61 |
donated to the doctrine organization, and which is now deprecated in
|
|
|
62 |
favour of this package.
|
|
|
63 |
|
|
|
64 |
.. _composer: https://getcomposer.org/
|
|
|
65 |
.. _CONTRIBUTING.md: CONTRIBUTING.md
|
|
|
66 |
.. _ocramius/instantiator: https://github.com/Ocramius/Instantiator
|
|
|
67 |
.. _Doctrine Coding Standard: https://github.com/doctrine/coding-standard
|
|
|
68 |
.. _object calisthenics: http://www.slideshare.net/guilhermeblanco/object-calisthenics-applied-to-php
|