Completed
Pull Request — feature/stable-doctrine-module (#518)
by
unknown
23:58 queued 21:46
created

MigrationsCommandFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
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.
17
 */
18
19
namespace DoctrineORMModule\Service;
20
21
use Zend\ServiceManager\FactoryInterface;
22
use Zend\ServiceManager\ServiceLocatorInterface;
23
24
/**
25
 * Service factory for migrations command
26
 *
27
 * @license MIT
28
 * @author Aleksandr Sandrovskiy <[email protected]>
29
 */
30
class MigrationsCommandFactory implements FactoryInterface
31
{
32
    /**
33
     * @var string
34
     */
35
    private $name;
36
37
    /**
38
     * @param $name
39
     */
40
    public function __construct($name)
41
    {
42
        $this->name = ucfirst(strtolower($name));
43
    }
44
45
    /**
46
     * @param \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator
47
     * @return mixed
48
     * @throws \InvalidArgumentException
49
     */
50
    public function createService(ServiceLocatorInterface $serviceLocator)
51
    {
52
        $className = 'Doctrine\DBAL\Migrations\Tools\Console\Command\\' . $this->name . 'Command';
53
54
        if (! class_exists($className)) {
55
            throw new \InvalidArgumentException();
56
        }
57
58
        // @TODO currently hardcoded: `orm_default` should be injected
59
        /* @var $configuration \Doctrine\DBAL\Migrations\Configuration\Configuration */
60
        $configuration = $serviceLocator->get('doctrine.migrations_configuration.orm_default');
61
        /* @var $command \Doctrine\DBAL\Migrations\Tools\Console\Command\AbstractCommand */
62
        $command       = new $className;
63
64
        $command->setMigrationConfiguration($configuration);
65
66
        return $command;
67
    }
68
}
69