2024.8.23
Loading...
Searching...
No Matches
class.bins.php
Go to the documentation of this file.
1<?php
2/*
3 *
4 * * Copyright (c) 2021-2024 Bearsampp
5 * * License: GNU General Public License version 3 or later; see LICENSE.txt
6 * * Website: https://bearsampp.com
7 * * Github: https://github.com/Bearsampp
8 *
9 */
10
11/**
12 * The `Bins` class manages various bin modules such as Mailhog, Mailpit, Memcached, Apache, PHP, MySQL, MariaDB, PostgreSQL, Node.js, FileZilla, and Xlight.
13 * It provides methods to initialize, reload, update, and retrieve these modules.
14 * The class also handles logging and service management for the enabled bin modules.
15 */
16class Bins
17{
18 const TYPE = 'bins';
19
20 private $mailhog;
21 private $mailpit;
22 private $memcached;
23 private $apache;
24 private $php;
25 private $mysql;
26 private $mariadb;
27 private $postgresql;
28 private $nodejs;
29 private $filezilla;
30 private $xlight;
31
32 /**
33 * Constructor for the Bins class.
34 * Initializes the Bins object and logs the initialization.
35 */
36 public function __construct()
37 {
38 Util::logInitClass($this);
39 }
40
41 /**
42 * Reloads the configuration for all bin modules.
43 * Logs the reload action and calls the reload method on each bin module.
44 */
45 public function reload()
46 {
47 Util::logInfo('Reload bins');
48 foreach ($this->getAll() as $bin) {
49 $bin->reload();
50 }
51 }
52
53 /**
54 * Updates the configuration for all bin modules.
55 * Logs the update action and calls the update method on each bin module.
56 */
57 public function update()
58 {
59 Util::logInfo('Update bins config');
60 foreach ($this->getAll() as $bin) {
61 $bin->update();
62 }
63 }
64
65 /**
66 * Retrieves all bin modules.
67 *
68 * @return array An array of all bin modules.
69 */
70 public function getAll()
71 {
72 return array(
73 $this->getMailhog(),
74 $this->getMailpit(),
75 $this->getMemcached(),
76 $this->getApache(),
77 $this->getFilezilla(),
78 $this->getMariadb(),
79 $this->getPostgresql(),
80 $this->getMysql(),
81 $this->getPhp(),
82 $this->getNodejs(),
83 $this->getXlight(),
84 );
85 }
86
87 /**
88 * Retrieves the Mailhog bin module.
89 * If the Mailhog module is not initialized, it creates a new instance.
90 *
91 * @return BinMailhog The Mailhog bin module.
92 */
93 public function getMailhog()
94 {
95 if ($this->mailhog == null) {
96 $this->mailhog = new BinMailhog('mailhog', self::TYPE);
97 }
98 return $this->mailhog;
99 }
100
101 /**
102 * Retrieves the Mailpit bin module.
103 * If the Mailpit module is not initialized, it creates a new instance.
104 *
105 * @return BinMailpit The Mailpit bin module.
106 */
107 public function getMailpit()
108 {
109 if ($this->mailpit == null) {
110 $this->mailpit = new BinMailpit('mailpit', self::TYPE);
111 }
112 return $this->mailpit;
113 }
114
115 /**
116 * Retrieves the Memcached bin module.
117 * If the Memcached module is not initialized, it creates a new instance.
118 *
119 * @return BinMemcached The Memcached bin module.
120 */
121 public function getMemcached()
122 {
123 if ($this->memcached == null) {
124 $this->memcached = new BinMemcached('memcached', self::TYPE);
125 }
126 return $this->memcached;
127 }
128
129 /**
130 * Retrieves the Apache bin module.
131 * If the Apache module is not initialized, it creates a new instance.
132 *
133 * @return BinApache The Apache bin module.
134 */
135 public function getApache()
136 {
137 if ($this->apache == null) {
138 $this->apache = new BinApache('apache', self::TYPE);
139 }
140 return $this->apache;
141 }
142
143 /**
144 * Retrieves the PHP bin module.
145 * If the PHP module is not initialized, it creates a new instance.
146 *
147 * @return BinPhp The PHP bin module.
148 */
149 public function getPhp()
150 {
151 if ($this->php == null) {
152 $this->php = new BinPhp('php', self::TYPE);
153 }
154 return $this->php;
155 }
156
157 /**
158 * Retrieves the MySQL bin module.
159 * If the MySQL module is not initialized, it creates a new instance.
160 *
161 * @return BinMysql The MySQL bin module.
162 */
163 public function getMysql()
164 {
165 if ($this->mysql == null) {
166 $this->mysql = new BinMysql('mysql', self::TYPE);
167 }
168 return $this->mysql;
169 }
170
171 /**
172 * Retrieves the MariaDB bin module.
173 * If the MariaDB module is not initialized, it creates a new instance.
174 *
175 * @return BinMariadb The MariaDB bin module.
176 */
177 public function getMariadb()
178 {
179 if ($this->mariadb == null) {
180 $this->mariadb = new BinMariadb('mariadb', self::TYPE);
181 }
182 return $this->mariadb;
183 }
184
185 /**
186 * Retrieves the PostgreSQL bin module.
187 * If the PostgreSQL module is not initialized, it creates a new instance.
188 *
189 * @return BinPostgresql The PostgreSQL bin module.
190 */
191 public function getPostgresql()
192 {
193 if ($this->postgresql == null) {
194 $this->postgresql = new BinPostgresql('postgresql', self::TYPE);
195 }
196 return $this->postgresql;
197 }
198
199 /**
200 * Retrieves the Node.js bin module.
201 * If the Node.js module is not initialized, it creates a new instance.
202 *
203 * @return BinNodejs The Node.js bin module.
204 */
205 public function getNodejs()
206 {
207 if ($this->nodejs == null) {
208 $this->nodejs = new BinNodejs('nodejs', self::TYPE);
209 }
210 return $this->nodejs;
211 }
212
213 /**
214 * Retrieves the FileZilla bin module.
215 * If the FileZilla module is not initialized, it creates a new instance.
216 *
217 * @return BinFilezilla The FileZilla bin module.
218 */
219 public function getFilezilla()
220 {
221 if ($this->filezilla == null) {
222 $this->filezilla = new BinFilezilla('filezilla', self::TYPE);
223 }
224 return $this->filezilla;
225 }
226
227 /**
228 * Retrieves the Xlight bin module.
229 * If the Xlight module is not initialized, it creates a new instance.
230 *
231 * @return BinXlight The Xlight bin module.
232 */
233 public function getXlight()
234 {
235 if ($this->xlight == null) {
236 $this->xlight = new BinXlight('xlight', self::TYPE);
237 }
238 return $this->xlight;
239 }
240
241 /**
242 * Retrieves the log paths for all bin modules.
243 *
244 * @return array An array of log paths for all bin modules.
245 */
246 public function getLogsPath()
247 {
248 return array(
249 $this->getFilezilla()->getLogsPath(),
250 );
251 }
252
253 /**
254 * Retrieves the services for all enabled bin modules.
255 *
256 * @return array An associative array of service names and their corresponding service objects.
257 */
258 public function getServices()
259 {
260 $result = array();
261
262 if ($this->getMailhog()->isEnable()) {
263 $result[BinMailhog::SERVICE_NAME] = $this->getMailhog()->getService();
264 }
265 if ($this->getMailpit()->isEnable()) {
266 $result[BinMailpit::SERVICE_NAME] = $this->getMailpit()->getService();
267 }
268 if ($this->getMemcached()->isEnable()) {
269 $result[BinMemcached::SERVICE_NAME] = $this->getMemcached()->getService();
270 }
271 if ($this->getApache()->isEnable()) {
272 $result[BinApache::SERVICE_NAME] = $this->getApache()->getService();
273 }
274 if ($this->getMysql()->isEnable()) {
275 $result[BinMysql::SERVICE_NAME] = $this->getMysql()->getService();
276 }
277 if ($this->getMariadb()->isEnable()) {
278 $result[BinMariadb::SERVICE_NAME] = $this->getMariadb()->getService();
279 }
280 if ($this->getPostgresql()->isEnable()) {
281 $result[BinPostgresql::SERVICE_NAME] = $this->getPostgresql()->getService();
282 }
283 if ($this->getFilezilla()->isEnable()) {
284 $result[BinFilezilla::SERVICE_NAME] = $this->getFilezilla()->getService();
285 }
286 if ($this->getXlight()->isEnable()) {
287 $result[BinXlight::SERVICE_NAME] = $this->getXlight()->getService();
288 }
289
290 return $result;
291 }
292}
$result
const SERVICE_NAME
getMailhog()
$postgresql
getLogsPath()
getMariadb()
getServices()
reload()
getApache()
getAll()
getNodejs()
getPostgresql()
const TYPE
update()
getMailpit()
getFilezilla()
getXlight()
__construct()
getMemcached()
getMysql()
static logInitClass($classInstance)
static logInfo($data, $file=null)