|
58
|
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 LGPL. For more information, see |
|
|
17 |
* <http://www.doctrine-project.org>. |
|
|
18 |
*/ |
|
|
19 |
|
|
|
20 |
namespace Doctrine\Common\DataFixtures; |
|
|
21 |
|
|
|
22 |
use Doctrine\Common\DataFixtures\ReferenceRepository; |
|
|
23 |
|
|
|
24 |
/** |
|
|
25 |
* Abstract Fixture class helps to manage references |
|
|
26 |
* between fixture classes in order to set relations |
|
|
27 |
* among other fixtures |
|
|
28 |
* |
|
|
29 |
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com> |
|
|
30 |
*/ |
|
|
31 |
abstract class AbstractFixture implements SharedFixtureInterface |
|
|
32 |
{ |
|
|
33 |
/** |
|
|
34 |
* Fixture reference repository |
|
|
35 |
* |
|
|
36 |
* @var ReferenceRepository |
|
|
37 |
*/ |
|
|
38 |
private $referenceRepository; |
|
|
39 |
|
|
|
40 |
/** |
|
|
41 |
* {@inheritdoc} |
|
|
42 |
*/ |
|
|
43 |
public function setReferenceRepository(ReferenceRepository $referenceRepository) |
|
|
44 |
{ |
|
|
45 |
$this->referenceRepository = $referenceRepository; |
|
|
46 |
} |
|
|
47 |
|
|
|
48 |
/** |
|
|
49 |
* Set the reference entry identified by $name |
|
|
50 |
* and referenced to managed $object. If $name |
|
|
51 |
* already is set, it overrides it |
|
|
52 |
* |
|
|
53 |
* @param string $name |
|
|
54 |
* @param object $object - managed object |
|
|
55 |
* @see Doctrine\Common\DataFixtures\ReferenceRepository::setReference |
|
|
56 |
* @return void |
|
|
57 |
*/ |
|
|
58 |
public function setReference($name, $object) |
|
|
59 |
{ |
|
|
60 |
$this->referenceRepository->setReference($name, $object); |
|
|
61 |
} |
|
|
62 |
|
|
|
63 |
/** |
|
|
64 |
* Set the reference entry identified by $name |
|
|
65 |
* and referenced to managed $object. If $name |
|
|
66 |
* already is set, it overrides it |
|
|
67 |
* |
|
|
68 |
* @param string $name |
|
|
69 |
* @param object $object - managed object |
|
|
70 |
* @see Doctrine\Common\DataFixtures\ReferenceRepository::addReference |
|
|
71 |
* @return void |
|
|
72 |
*/ |
|
|
73 |
public function addReference($name, $object) |
|
|
74 |
{ |
|
|
75 |
$this->referenceRepository->addReference($name, $object); |
|
|
76 |
} |
|
|
77 |
|
|
|
78 |
/** |
|
|
79 |
* Loads an object using stored reference |
|
|
80 |
* named by $name |
|
|
81 |
* |
|
|
82 |
* @param string $name |
|
|
83 |
* @see Doctrine\Common\DataFixtures\ReferenceRepository::getReference |
|
|
84 |
* @return object |
|
|
85 |
*/ |
|
|
86 |
public function getReference($name) |
|
|
87 |
{ |
|
|
88 |
return $this->referenceRepository->getReference($name); |
|
|
89 |
} |
|
|
90 |
|
|
|
91 |
/** |
|
|
92 |
* Check if an object is stored using reference |
|
|
93 |
* named by $name |
|
|
94 |
* |
|
|
95 |
* @param string $name |
|
|
96 |
* @see Doctrine\Common\DataFixtures\ReferenceRepository::hasReference |
|
|
97 |
* @return boolean |
|
|
98 |
*/ |
|
|
99 |
public function hasReference($name) |
|
|
100 |
{ |
|
|
101 |
return $this->referenceRepository->hasReference($name); |
|
|
102 |
} |
|
|
103 |
} |