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
|
|
|
* <https://github.com/baleen/migrations>. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace Baleen\Migrations\Repository; |
21
|
|
|
|
22
|
|
|
use Baleen\Migrations\Exception\RepositoryException; |
23
|
|
|
use Baleen\Migrations\Migration\Factory\FactoryInterface; |
24
|
|
|
use Baleen\Migrations\Migration\Factory\SimpleFactory; |
25
|
|
|
use Baleen\Migrations\Version\Collection\Linked; |
26
|
|
|
use Baleen\Migrations\Version\Comparator\ComparatorInterface; |
27
|
|
|
use Baleen\Migrations\Version\Comparator\IdComparator; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Class AbstractRepository. |
31
|
|
|
* |
32
|
|
|
* @author Gabriel Somoza <[email protected]> |
33
|
|
|
*/ |
34
|
|
|
abstract class AbstractRepository implements RepositoryInterface |
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* @var FactoryInterface |
38
|
|
|
*/ |
39
|
|
|
private $factory = null; |
40
|
|
|
|
41
|
|
|
/** @var ComparatorInterface */ |
42
|
|
|
private $comparator = null; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* AbstractRepository constructor |
46
|
|
|
* |
47
|
|
|
* @param FactoryInterface $factory |
|
|
|
|
48
|
|
|
* @param ComparatorInterface $comparator |
|
|
|
|
49
|
|
|
*/ |
50
|
11 |
|
public function __construct(FactoryInterface $factory = null, ComparatorInterface $comparator = null) |
51
|
|
|
{ |
52
|
11 |
|
if (null === $factory) { |
53
|
9 |
|
$factory = new SimpleFactory(); |
54
|
9 |
|
} |
55
|
11 |
|
$this->factory = $factory; |
56
|
|
|
|
57
|
11 |
|
if (null === $comparator) { |
58
|
10 |
|
$comparator = new IdComparator(); |
59
|
10 |
|
} |
60
|
11 |
|
$this->comparator = $comparator; |
61
|
11 |
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return ComparatorInterface |
65
|
|
|
*/ |
66
|
5 |
|
final private function getComparator() |
67
|
|
|
{ |
68
|
5 |
|
return $this->comparator; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Returns the migration factory. Creates a new SimpleFactory object for it if none was configured. |
73
|
|
|
* |
74
|
|
|
* @return FactoryInterface |
75
|
|
|
*/ |
76
|
10 |
|
final protected function getMigrationFactory() |
77
|
|
|
{ |
78
|
10 |
|
return $this->factory; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @inheritdoc |
83
|
|
|
*/ |
84
|
7 |
|
final public function fetchAll() |
85
|
|
|
{ |
86
|
7 |
|
$collection = $this->doFetchAll(); |
87
|
7 |
|
if (!$collection instanceof Linked) { |
88
|
|
|
RepositoryException::throwInvalidObjectException($collection, Linked::class); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
return $collection->sort($this->getComparator()); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Must fetch all versions available to the repository, load them with their migrations, and return them as a |
96
|
|
|
* Linked collection. It must use a factory (default or supplied by 'setMigrationFactory()') to instantiate |
97
|
|
|
* each of the migrations. |
98
|
|
|
* |
99
|
|
|
* @return Linked |
100
|
|
|
*/ |
101
|
|
|
abstract protected function doFetchAll(); |
102
|
|
|
} |
103
|
|
|
|
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.