1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
* |
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
16
|
|
|
* and is licensed under the MIT license. For more information, see |
17
|
|
|
* <http://www.doctrine-project.org>. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace Doctrine\ORM\Persisters\Collection; |
21
|
|
|
|
22
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
23
|
|
|
use Doctrine\ORM\UnitOfWork; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Base class for all collection persisters. |
27
|
|
|
* |
28
|
|
|
* @since 2.0 |
29
|
|
|
* @author Roman Borschel <[email protected]> |
30
|
|
|
*/ |
31
|
|
|
abstract class AbstractCollectionPersister implements CollectionPersister |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* @var EntityManagerInterface |
35
|
|
|
*/ |
36
|
|
|
protected $em; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var \Doctrine\DBAL\Connection |
40
|
|
|
*/ |
41
|
|
|
protected $conn; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var UnitOfWork |
45
|
|
|
*/ |
46
|
|
|
protected $uow; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* The database platform. |
50
|
|
|
* |
51
|
|
|
* @var \Doctrine\DBAL\Platforms\AbstractPlatform |
52
|
|
|
*/ |
53
|
|
|
protected $platform; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* The quote strategy. |
57
|
|
|
* |
58
|
|
|
* @var \Doctrine\ORM\Mapping\QuoteStrategy |
59
|
|
|
*/ |
60
|
|
|
protected $quoteStrategy; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Initializes a new instance of a class derived from AbstractCollectionPersister. |
64
|
|
|
* |
65
|
|
|
* @param EntityManagerInterface $em |
66
|
|
|
*/ |
67
|
67 |
|
public function __construct(EntityManagerInterface $em) |
68
|
|
|
{ |
69
|
67 |
|
$this->em = $em; |
70
|
67 |
|
$this->uow = $em->getUnitOfWork(); |
71
|
67 |
|
$this->conn = $em->getConnection(); |
72
|
67 |
|
$this->platform = $this->conn->getDatabasePlatform(); |
73
|
67 |
|
$this->quoteStrategy = $em->getConfiguration()->getQuoteStrategy(); |
74
|
67 |
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Check if entity is in a valid state for operations. |
78
|
|
|
* |
79
|
|
|
* @param object $entity |
80
|
|
|
* |
81
|
|
|
* @return bool |
82
|
|
|
*/ |
83
|
|
|
protected function isValidEntityState($entity) |
84
|
|
|
{ |
85
|
|
|
$entityState = $this->uow->getEntityState($entity, UnitOfWork::STATE_NEW); |
86
|
|
|
|
87
|
|
|
if ($entityState === UnitOfWork::STATE_NEW) { |
88
|
|
|
return false; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
// If Entity is scheduled for inclusion, it is not in this collection. |
92
|
|
|
// We can assure that because it would have return true before on array check |
93
|
|
|
return ! ($entityState === UnitOfWork::STATE_MANAGED && $this->uow->isScheduledForInsert($entity)); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|