Skip to content

Commit e342b81

Browse files
committed
DI: switch to newer nette/schema
1 parent a027cc2 commit e342b81

File tree

1 file changed

+36
-46
lines changed

1 file changed

+36
-46
lines changed

src/DI/DeployerExtension.php

Lines changed: 36 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,63 +7,53 @@
77
use Contributte\Deployer\Manager;
88
use Contributte\Deployer\Runner;
99
use Nette\DI\CompilerExtension;
10-
use Nette\DI\Statement;
10+
use Nette\DI\Definitions\Statement;
11+
use Nette\Schema\Expect;
12+
use Nette\Schema\Schema;
13+
use stdClass;
1114

1215
/**
13-
* Deployer Extension
16+
* @property-read stdClass $config
1417
*/
1518
final class DeployerExtension extends CompilerExtension
1619
{
1720

18-
/** @var mixed[] */
19-
private $defaults = [
20-
'config' => [
21-
'mode' => Config::MODE_TEST,
22-
'logFile' => '%appDir/../log/deploy.log',
23-
'tempDir' => '%appDir/../temp',
24-
'colors' => null,
25-
],
26-
'sections' => [],
27-
'userdata' => [],
28-
'plugins' => [],
29-
];
30-
31-
/** @var mixed[] */
32-
private $sectionDefaults = [
33-
'testMode' => true,
34-
'deployFile' => null,
35-
'remote' => null,
36-
'local' => '%appDir',
37-
'ignore' => [],
38-
'allowdelete' => true,
39-
'before' => [],
40-
'after' => [],
41-
'purge' => [],
42-
'preprocess' => false,
43-
'passiveMode' => false,
44-
'filePermissions' => '',
45-
'dirPermissions' => '',
46-
];
21+
public function getConfigSchema(): Schema
22+
{
23+
return Expect::structure([
24+
'config' => Expect::structure([
25+
'mode' => Expect::anyOf(Config::MODE_GENERATE, Config::MODE_RUN, Config::MODE_TEST)->default(Config::MODE_TEST),
26+
'logFile' => Expect::string()->required(),
27+
'tempDir' => Expect::string()->required(),
28+
'colors' => Expect::string(),
29+
]),
30+
'userdata' => Expect::mixed(),
31+
'plugins' => Expect::mixed(),
32+
'sections' => Expect::arrayOf(
33+
Expect::structure([
34+
'testMode' => Expect::bool()->default(true),
35+
'deployFile' => Expect::string(),
36+
'remote' => Expect::string(),
37+
'local' => Expect::string()->required(),
38+
'ignore' => Expect::arrayOf('string'),
39+
'allowdelete' => Expect::bool()->default(true),
40+
'before' => Expect::mixed(),
41+
'after' => Expect::mixed(),
42+
'purge' => Expect::mixed(),
43+
'preprocess' => Expect::bool()->default(false),
44+
'passiveMode' => Expect::bool()->default(false),
45+
'filePermissions' => Expect::string(),
46+
'dirPermissions' => Expect::string(),
47+
])->required()
48+
),
49+
]);
50+
}
4751

48-
/**
49-
* Processes configuration data. Intended to be overridden by descendant.
50-
*/
5152
public function loadConfiguration(): void
5253
{
53-
// Validate config
54-
$config = $this->validateConfig($this->defaults);
55-
56-
// Get builder
5754
$builder = $this->getContainerBuilder();
55+
$config = $this->config;
5856

59-
// Process sections
60-
foreach ($config['sections'] as $name => $section) {
61-
62-
// Validate and merge section
63-
$config['sections'][$name] = $this->validateConfig($this->sectionDefaults, $section);
64-
}
65-
66-
// Add deploy manager
6757
$builder->addDefinition($this->prefix('manager'))
6858
->setFactory(Manager::class, [
6959
new Statement(Runner::class),

0 commit comments

Comments
 (0)