Completed
Push — master ( e41910...8b07f6 )
by Zach
02:33
created

PathHelpers::getAppPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Yarak\Config;
4
5
use Yarak\Helpers\Str;
6
7
trait PathHelpers
8
{
9
    /**
10
     * Get a value from the config array.
11
     *
12
     * @param string|array $value
13
     *
14
     * @return mixed
15
     */
16
    abstract public function get($value);
17
18
    /**
19
     * Return true if config array has given value.
20
     *
21
     * @param mixed $value
22
     *
23
     * @return bool
24
     */
25
    abstract public function has($value);
26
27
    /**
28
     * Return the app path.
29
     *
30
     * @return string
31
     */
32
    public function getAppPath()
33
    {
34
        return Str::append($this->get(['application', 'appDir']), '/');
35
    }
36
37
    /**
38
     * Return the database directory path.
39
     *
40
     * @return string
41
     */
42
    public function getDatabaseDirectory()
43
    {
44
        return Str::append($this->get(['application', 'databaseDir']), '/');
45
    }
46
47
    /**
48
     * Return the migration directory path.
49
     *
50
     * @param string $path
51
     *
52
     * @return string
53
     */
54
    public function getMigrationDirectory($path = '')
55
    {
56
        return $this->getDatabaseDirectory().'migrations/'.$path;
57
    }
58
59
    /**
60
     * Return the factory directory path.
61
     *
62
     * @param string $path
63
     *
64
     * @return string
65
     */
66
    public function getFactoryDirectory($path = '')
67
    {
68
        return $this->getDatabaseDirectory().'factories/'.$path;
69
    }
70
71
    /**
72
     * Return the seeds directory path.
73
     *
74
     * @param string $path
75
     *
76
     * @return string
77
     */
78
    public function getSeedDirectory($path = '')
79
    {
80
        return $this->getDatabaseDirectory().'seeds/'.$path;
81
    }
82
83
    /**
84
     * Make database directory structure if it doesn't exist.
85
     */
86
    public function getAllDatabaseDirectories()
87
    {
88
        return [
89
            'database'   => $this->getDatabaseDirectory(),
90
            'migrations' => $this->getMigrationDirectory(),
91
            'factories'  => $this->getFactoryDirectory(),
92
            'seeds'      => $this->getSeedDirectory(),
93
        ];
94
    }
95
96
    /**
97
     * Get the console directory path.
98
     *
99
     * @param string $path
100
     *
101
     * @return string
102
     */
103
    public function getConsoleDirectory($path = '')
104
    {
105
        if (!$this->has(['application', 'consoleDir'])) {
106
            return;
107
        }
108
109
        return Str::append(
110
            $this->get(['application', 'consoleDir']),
111
            '/'
112
        ).$path;
113
    }
114
115
    /**
116
     * Get the commands directory path.
117
     *
118
     * @param string $path
119
     *
120
     * @return string
121
     */
122
    public function getCommandsDirectory($path = '')
123
    {
124
        return Str::append(
125
            $this->get(['application', 'consoleDir']),
126
            '/'
127
        ).'commands/'.$path;
128
    }
129
}
130