Test Failed
Pull Request — master (#20)
by Anton
03:39
created

Application::getModulePath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * @copyright Bluz PHP Team
4
 * @link https://github.com/bluzphp/bluzman
5
 */
6
7
namespace Bluzman\Application;
8
9
use Bluz\Config\Config;
10
use Bluz\Proxy;
11
use Bluzman\Command;
12
use Symfony\Component\Console;
13
use Symfony\Component\Console\Input\InputDefinition;
14
use Symfony\Component\Console\Input\InputOption;
15
use Symfony\Component\Console\Input\InputArgument;
16
17
/**
18
 * @package Bluzman\Application
19
 *
20
 * @author Pavel Machekhin
21
 * @created 2013-11-28 12:31
22
 */
23
class Application extends Console\Application
24
{
25
    /**
26
     * @param string $name
27
     * @param string $version
28
     */
29 14
    public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN')
30
    {
31 14
        parent::__construct($name, $version);
32
33 14
        $this->registerCommands();
34 14
    }
35
36
    /**
37
     * init
38
     *
39
     * @return void
40
     */
41
    public function init()
42
    {
43
        // Init Bluz config
44
        $config = new Config();
45
        $config->setPath(PATH_APPLICATION);
46
        $config->setEnvironment(BLUZ_ENV);
47
        $config->init();
48
49
        Proxy\Config::setInstance($config);
50
    }
51
52
    /**
53
     * Register Bluzman commands
54
     *
55
     * @todo Find a way to do this automatically or move it to /bin/bluzman
56
     */
57 14
    protected function registerCommands()
58
    {
59 14
        $this->addCommands(
60
            [
61 14
                new Command\MagicCommand,
62 14
                new Command\TestCommand,
63 14
                new Command\Db\CreateCommand,
64 14
                new Command\Db\MigrateCommand,
65 14
                new Command\Db\RollbackCommand,
66 14
                new Command\Db\StatusCommand,
67 14
                new Command\Db\SeedCreateCommand,
68
                new Command\Db\SeedRunCommand,
69 14
                new Command\Generate\ModuleCommand,
70 14
                new Command\Generate\ControllerCommand,
71 14
                new Command\Generate\ModelCommand,
72 14
                new Command\Generate\CrudCommand,
73
                new Command\Generate\GridCommand,
74
                new Command\Generate\RestCommand,
75
                new Command\Module\InstallCommand,
76
                new Command\Module\ListCommand,
77
                new Command\Module\RemoveCommand,
78
                new Command\Server\StartCommand,
79
                new Command\Server\StopCommand,
80
                new Command\Server\StatusCommand,
81
            ]
82 14
        );
83
    }
84 14
85
    /**
86 14
     * Returns the path to the directory with bluzman application
87 14
     *
88 14
     * @return string
89 14
     */
90 14
    public function getWorkingPath()
91 14
    {
92 14
        return getcwd();
93 14
    }
94 14
95 14
    /**
96 14
     * Get Module path
97 14
     *
98 14
     * @param  string $name
99 14
     * @return string
100 14
     */
101 14
    public function getModulePath($name)
102 14
    {
103 14
        return $this->getWorkingPath() . DIRECTORY_SEPARATOR
104 14
            . 'application' . DIRECTORY_SEPARATOR
105 14
            . 'modules' . DIRECTORY_SEPARATOR
106
            . $name;
107
    }
108 14
109
    /**
110
     * Get Model path
111
     *
112
     * @param  string $name
113
     * @return string
114
     */
115
    public function getModelPath($name)
116
    {
117
        return $this->getWorkingPath() . DIRECTORY_SEPARATOR
118
            . 'application' . DIRECTORY_SEPARATOR
119
            . 'models' . DIRECTORY_SEPARATOR
120
            . $name;
121
    }
122
123
    /**
124
     * @param  string $name
125
     * @return bool
126 3
     */
127
    public function isModuleExists($name)
128 3
    {
129 3
        return is_dir($this->getModulePath($name));
130 3
    }
131 3
132
    /**
133
     * @param  string $name
134
     * @return bool
135
     */
136
    public function isModelExists($name)
137
    {
138
        return is_dir($this->getModelPath($name));
139
    }
140
}
141