|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
5
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
6
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
7
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
8
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
9
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
10
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
11
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
12
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
13
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
14
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
15
|
|
|
* |
|
16
|
|
|
* This software consists of voluntary contributions made by many individuals |
|
17
|
|
|
* and is licensed under the MIT license. For more information, see |
|
18
|
|
|
* <http://www.doctrine-project.org>. |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace Baleen\Cli\Provider; |
|
22
|
|
|
|
|
23
|
|
|
use Baleen\Migrations\Repository\RepositoryInterface; |
|
24
|
|
|
use Baleen\Migrations\Storage\StorageInterface; |
|
25
|
|
|
use Baleen\Migrations\Timeline\TimelineFactory; |
|
26
|
|
|
use Baleen\Migrations\Version\Comparator\ComparatorInterface; |
|
27
|
|
|
use Baleen\Migrations\Version\Comparator\DefaultComparator; |
|
28
|
|
|
use League\Container\ServiceProvider; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Class TimelineProvider. |
|
32
|
|
|
* |
|
33
|
|
|
* @author Gabriel Somoza <[email protected]> |
|
34
|
|
|
*/ |
|
35
|
|
|
class TimelineProvider extends ServiceProvider |
|
36
|
|
|
{ |
|
37
|
|
|
protected $provides = [ |
|
38
|
|
|
Services::TIMELINE, |
|
39
|
|
|
Services::COMPARATOR, |
|
40
|
|
|
]; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @inheritdoc |
|
44
|
|
|
*/ |
|
45
|
|
|
public function register() |
|
46
|
|
|
{ |
|
47
|
|
|
$container = $this->getContainer(); |
|
48
|
|
|
|
|
49
|
|
|
if (!$container->isRegistered(Services::COMPARATOR)) { |
|
50
|
|
|
$container->singleton(Services::COMPARATOR, DefaultComparator::class); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
$container->singleton( |
|
54
|
|
|
Services::TIMELINE, |
|
55
|
|
|
function (RepositoryInterface $repository, StorageInterface $storage, ComparatorInterface $comparator) { |
|
56
|
|
|
$available = $repository->fetchAll(); |
|
57
|
|
|
$migrated = $storage->fetchAll(); |
|
58
|
|
|
$factory = new TimelineFactory($available, $migrated); |
|
59
|
|
|
|
|
60
|
|
|
return $factory->create($comparator); |
|
61
|
|
|
} |
|
62
|
|
|
)->withArguments([ |
|
63
|
|
|
Services::REPOSITORY, |
|
64
|
|
|
Services::STORAGE, |
|
65
|
|
|
DefaultComparator::class, |
|
66
|
|
|
]); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|