Skip to content

Commit d5742de

Browse files
authored
Fix of runtime errors caused by new DI schema (#12)
1 parent e342b81 commit d5742de

File tree

3 files changed

+67
-56
lines changed

3 files changed

+67
-56
lines changed

src/Config/ConfigFactory.php

Lines changed: 49 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
class ConfigFactory
66
{
77

8-
/** @var mixed[] */
8+
/** @var object */
99
private $data;
1010

1111
/**
12-
* @param mixed[] $data
12+
* @param object $data
1313
*/
14-
public function __construct(array $data)
14+
public function __construct(object $data)
1515
{
1616
$this->data = $data;
1717
}
@@ -22,57 +22,68 @@ public function create(): Config
2222
$config = new Config();
2323

2424
// Parse mode
25-
switch ($this->data['config']['mode']) {
26-
case Config::MODE_GENERATE:
27-
$mode = Config::MODE_GENERATE;
28-
break;
29-
case Config::MODE_RUN:
30-
$mode = Config::MODE_RUN;
31-
break;
32-
default:
33-
$mode = Config::MODE_TEST;
25+
if (isset($this->data->config) && isset($this->data->config->mode)) {
26+
switch ($this->data->config->mode) {
27+
case Config::MODE_GENERATE:
28+
$mode = Config::MODE_GENERATE;
29+
break;
30+
case Config::MODE_RUN:
31+
$mode = Config::MODE_RUN;
32+
break;
33+
default:
34+
$mode = Config::MODE_TEST;
35+
}
36+
37+
// Set mode (run|generate|test)
38+
$config->setMode($mode);
39+
} else {
40+
$config->setMode(Config::MODE_TEST);
3441
}
3542

36-
// Set mode (run|generate|test)
37-
$config->setMode($mode);
38-
$config->setLogFile($this->data['config']['logFile']);
39-
$config->setTempDir($this->data['config']['tempDir'] ?? sys_get_temp_dir() . '/deployment');
43+
$config->setLogFile((isset($this->data->config) && isset($this->data->config->logFile)) ? $this->data->config->logFile : '');
44+
$config->setTempDir((isset($this->data->config) && isset($this->data->config->tempDir)) ? $this->data->config->tempDir : sys_get_temp_dir() . '/deployment');
4045

4146
// Set or detect colors support
42-
if ($this->data['config']['colors'] !== null) {
43-
$config->setColors((bool) $this->data['config']['colors']);
47+
if (isset($this->data->config) && isset($this->data->config->colors) && $this->data->config->colors !== null) {
48+
$config->setColors((bool) $this->data->config->colors);
4449
} else {
4550
$config->setColors(PHP_SAPI === 'cli' && ((function_exists('posix_isatty') && posix_isatty(STDOUT))
4651
|| getenv('ConEmuANSI') === 'ON' || getenv('ANSICON') !== false));
4752
}
4853

4954
// Set user data
50-
$config->setUserdata($this->data['userdata']);
55+
if (isset($this->data->userdata)) {
56+
$config->setUserdata($this->data->userdata);
57+
}
5158

5259
// Set plugins
53-
$config->setPlugins($this->data['plugins']);
60+
if (isset($this->data->plugins)) {
61+
$config->setPlugins($this->data->plugins);
62+
}
5463

5564
// Parse sections
56-
foreach ($this->data['sections'] as $name => $sdata) {
57-
$section = new Section();
58-
$section->setName($name);
59-
$section->setTestMode($sdata['testMode']);
60-
$section->setLocal($sdata['local']);
61-
$section->setRemote($sdata['remote']);
62-
$section->setPreprocess($sdata['preprocess']);
63-
$section->setPreprocessMasks($sdata['preprocess'] !== false ? $sdata['preprocess'] : []);
64-
$section->setAllowDelete($sdata['allowdelete']);
65-
$section->setIgnoreMasks($sdata['ignore']);
66-
$section->setDeployFile($sdata['deployFile']);
67-
$section->setAfterCallbacks($sdata['after']);
68-
$section->setBeforeCallbacks($sdata['before']);
69-
$section->setPassiveMode($sdata['passiveMode']);
70-
$section->setPurges($sdata['purge']);
71-
$section->setFilePermissions($sdata['filePermissions']);
72-
$section->setDirPermissions($sdata['dirPermissions']);
65+
if (isset($this->data->sections)) {
66+
foreach ($this->data->sections as $name => $sdata) {
67+
$section = new Section();
68+
$section->setName($name);
69+
$section->setTestMode($sdata->testMode);
70+
$section->setLocal($sdata->local);
71+
$section->setRemote($sdata->remote);
72+
$section->setPreprocess($sdata->preprocess);
73+
$section->setPreprocessMasks($sdata->preprocess !== false ? $sdata->preprocess : []);
74+
$section->setAllowDelete($sdata->allowdelete);
75+
$section->setIgnoreMasks($sdata->ignore);
76+
$section->setDeployFile($sdata->deployFile);
77+
$section->setAfterCallbacks($sdata->after);
78+
$section->setBeforeCallbacks($sdata->before);
79+
$section->setPassiveMode($sdata->passiveMode);
80+
$section->setPurges($sdata->purge);
81+
$section->setFilePermissions($sdata->filePermissions);
82+
$section->setDirPermissions($sdata->dirPermissions);
7383

7484
// Add to config
75-
$config->addSection($section);
85+
$config->addSection($section);
86+
}
7687
}
7788

7889
return $config;

src/Config/Section.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,18 @@ class Section
4747
/** @var bool */
4848
private $passiveMode = true;
4949

50-
/** @var string */
51-
private $filePermissions = '';
50+
/** @var string|null */
51+
private $filePermissions;
5252

53-
/** @var string */
54-
private $dirPermissions = '';
53+
/** @var string|null */
54+
private $dirPermissions;
5555

5656
public function getName(): ?string
5757
{
5858
return $this->name;
5959
}
6060

61-
public function setName(string $name): void
61+
public function setName(?string $name): void
6262
{
6363
$this->name = $name;
6464
}
@@ -68,7 +68,7 @@ public function getRemote(): ?string
6868
return $this->remote;
6969
}
7070

71-
public function setRemote(string $remote): void
71+
public function setRemote(?string $remote): void
7272
{
7373
$this->remote = $remote;
7474
}
@@ -78,7 +78,7 @@ public function getLocal(): ?string
7878
return $this->local;
7979
}
8080

81-
public function setLocal(string $local): void
81+
public function setLocal(?string $local): void
8282
{
8383
$this->local = $local;
8484
}
@@ -249,20 +249,20 @@ public function setTestMode(bool $testMode): void
249249

250250
public function getFilePermissions(): ?int
251251
{
252-
return $this->filePermissions === '' ? null : (int) octdec($this->filePermissions);
252+
return (($this->filePermissions === null) || $this->filePermissions === '') ? null : (int) octdec($this->filePermissions);
253253
}
254254

255-
public function setFilePermissions(string $mask): void
255+
public function setFilePermissions(?string $mask): void
256256
{
257257
$this->filePermissions = $mask;
258258
}
259259

260260
public function getDirPermissions(): ?int
261261
{
262-
return $this->dirPermissions === '' ? null : (int) octdec($this->dirPermissions);
262+
return (($this->dirPermissions === null) || $this->dirPermissions === '') ? null : (int) octdec($this->dirPermissions);
263263
}
264264

265-
public function setDirPermissions(string $mask): void
265+
public function setDirPermissions(?string $mask): void
266266
{
267267
$this->dirPermissions = $mask;
268268
}

src/DI/DeployerExtension.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,21 @@ public function getConfigSchema(): Schema
2525
'mode' => Expect::anyOf(Config::MODE_GENERATE, Config::MODE_RUN, Config::MODE_TEST)->default(Config::MODE_TEST),
2626
'logFile' => Expect::string()->required(),
2727
'tempDir' => Expect::string()->required(),
28-
'colors' => Expect::string(),
28+
'colors' => Expect::bool()->default(false),
2929
]),
30-
'userdata' => Expect::mixed(),
31-
'plugins' => Expect::mixed(),
30+
'userdata' => Expect::mixed()->default([]),
31+
'plugins' => Expect::mixed()->default([]),
3232
'sections' => Expect::arrayOf(
3333
Expect::structure([
3434
'testMode' => Expect::bool()->default(true),
3535
'deployFile' => Expect::string(),
3636
'remote' => Expect::string(),
3737
'local' => Expect::string()->required(),
38-
'ignore' => Expect::arrayOf('string'),
38+
'ignore' => Expect::arrayOf('string')->default([]),
3939
'allowdelete' => Expect::bool()->default(true),
40-
'before' => Expect::mixed(),
41-
'after' => Expect::mixed(),
42-
'purge' => Expect::mixed(),
40+
'before' => Expect::mixed()->default([]),
41+
'after' => Expect::mixed()->default([]),
42+
'purge' => Expect::mixed()->default([]),
4343
'preprocess' => Expect::bool()->default(false),
4444
'passiveMode' => Expect::bool()->default(false),
4545
'filePermissions' => Expect::string(),

0 commit comments

Comments
 (0)