1 | <?php |
||
26 | abstract class AbstractManager implements ManagerInterface |
||
27 | { |
||
28 | /** |
||
29 | * Current app version. |
||
30 | * |
||
31 | * @var string |
||
32 | */ |
||
33 | protected $currentVersion; |
||
34 | |||
35 | /** |
||
36 | * The latest app version. |
||
37 | * |
||
38 | * @var string |
||
39 | */ |
||
40 | protected $latestVersion = '0.0.0'; |
||
41 | |||
42 | /** |
||
43 | * @var ClientInterface |
||
44 | */ |
||
45 | protected $client; |
||
46 | |||
47 | /** |
||
48 | * @var Temp directory to store update packages. |
||
49 | */ |
||
50 | protected $tempDir; |
||
51 | |||
52 | /** |
||
53 | * @var App target directory. |
||
54 | */ |
||
55 | protected $targetDir; |
||
56 | |||
57 | /** |
||
58 | * Logger. |
||
59 | * |
||
60 | * @var LoggerInterface |
||
61 | */ |
||
62 | protected $logger; |
||
63 | |||
64 | /** |
||
65 | * Construct. |
||
66 | * |
||
67 | * @param ClientInterface $client Client |
||
68 | * @param VersionInterface $version Version |
||
69 | * @param array $options An array of options |
||
70 | * @param LoggerInterface|null $logger Logger |
||
71 | */ |
||
72 | public function __construct( |
||
73 | ClientInterface $client, |
||
74 | VersionInterface $version, |
||
75 | array $options = array(), |
||
76 | LoggerInterface $logger = null |
||
77 | ) { |
||
78 | $this->client = $client; |
||
79 | $this->currentVersion = $version->getVersion(); |
||
80 | $this->tempDir = $options['temp_dir']; |
||
81 | $this->targetDir = $options['target_dir']; |
||
82 | $this->logger = $logger; |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * Gets the logger instance. |
||
87 | * |
||
88 | * @return LoggerInterface Logger |
||
89 | */ |
||
90 | protected function getLogger() |
||
94 | |||
95 | /** |
||
96 | * Has the logger instance. |
||
97 | * |
||
98 | * @return bool |
||
99 | */ |
||
100 | protected function hasLogger() |
||
108 | |||
109 | /** |
||
110 | * Adds logger info message. |
||
111 | * |
||
112 | * @param string $message Message |
||
113 | */ |
||
114 | protected function addLogInfo($message) |
||
120 | |||
121 | /** |
||
122 | * Copies remote file to the server where |
||
123 | * the app is installed. |
||
124 | * |
||
125 | * @param string $fromUrl Remote file url |
||
126 | * @param string $name Copied file name |
||
127 | * |
||
128 | * @return bool True on success |
||
129 | * |
||
130 | * @throws NotFoundHttpException When file not found |
||
131 | */ |
||
132 | protected function copyRemoteFile($fromUrl, $name) |
||
151 | |||
152 | /** |
||
153 | * Sorts an array of packages by version. |
||
154 | * Descending order based on Semantic Versioning. |
||
155 | * |
||
156 | * @param array $array Array of objects |
||
157 | */ |
||
158 | protected function sortPackagesByVersion(array $array = array()) |
||
168 | } |
||
169 |