Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 94e3772

Browse files
committed
Merge branch '2.14.x' into 3.0.x
* 2.14.x: Deprecate EntityManager::create() (doctrine#9961) Address deprecation of SchemaDiff::toSaveSql() Address deprecation of SchemaDiff::toSql() Use error style for notifications Fix calls to AbstractSchemaManager::createSchema() (doctrine#10165) Fix build with DBAL 3.5 (doctrine#10163) Adjust comments (doctrine#10160) Deprecate methods related to the annotation driver Use correct link Deprecate annotations Remove trailing whitespace Migrate more documentation towards attributes Remove wrong sentence Do not export phpstan stuff (doctrine#10154)
2 parents 8efcaf9 + cf91ce6 commit 94e3772

63 files changed

Lines changed: 1418 additions & 289 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,8 @@ phpcs.xml.dist export-ignore
1616
phpbench.json export-ignore
1717
phpstan.neon export-ignore
1818
phpstan-baseline.neon export-ignore
19+
phpstan-dbal2.neon export-ignore
20+
phpstan-params.neon export-ignore
21+
phpstan-persistence2.neon export-ignore
1922
psalm.xml export-ignore
2023
psalm-baseline.xml export-ignore

UPGRADE.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,11 +494,24 @@ Use `toIterable()` instead.
494494

495495
# Upgrade to 2.14
496496

497+
## Deprecated incomplete schema updates
498+
499+
Using `orm:schema-tool:update` without passing the `--complete` flag is
500+
deprecated. Use schema asset filtering if you need to preserve assets not
501+
managed by DBAL.
502+
503+
Likewise, calling `SchemaTool::updateSchema()` or
504+
`SchemaTool::getUpdateSchemaSql()` with a second argument is deprecated.
505+
497506
## Deprecated annotation mapping driver.
498507

499508
Please switch to one of the other mapping drivers. Native attributes which PHP
500509
supports since version 8.0 are probably your best option.
501510

511+
As a consequence, the following methods are deprecated:
512+
- `ORMSetup::createAnnotationMetadataConfiguration`
513+
- `ORMSetup::createDefaultAnnotationDriver`
514+
502515
## Deprecated `Doctrine\ORM\Proxy\Proxy` interface.
503516

504517
Use `Doctrine\Persistence\Proxy` instead to check whether proxies are initialized.
@@ -517,6 +530,13 @@ It will be removed in 3.0. Use one of the dedicated event classes instead:
517530

518531
# Upgrade to 2.13
519532

533+
## Deprecated `EntityManager::create()`
534+
535+
The constructor of `EntityManager` is now public and should be used instead of the `create()` method.
536+
However, the constructor expects a `Connection` while `create()` accepted an array with connection parameters.
537+
You can pass that array to DBAL's `Doctrine\DBAL\DriverManager::getConnection()` method to bootstrap the
538+
connection.
539+
520540
## Deprecated `QueryBuilder` methods and constants.
521541

522542
1. The `QueryBuilder::getState()` method has been deprecated as the builder state is an internal concern.

docs/en/cookbook/advanced-field-value-conversion-using-custom-mapping-types.rst

Lines changed: 21 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -32,59 +32,39 @@ The entity class:
3232
3333
namespace Geo\Entity;
3434
35-
/**
36-
* @Entity
37-
*/
35+
use Geo\ValueObject\Point;
36+
37+
#[Entity]
3838
class Location
3939
{
40-
/**
41-
* @Column(type="point")
42-
*
43-
* @var \Geo\ValueObject\Point
44-
*/
45-
private $point;
46-
47-
/**
48-
* @Column(type="string")
49-
*
50-
* @var string
51-
*/
52-
private $address;
53-
54-
/**
55-
* @param \Geo\ValueObject\Point $point
56-
*/
57-
public function setPoint(\Geo\ValueObject\Point $point)
40+
#[Column(type: 'point')]
41+
private Point $point;
42+
43+
#[Column]
44+
private string $address;
45+
46+
public function setPoint(Point $point): void
5847
{
5948
$this->point = $point;
6049
}
6150
62-
/**
63-
* @return \Geo\ValueObject\Point
64-
*/
65-
public function getPoint()
51+
public function getPoint(): Point
6652
{
6753
return $this->point;
6854
}
6955
70-
/**
71-
* @param string $address
72-
*/
73-
public function setAddress($address)
56+
public function setAddress(string $address): void
7457
{
7558
$this->address = $address;
7659
}
7760
78-
/**
79-
* @return string
80-
*/
81-
public function getAddress()
61+
public function getAddress(): string
8262
{
8363
return $this->address;
8464
}
8565
}
8666
87-
We use the custom type ``point`` in the ``@Column`` docblock annotation of the
67+
We use the custom type ``point`` in the ``#[Column]`` attribute of the
8868
``$point`` field. We will create this custom mapping type in the next chapter.
8969

9070
The point class:
@@ -97,29 +77,18 @@ The point class:
9777
9878
class Point
9979
{
100-
101-
/**
102-
* @param float $latitude
103-
* @param float $longitude
104-
*/
105-
public function __construct($latitude, $longitude)
106-
{
107-
$this->latitude = $latitude;
108-
$this->longitude = $longitude;
80+
public function __construct(
81+
private float $latitude,
82+
private float $longitude,
83+
) {
10984
}
11085
111-
/**
112-
* @return float
113-
*/
114-
public function getLatitude()
86+
public function getLatitude(): float
11587
{
11688
return $this->latitude;
11789
}
11890
119-
/**
120-
* @return float
121-
*/
122-
public function getLongitude()
91+
public function getLongitude(): float
12392
{
12493
return $this->longitude;
12594
}
@@ -222,7 +191,7 @@ Example usage
222191
<?php
223192
224193
// Bootstrapping stuff...
225-
// $em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config);
194+
// $em = new \Doctrine\ORM\EntityManager($connection, $config);
226195
227196
// Setup custom mapping type
228197
use Doctrine\DBAL\Types\Type;

docs/en/cookbook/dql-user-defined-functions.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ configuration:
4646
$config->addCustomNumericFunction($name, $class);
4747
$config->addCustomDatetimeFunction($name, $class);
4848
49-
$em = EntityManager::create($dbParams, $config);
49+
$em = new EntityManager($connection, $config);
5050
5151
The ``$name`` is the name the function will be referred to in the
5252
DQL query. ``$class`` is a string of a class-name which has to
@@ -247,5 +247,3 @@ vendor sql functions and extend the DQL languages scope.
247247
Code for this Extension to DQL and other Doctrine Extensions can be
248248
found
249249
`in the GitHub DoctrineExtensions repository <https://github.com/beberlei/DoctrineExtensions>`_.
250-
251-

docs/en/cookbook/implementing-the-notify-changetracking-policy.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ implement the ``NotifyPropertyChanged`` interface from the
2929
<?php
3030
use Doctrine\Persistence\NotifyPropertyChanged;
3131
use Doctrine\Persistence\PropertyChangedListener;
32-
32+
3333
abstract class DomainObject implements NotifyPropertyChanged
3434
{
3535
private $listeners = array();
36-
36+
3737
public function addPropertyChangedListener(PropertyChangedListener $listener) {
3838
$this->listeners[] = $listener;
3939
}
40-
40+
4141
/** Notifies listeners of a change. */
4242
protected function onPropertyChanged($propName, $oldValue, $newValue) {
4343
if ($this->listeners) {
@@ -55,12 +55,12 @@ listeners:
5555
.. code-block:: php
5656
5757
<?php
58-
// Mapping not shown, either in annotations or xml as usual
58+
// Mapping not shown, either in attributes, annotations or xml as usual
5959
class MyEntity extends DomainObject
6060
{
6161
private $data;
6262
// ... other fields as usual
63-
63+
6464
public function setData($data) {
6565
if ($data != $this->data) { // check: is it actually modified?
6666
$this->onPropertyChanged('data', $this->data, $data);

docs/en/cookbook/resolve-target-entity-listener.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ the targetEntity resolution will occur reliably:
127127
// Add the ResolveTargetEntityListener
128128
$evm->addEventListener(Doctrine\ORM\Events::loadClassMetadata, $rtel);
129129
130-
$em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config, $evm);
130+
$connection = \Doctrine\DBAL\DriverManager::createConnection($connectionOptions, $config, $evm);
131+
$em = new \Doctrine\ORM\EntityManager($connection, $config, $evm);
131132
132133
Final Thoughts
133134
--------------
@@ -136,5 +137,3 @@ With the ``ResolveTargetEntityListener``, we are able to decouple our
136137
bundles, keeping them usable by themselves, but still being able to
137138
define relationships between different objects. By using this method,
138139
I've found my bundles end up being easier to maintain independently.
139-
140-

docs/en/cookbook/sql-table-prefixes.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,4 @@ before the prefix has been set.
8181
$tablePrefix = new \DoctrineExtensions\TablePrefix('prefix_');
8282
$evm->addEventListener(\Doctrine\ORM\Events::loadClassMetadata, $tablePrefix);
8383
84-
$em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config, $evm);
85-
86-
84+
$em = new \Doctrine\ORM\EntityManager($connection, $config, $evm);

docs/en/cookbook/strategy-cookbook-introduction.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ As you can see, we have a method "setBlockEntity" which ties a potential strateg
154154
* This var contains the classname of the strategy
155155
* that is used for this blockitem. (This string (!) value will be persisted by Doctrine ORM)
156156
*
157-
* This is a doctrine field, so make sure that you use an @column annotation or setup your
158-
* xml files correctly
157+
* This is a doctrine field, so make sure that you use a
158+
#[Column] attribute or setup your xml files correctly
159159
* @var string
160160
*/
161161
protected $strategyClassName;

docs/en/cookbook/validation-of-entities.rst

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ are allowed to:
3636
public function assertCustomerAllowedBuying()
3737
{
3838
$orderLimit = $this->customer->getOrderLimit();
39-
39+
4040
$amount = 0;
4141
foreach ($this->orderLines as $line) {
4242
$amount += $line->getAmount();
4343
}
44-
44+
4545
if ($amount > $orderLimit) {
4646
throw new CustomerOrderLimitExceededException();
4747
}
@@ -53,7 +53,21 @@ code, enforcing it at any time is important so that customers with
5353
a unknown reputation don't owe your business too much money.
5454

5555
We can enforce this constraint in any of the metadata drivers.
56-
First Annotations:
56+
First Attributes:
57+
58+
.. code-block:: php
59+
60+
<?php
61+
62+
#[Entity]
63+
#[HasLifecycleCallbacks]
64+
class Order
65+
{
66+
#[PrePersist, PreUpdate]
67+
public function assertCustomerAllowedBuying() {}
68+
}
69+
70+
As Annotations:
5771

5872
.. code-block:: php
5973
@@ -98,19 +112,17 @@ validation callbacks.
98112
<?php
99113
class Order
100114
{
101-
/**
102-
* @PrePersist @PreUpdate
103-
*/
115+
#[PrePersist, PreUpdate]
104116
public function validate()
105117
{
106118
if (!($this->plannedShipDate instanceof DateTime)) {
107119
throw new ValidateException();
108120
}
109-
121+
110122
if ($this->plannedShipDate->format('U') < time()) {
111123
throw new ValidateException();
112124
}
113-
125+
114126
if ($this->customer == null) {
115127
throw new OrderRequiresCustomerException();
116128
}

0 commit comments

Comments
 (0)