1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @year 2016 |
4
|
|
|
* @link https://github.com/nnx-framework/cloner |
5
|
|
|
* @author Lobanov Aleksandr <[email protected]> |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Nnx\Cloner; |
9
|
|
|
|
10
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
11
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class EntityCloner |
15
|
|
|
* |
16
|
|
|
* @package Nnx\Cloner |
17
|
|
|
*/ |
18
|
|
|
class EntityCloner extends Cloner |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var ObjectManager |
22
|
|
|
*/ |
23
|
|
|
private $objectManager; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* EntityCloner constructor. |
27
|
|
|
* |
28
|
|
|
* @param ClonerInterface $clonerManager |
29
|
|
|
* @param Options\ClonerOptions $options |
30
|
|
|
* @param ObjectManager $objectManager |
31
|
|
|
*/ |
32
|
|
|
public function __construct( |
33
|
|
|
ClonerInterface $clonerManager, |
34
|
|
|
Options\ClonerOptions $options, |
35
|
|
|
ObjectManager $objectManager |
|
|
|
|
36
|
|
|
) { |
37
|
|
|
parent::__construct($clonerManager, $options); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param mixed $object |
42
|
|
|
* @param string $relationName |
43
|
|
|
* @param Options\Cloner\RelationOptions $options |
44
|
|
|
* |
45
|
|
|
* @return ArrayCollection|mixed |
46
|
|
|
*/ |
47
|
|
|
protected function handleRelation($object, $relationName, Options\Cloner\RelationOptions $options) |
48
|
|
|
{ |
49
|
|
|
$cloneData = parent::handleRelation($object, $relationName, $options); |
50
|
|
|
if (is_array($cloneData)) { |
51
|
|
|
return new ArrayCollection($cloneData); |
52
|
|
|
} |
53
|
|
|
return $cloneData; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param mixed $object |
58
|
|
|
* @param mixed $cloneObject |
59
|
|
|
*/ |
60
|
|
|
protected function afterClone($object, $cloneObject) |
61
|
|
|
{ |
62
|
|
|
parent::afterClone($object, $cloneObject); |
63
|
|
|
|
64
|
|
|
$this->getObjectManager()->detach($cloneObject); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return ObjectManager |
69
|
|
|
*/ |
70
|
|
|
protected function getObjectManager() |
71
|
|
|
{ |
72
|
|
|
return $this->objectManager; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.