-
-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bugfix pri onAfter a onBefore #6
Open
kubomikita
wants to merge
8
commits into
contributte:master
Choose a base branch
from
kubomikita:advholding
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7f39e7f
bugfix pri onAfter a onBefore
kubomikita b40377d
nette 3.0 compatibility
kubomikita 19ead41
codesniffer fix errors
kubomikita c183d35
squizlabs/php_codesniffer run
kubomikita 119dd25
runer code standard fix
kubomikita 666dc42
update
kubomikita 96162c7
stable version for old projects
kubomikita 7c39627
update dependencies
kubomikita File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,67 +8,95 @@ | |
use Contributte\Deployer\Runner; | ||
use Nette\DI\CompilerExtension; | ||
use Nette\DI\Statement; | ||
use Nette\Schema\Expect; | ||
use Nette\Schema\Processor; | ||
use Nette\Schema\Schema; | ||
|
||
/** | ||
* Deployer Extension | ||
*/ | ||
final class DeployerExtension extends CompilerExtension | ||
{ | ||
|
||
/** @var mixed[] */ | ||
private $defaults = [ | ||
'config' => [ | ||
'mode' => Config::MODE_TEST, | ||
'logFile' => '%appDir/../log/deploy.log', | ||
'tempDir' => '%appDir/../temp', | ||
'colors' => null, | ||
], | ||
'sections' => [], | ||
'userdata' => [], | ||
'plugins' => [], | ||
]; | ||
public function getConfigSchema() : Schema | ||
{ | ||
return Expect::structure( | ||
[ | ||
'config' => Expect::structure( | ||
[ | ||
'mode' => Expect::string(Config::MODE_TEST), | ||
'logFile' => Expect::string('%appDir/../log/deploy.log'), | ||
'tempDir' => Expect::string('%appDir/../temp'), | ||
'colors' => Expect::bool(), | ||
] | ||
), | ||
'sections' => Expect::array(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
'userdata' => Expect::array(), | ||
'plugins' => Expect::array() | ||
] | ||
); | ||
} | ||
|
||
/** @var mixed[] */ | ||
private $sectionDefaults = [ | ||
'testMode' => true, | ||
'deployFile' => null, | ||
'remote' => null, | ||
'local' => '%appDir', | ||
'ignore' => [], | ||
'allowdelete' => true, | ||
'before' => [], | ||
'after' => [], | ||
'purge' => [], | ||
'preprocess' => false, | ||
'passiveMode' => false, | ||
'filePermissions' => '', | ||
'dirPermissions' => '', | ||
]; | ||
/** | ||
* Validates section config | ||
* | ||
* @param array $data Config array of section | ||
* | ||
* @return array | ||
*/ | ||
public function validateSectionConfig(array $data): array | ||
{ | ||
$schema = Expect::structure( | ||
[ | ||
'remote' => Expect::string()->required(), | ||
'local' => Expect::string()->required(), | ||
'deployFile' => Expect::string('.dep'), | ||
'ignore' => Expect::array(), | ||
'purge' => Expect::array(), | ||
'after' => Expect::array(), | ||
'before' => Expect::array(), | ||
'testMode' => Expect::bool(false), | ||
'preprocess' => Expect::bool(false), | ||
'allowdelete' => Expect::bool(true), | ||
'passiveMode' => Expect::bool(false), | ||
'filePermissions' => Expect::string(''), | ||
'dirPermissions' => Expect::string(''), | ||
] | ||
); | ||
|
||
/** | ||
* Processes configuration data. Intended to be overridden by descendant. | ||
*/ | ||
public function loadConfiguration(): void | ||
{ | ||
// Validate config | ||
$config = $this->validateConfig($this->defaults); | ||
$processor = new Processor(); | ||
return (array) $processor->process($schema, $data); | ||
} | ||
|
||
// Get builder | ||
$builder = $this->getContainerBuilder(); | ||
/** | ||
* Processes configuration data. Intended to be overridden by descendant. | ||
* | ||
* @return void | ||
*/ | ||
public function loadConfiguration(): void | ||
{ | ||
// Validate config | ||
$config = (array) $this->config; | ||
$config['config'] = (array) $this->config->config; | ||
|
||
// Process sections | ||
foreach ($config['sections'] as $name => $section) { | ||
// Get builder | ||
$builder = $this->getContainerBuilder(); | ||
|
||
// Validate and merge section | ||
$config['sections'][$name] = $this->validateConfig($this->sectionDefaults, $section); | ||
} | ||
// Process sections | ||
foreach ($config['sections'] as $name => $section) { | ||
|
||
// Add deploy manager | ||
$builder->addDefinition($this->prefix('manager')) | ||
->setFactory(Manager::class, [ | ||
new Statement(Runner::class), | ||
new Statement(ConfigFactory::class, [$config]), | ||
]); | ||
} | ||
// Validate and merge section | ||
$config['sections'][$name] = $this->validateSectionConfig($section); | ||
} | ||
|
||
// Add deploy manager | ||
$builder->addDefinition($this->prefix('manager')) | ||
->setFactory( | ||
Manager::class, [ | ||
new Statement(Runner::class), | ||
new Statement(ConfigFactory::class, [$config]), | ||
] | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default parameters in schema are not translated to their respective values. They should be added through
$this->getContainerBuilder()->parameters
orlogFile
andtempDir
should be->required();