Skip to content

Commit 36e192d

Browse files
committed
Fix factory key
1 parent 8c0c0b3 commit 36e192d

File tree

1 file changed

+71
-61
lines changed

1 file changed

+71
-61
lines changed

src/Factory.php

Lines changed: 71 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace phpbu\App;
34

45
use phpbu\App\Backup\Check;
@@ -30,18 +31,18 @@ class Factory
3031
private static $classMap = [
3132
// type
3233
// alias => fqcn
33-
'adapter' => [
34+
'adapter' => [
3435
'array' => '\\phpbu\\App\\Adapter\\PHPArray',
3536
'constant' => '\\phpbu\\App\\Adapter\\PHPConstant',
3637
'dotenv' => '\\phpbu\\App\\Adapter\\Dotenv',
3738
'env' => '\\phpbu\\App\\Adapter\\Env',
3839
'wordpress' => '\\phpbu\\App\\Adapter\\WordPress',
3940
],
4041
'logger' => [
41-
'json' => '\\phpbu\\App\\Log\\Json',
42-
'mail' => '\\phpbu\\App\\Log\\Mail',
43-
'webhook' => '\\phpbu\\App\\Log\\Webhook',
44-
'telegram' => '\\phpbu\\App\\Log\\Telegram',
42+
'json' => '\\phpbu\\App\\Log\\Json',
43+
'mail' => '\\phpbu\\App\\Log\\Mail',
44+
'webhook' => '\\phpbu\\App\\Log\\Webhook',
45+
'telegram' => '\\phpbu\\App\\Log\\Telegram',
4546
'prometheus' => '\\phpbu\\App\\Log\\Prometheus',
4647
],
4748
'source' => [
@@ -63,43 +64,43 @@ class Factory
6364
'sizediffpreviouspercent' => '\\phpbu\\App\\Backup\\Check\\SizeDiffPreviousPercent',
6465
'sizediffavgpercent' => '\\phpbu\\App\\Backup\\Check\\SizeDiffAvgPercent',
6566
],
66-
'crypter' => [
67+
'crypter' => [
6768
'gpg' => '\\phpbu\\App\\Backup\\Crypter\\Gpg',
6869
'mcrypt' => '\\phpbu\\App\\Backup\\Crypter\\Mcrypt',
6970
'openssl' => '\\phpbu\\App\\Backup\\Crypter\\OpenSSL',
7071
],
7172
'sync' => [
72-
'amazons3' => '\\phpbu\\App\\Backup\\Sync\\AmazonS3v3',
73-
'amazons3-v3' => '\\phpbu\\App\\Backup\\Sync\\AmazonS3v3',
74-
'amazons3-v2' => '\\phpbu\\App\\Backup\\Sync\\AmazonS3v2',
75-
'backblazes3' => '\\phpbu\\App\\Backup\\Sync\\BackblazeS3',
76-
'azureblob' => '\\phpbu\\App\\Backup\\Sync\\AzureBlob',
77-
'dropbox' => '\\phpbu\\App\\Backup\\Sync\\Dropbox',
78-
'ftp' => '\\phpbu\\App\\Backup\\Sync\\Ftp',
79-
'googledrive' => '\\phpbu\\App\\Backup\\Sync\\GoogleDrive',
80-
'googlecloud' => '\\phpbu\\App\\Backup\\Sync\\GoogleCloudStorage',
81-
'rsync' => '\\phpbu\\App\\Backup\\Sync\\Rsync',
82-
'sftp' => '\\phpbu\\App\\Backup\\Sync\\Sftp',
83-
'softlayer' => '\\phpbu\\App\\Backup\\Sync\\SoftLayer',
84-
'openstack' => '\\phpbu\\App\\Backup\\Sync\\OpenStack',
85-
'yandex-disk' => '\\phpbu\\App\\Backup\\Sync\\YandexDisk',
73+
'amazons3' => '\\phpbu\\App\\Backup\\Sync\\AmazonS3v3',
74+
'amazons3-v3' => '\\phpbu\\App\\Backup\\Sync\\AmazonS3v3',
75+
'amazons3-v2' => '\\phpbu\\App\\Backup\\Sync\\AmazonS3v2',
76+
'backblazes3' => '\\phpbu\\App\\Backup\\Sync\\BackblazeS3',
77+
'azureblob' => '\\phpbu\\App\\Backup\\Sync\\AzureBlob',
78+
'dropbox' => '\\phpbu\\App\\Backup\\Sync\\Dropbox',
79+
'ftp' => '\\phpbu\\App\\Backup\\Sync\\Ftp',
80+
'googledrive' => '\\phpbu\\App\\Backup\\Sync\\GoogleDrive',
81+
'googlecloudstorage' => '\\phpbu\\App\\Backup\\Sync\\GoogleCloudStorage',
82+
'rsync' => '\\phpbu\\App\\Backup\\Sync\\Rsync',
83+
'sftp' => '\\phpbu\\App\\Backup\\Sync\\Sftp',
84+
'softlayer' => '\\phpbu\\App\\Backup\\Sync\\SoftLayer',
85+
'openstack' => '\\phpbu\\App\\Backup\\Sync\\OpenStack',
86+
'yandex-disk' => '\\phpbu\\App\\Backup\\Sync\\YandexDisk',
8687
],
8788
'cleaner' => [
88-
'capacity' => '\\phpbu\\App\\Backup\\Cleaner\\Capacity',
89-
'outdated' => '\\phpbu\\App\\Backup\\Cleaner\\Outdated',
90-
'stepwise' => '\\phpbu\\App\\Backup\\Cleaner\\Stepwise',
91-
'quantity' => '\\phpbu\\App\\Backup\\Cleaner\\Quantity',
89+
'capacity' => '\\phpbu\\App\\Backup\\Cleaner\\Capacity',
90+
'outdated' => '\\phpbu\\App\\Backup\\Cleaner\\Outdated',
91+
'stepwise' => '\\phpbu\\App\\Backup\\Cleaner\\Stepwise',
92+
'quantity' => '\\phpbu\\App\\Backup\\Cleaner\\Quantity',
9293
],
9394
];
9495

9596
/**
9697
* Backup Factory
9798
* Creates 'Source', 'Check', 'Crypter', 'Sync' and 'Cleaner' Objects.
9899
*
99-
* @param string $type
100-
* @param string $alias
100+
* @param string $type
101+
* @param string $alias
101102
* @return mixed
102-
*@throws Exception
103+
* @throws Exception
103104
*/
104105
protected function create($type, $alias)
105106
{
@@ -110,37 +111,39 @@ protected function create($type, $alias)
110111
throw new Exception(sprintf('unknown %s: %s', $type, $alias));
111112
}
112113
$class = self::$classMap[$type][$alias];
114+
113115
return new $class();
114116
}
115117

116118
/**
117119
* Adapter Factory
118120
*
119-
* @param string $alias
120-
* @param array $conf
121+
* @param string $alias
122+
* @param array $conf
121123
* @return Adapter
122-
*@throws Exception
124+
* @throws Exception
123125
*/
124-
public function createAdapter($alias, $conf = []) : Adapter
126+
public function createAdapter($alias, $conf = []): Adapter
125127
{
126128
/** @var Adapter $adapter */
127129
$adapter = $this->create('adapter', $alias);
128130
if (!($adapter instanceof Adapter)) {
129131
throw new Exception(sprintf('adapter \'%s\' has to implement the \'Adapter\' interfaces', $alias));
130132
}
131133
$adapter->setup($conf);
134+
132135
return $adapter;
133136
}
134137

135138
/**
136139
* Logger Factory
137140
*
138-
* @param string $alias
139-
* @param array $conf
141+
* @param string $alias
142+
* @param array $conf
140143
* @return Logger
141-
*@throws Exception
144+
* @throws Exception
142145
*/
143-
public function createLogger($alias, $conf = []) : Logger
146+
public function createLogger($alias, $conf = []): Logger
144147
{
145148
/** @var Logger $logger */
146149
$logger = $this->create('logger', $alias);
@@ -151,6 +154,7 @@ public function createLogger($alias, $conf = []) : Logger
151154
throw new Exception(sprintf('logger \'%s\' has to implement the \'Listener\' interface', $alias));
152155
}
153156
$logger->setup($conf);
157+
154158
return $logger;
155159
}
156160

