|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the puli/composer-plugin package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Bernhard Schussek <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Puli\ComposerPlugin; |
|
13
|
|
|
|
|
14
|
|
|
use Webmozart\Assert\Assert; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* A Puli package. |
|
18
|
|
|
* |
|
19
|
|
|
* This class acts as data transfer object (DTO) for results delivered by the |
|
20
|
|
|
* "puli package" command. |
|
21
|
|
|
* |
|
22
|
|
|
* @since 1.0 |
|
23
|
|
|
* |
|
24
|
|
|
* @author Bernhard Schussek <[email protected]> |
|
25
|
|
|
*/ |
|
26
|
|
|
class PuliPackage |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* State: The package is enabled. |
|
30
|
|
|
*/ |
|
31
|
|
|
const STATE_ENABLED = 'enabled'; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* State: The package was not found on the filesystem. |
|
35
|
|
|
*/ |
|
36
|
|
|
const STATE_NOT_FOUND = 'not-found'; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* State: The package could not be loaded. |
|
40
|
|
|
*/ |
|
41
|
|
|
const STATE_NOT_LOADABLE = 'not-loadable'; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Environment: The production environment. |
|
45
|
|
|
*/ |
|
46
|
|
|
const ENV_PROD = 'prod'; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Environment: The development environment. |
|
50
|
|
|
*/ |
|
51
|
|
|
const ENV_DEV = 'dev'; |
|
52
|
|
|
|
|
53
|
|
|
private static $states = array( |
|
54
|
|
|
self::STATE_ENABLED, |
|
55
|
|
|
self::STATE_NOT_FOUND, |
|
56
|
|
|
self::STATE_NOT_LOADABLE, |
|
57
|
|
|
); |
|
58
|
|
|
|
|
59
|
|
|
private static $envs = array( |
|
60
|
|
|
self::ENV_PROD, |
|
61
|
|
|
self::ENV_DEV, |
|
62
|
|
|
); |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @var string |
|
66
|
|
|
*/ |
|
67
|
|
|
private $name; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @var string |
|
71
|
|
|
*/ |
|
72
|
|
|
private $installerName; |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @var string |
|
76
|
|
|
*/ |
|
77
|
|
|
private $installPath; |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @var string |
|
81
|
|
|
*/ |
|
82
|
|
|
private $state; |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @var string |
|
86
|
|
|
*/ |
|
87
|
|
|
private $env; |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Creates a new package DTO. |
|
91
|
|
|
* |
|
92
|
|
|
* @param string $name The package name. |
|
93
|
|
|
* @param string $installerName The name of the installer. |
|
94
|
|
|
* @param string $installPath The absolute install path. |
|
95
|
|
|
* @param string $state One of the STATE_* constants in this class. |
|
96
|
|
|
* @param string $env The environment that the package is |
|
97
|
|
|
* installed in. |
|
98
|
|
|
*/ |
|
99
|
31 |
|
public function __construct($name, $installerName, $installPath, $state, $env) |
|
100
|
|
|
{ |
|
101
|
31 |
|
Assert::stringNotEmpty($name, 'The package name must be a non-empty string. Got: %s'); |
|
102
|
31 |
|
Assert::string($installerName, 'The installer name must be a string. Got: %s'); |
|
103
|
31 |
|
Assert::stringNotEmpty($installPath, 'The install path must be a non-empty string. Got: %s'); |
|
104
|
31 |
|
Assert::oneOf($state, self::$states, 'The package state must be one of %2$s. Got: %s'); |
|
105
|
31 |
|
Assert::oneOf($env, self::$envs, 'The package environment must be one of %2$s. Got: %s'); |
|
106
|
|
|
|
|
107
|
31 |
|
$this->name = $name; |
|
108
|
31 |
|
$this->installerName = $installerName; |
|
109
|
31 |
|
$this->installPath = $installPath; |
|
110
|
31 |
|
$this->state = $state; |
|
111
|
31 |
|
$this->env = $env; |
|
112
|
31 |
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Returns the package name. |
|
116
|
|
|
* |
|
117
|
|
|
* @return string The package name. |
|
118
|
|
|
*/ |
|
119
|
31 |
|
public function getName() |
|
120
|
|
|
{ |
|
121
|
31 |
|
return $this->name; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* Returns the name of the package installer. |
|
126
|
|
|
* |
|
127
|
|
|
* @return string The installer name. |
|
128
|
|
|
*/ |
|
129
|
31 |
|
public function getInstallerName() |
|
130
|
|
|
{ |
|
131
|
31 |
|
return $this->installerName; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* Returns the absolute path to where the package is installed. |
|
136
|
|
|
* |
|
137
|
|
|
* @return string The install path. |
|
138
|
|
|
*/ |
|
139
|
31 |
|
public function getInstallPath() |
|
140
|
|
|
{ |
|
141
|
31 |
|
return $this->installPath; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* Returns the state of the package. |
|
146
|
|
|
* |
|
147
|
|
|
* @return string One of the STATE_* constants in this class. |
|
148
|
|
|
*/ |
|
149
|
31 |
|
public function getState() |
|
150
|
|
|
{ |
|
151
|
31 |
|
return $this->state; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* Returns the environment that the package is installed in. |
|
156
|
|
|
* |
|
157
|
|
|
* @return string One of the ENV_* constants in this class. |
|
158
|
|
|
*/ |
|
159
|
14 |
|
public function getEnvironment() |
|
160
|
|
|
{ |
|
161
|
14 |
|
return $this->env; |
|
162
|
|
|
} |
|
163
|
|
|
} |
|
164
|
|
|
|