@@ -161,7 +165,7 @@ public function createLogger($alias, $conf = []) : Logger
161165
* @return Target
162166
* @throws Exception
163167
*/
164-
public function createTarget(Configuration\Backup\Target $conf) : Target
168+
public function createTarget(Configuration\Backup\Target $conf): Target
165169
{
166170
$target = new Target($conf->dirname, $conf->filename);
167171
$target->setupPath();
@@ -170,109 +174,115 @@ public function createTarget(Configuration\Backup\Target $conf) : Target
170174
$compression = Target\Compression\Factory::create($conf->compression);
171175
$target->setCompression($compression);
172176
}
177+
173178
return $target;
174179
}
175180

176181
/**
177182
* Source Factory
178183
*
179-
* @param string $alias
180-
* @param array $conf
184+
* @param string $alias
185+
* @param array $conf
181186
* @return Source
182-
*@throws Exception
187+
* @throws Exception
183188
*/
184-
public function createSource($alias, $conf = []) : Source
189+
public function createSource($alias, $conf = []): Source
185190
{
186191
/** @var Source $source */
187192
$source = $this->create('source', $alias);
188193
if (!($source instanceof Source)) {
189194
throw new Exception(sprintf('source \'%s\' has to implement the \'Source\' interface', $alias));
190195
}
191196
$source->setup($conf);
197+
192198
return $source;
193199
}
194200

195201
/**
196202
* Check Factory
197203
*
198-
* @param string $alias
204+
* @param string $alias
199205
* @return Check
200-
*@throws Exception
206+
* @throws Exception
201207
*/
202-
public function createCheck($alias) : Check
208+
public function createCheck($alias): Check
203209
{
204210
/** @var Check $check */
205211
$check = $this->create('check', $alias);
206212
if (!($check instanceof Check)) {
207213
throw new Exception(sprintf('Check \'%s\' has to implement the \'Check\' interface', $alias));
208214
}
215+
209216
return $check;
210217
}
211218

212219
/**
213220
* Crypter Factory
214221
*
215-
* @param string $alias
216-
* @param array $conf
222+
* @param string $alias
223+
* @param array $conf
217224
* @return Crypter
218-
*@throws Exception
225+
* @throws Exception
219226
*/
220-
public function createCrypter($alias, $conf = []) : Crypter
227+
public function createCrypter($alias, $conf = []): Crypter
221228
{
222229
/** @var Crypter $crypter */
223230
$crypter = $this->create('crypter', $alias);
224231
if (!($crypter instanceof Crypter)) {
225232
throw new Exception(sprintf('Crypter \'%s\' has to implement the \'Crypter\' interface', $alias));
226233
}
227234
$crypter->setup($conf);
235+
228236
return $crypter;
229237
}
230238

231239
/**
232240
* Sync Factory
233241
*
234-
* @param string $alias
235-
* @param array $conf
242+
* @param string $alias
243+
* @param array $conf
236244
* @return Sync
237-
*@throws Exception
245+
* @throws Exception
238246
*/
239-
public function createSync($alias, $conf = []) : Sync
247+
public function createSync($alias, $conf = []): Sync
240248
{
241249
/** @var Sync $sync */
242250
$sync = $this->create('sync', $alias);
243251
if (!($sync instanceof Sync)) {
244252
throw new Exception(sprintf('sync \'%s\' has to implement the \'Sync\' interface', $alias));
245253
}
246254
$sync->setup($conf);
255+
247256
return $sync;
248257
}
249258

250259
/**
251260
* Cleaner Factory
252261
*
253-
* @param string $alias
254-
* @param array $conf
262+
* @param string $alias
263+
* @param array $conf
255264
* @return Cleaner
256-
*@throws Exception
265+
* @throws Exception
257266
*/
258-
public function createCleaner($alias, $conf = []) : Cleaner
267+
public function createCleaner($alias, $conf = []): Cleaner
259268
{
260269
/** @var Cleaner $cleaner */
261270
$cleaner = $this->create('cleaner', $alias);
262271
if (!($cleaner instanceof Cleaner)) {
263272
throw new Exception(sprintf('cleaner \'%s\' has to implement the \'Cleaner\' interface', $alias));
264273
}
265274
$cleaner->setup($conf);
275+
266276
return $cleaner;
267277
}
268278

269279
/**
270280
* Extend the backup factory
271281
*
272-
* @param string $type Type to create 'adapter', 'source', 'check', 'sync' or 'cleaner'
273-
* @param string $alias Name the class is registered at
274-
* @param string $fqcn Full Qualified Class Name
275-
* @param boolean $force Overwrite already registered class
282+
* @param string $type Type to create 'adapter', 'source', 'check', 'sync' or 'cleaner'
283+
* @param string $alias Name the class is registered at
284+
* @param string $fqcn Full Qualified Class Name
285+
* @param boolean $force Overwrite already registered class
276286
* @throws Exception
277287
*/
278288
public static function register($type, $alias, $fqcn, $force = false)
@@ -289,14 +299,14 @@ public static function register($type, $alias, $fqcn, $force = false)
289299
/**
290300
* Throws an exception if type is invalid
291301
*
292-
* @param string $type
302+
* @param string $type
293303
* @throws Exception
294304
*/
295305
private static function checkType($type)
296306
{
297307
if (!isset(self::$classMap[$type])) {
298308
throw new Exception(
299-
'invalid type, please use only \'' . implode('\', \'', array_keys(self::$classMap)) . '\''
309+
'invalid type, please use only \'' . implode('\', \'', array_keys(self::$classMap)) . '\'',
300310
);
301311
}
302312
}

0 commit comments

Comments
 (0)