Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jan 13, 2019. It is now read-only.

Commit 59eeaca

Browse files
committed
Init
0 parents commit 59eeaca

File tree

5 files changed

+256
-0
lines changed

5 files changed

+256
-0
lines changed

‎.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*swp
2+
vendor

‎LICENSE‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2017 Boyko Alexey
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

‎Plugin/Deployer.php‎

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
<?php
2+
/**
3+
* Deployer plugin for PHPCensor
4+
*
5+
* @author Alexey Boyko <ket4yiit@gmail.com>
6+
* @license MIT
7+
* https://github.com/ket4yii/phpcensor-deployer-plugin/blob/master/LICENSE
8+
*
9+
* @link https://github.com/ket4yii/phpcensor-deployer-plugin
10+
* @see http://deployer.org
11+
*/
12+
13+
namespace Ket4yii\PHPCensor\Deployer\Plugin;
14+
15+
use PHPCensor\Builder;
16+
use PHPCensor\Model\Build;
17+
18+
class Deployer implements \PHPCensor\Plugin
19+
{
20+
21+
protected $phpcensor;
22+
protected $build;
23+
protected $config;
24+
protected $dep;
25+
protected $branch;
26+
27+
/**
28+
* Standard Constructor
29+
*
30+
* $options['directory'] Output Directory. Default: %BUILDPATH%
31+
* $options['filename'] Phar Filename. Default: build.phar
32+
* $options['regexp'] Regular Expression Filename Capture. Default: /\.php$/
33+
* $options['stub'] Stub Content. No Default Value
34+
*
35+
* @param Builder $phpcensor PHPCensor instance
36+
* @param Build $build Build instance
37+
* @param array $options Plugin options
38+
*/
39+
public function __construct(
40+
Builder $phpcensor,
41+
Build $build,
42+
array $options = array()
43+
) {
44+
$this->phpcensor = $phpcensor;
45+
$this->build = $build;
46+
$this->config = $options;
47+
48+
$this->dep = $this->phpcensor->findBinary('dep');
49+
$this->branch = $this->build->getBranch();
50+
}
51+
52+
/**
53+
* PHPCensor plugin executor.
54+
*
55+
* @return bool Did plugin execute successfully
56+
*/
57+
public function execute()
58+
{
59+
if (($validationResult = $this->validateConfig()) !== null) {
60+
$this->phpcensor->log($validationResult['message']);
61+
62+
return $validationResult['successful'];
63+
}
64+
65+
$branchConfig = $this->config[$this->branch];
66+
$options = $this->getOptions($branchConfig);
67+
68+
$deployerCmd = "$this->dep$options";
69+
70+
return $this->phpcensor->executeCommand($deployerCmd);
71+
}
72+
73+
/**
74+
* Validate config.
75+
*
76+
* $validationRes['message'] Message to log
77+
* $validationRes['successful'] Plugin status that is connected with error
78+
*
79+
* @return array validation result
80+
*/
81+
protected function validateConfig()
82+
{
83+
if (empty($this->config)) {
84+
return [
85+
'message' => 'Can\'t find configuration for plugin!',
86+
'successful' => false
87+
];
88+
}
89+
90+
if (empty($this->config[$this->branch])) {
91+
return [
92+
'message' => 'There is no specified config for this branch.',
93+
'successful' => true
94+
];
95+
}
96+
97+
$branchConf = $this->config[$this->branch];
98+
99+
if (empty($branchConf['stage'])) {
100+
return [
101+
'message' => 'There is no stage for this branch',
102+
'successful' => false
103+
];
104+
}
105+
106+
return null;
107+
}
108+
109+
/**
110+
* Get verbosity flag.
111+
*
112+
* @param string $verbosity User defined verbosity level
113+
*
114+
* @return string Verbosity flag
115+
*/
116+
protected function getVerbosityOption($verbosity)
117+
{
118+
$LOG_LEVEL_ENUM = [
119+
'verbose' =>'v',
120+
'very verbose' => 'vv',
121+
'debug' => 'vvv',
122+
'quiet' => 'q'
123+
];
124+
125+
$verbosity = strtolower(trim($verbosity));
126+
127+
if ($verbosity !== 'normal') {
128+
return '-' . $LOG_LEVEL_ENUM[$verbosity];
129+
} else {
130+
return '';
131+
}
132+
}
133+
134+
/**
135+
* Make deployer options from config
136+
*
137+
* @param array $config Deployer configration array
138+
*
139+
* @return string Deployer options
140+
*/
141+
protected function getOptions($config)
142+
{
143+
$options = [];
144+
145+
if ($config['task'] != null) {
146+
$options[] = $config['task'];
147+
} else {
148+
$options[] = 'deploy';
149+
}
150+
151+
if ($config['stage'] != null) {
152+
$options[] = $config['stage'];
153+
}
154+
155+
if ($config['verbosity'] != null) {
156+
$options[] = $this->getVerbosityOption($config['verbosity']);
157+
}
158+
159+
if ($config['file'] != null) {
160+
$options[] = '--file=' . $config['file'];
161+
}
162+
163+
return implode('', $options);
164+
}
165+
}

‎README.md‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#PHPCensor-Deployer-Plugin
2+
3+
Simple plugin for [Deployer](http://deployer.org)
4+
5+
#How to use
6+
7+
Keyword of this plugin is simple. It means that you just need to define branch
8+
for configuration task name(if there is no task, plugin takes
9+
default value that is "deploy"), stage name(it would be just server name or defined stage)
10+
, verbosity level(for default is normal) and filename(by default deployer takes the deployer.php file)
11+
12+
##Plugin options
13+
14+
* stage(*required*) - Stage or server name
15+
* task(*optional*) - Task name (*default task is deploy*)
16+
* verbosity(*optional*) - Add verbose mode to plugin execution (*default is no verbose that equal to normal in the option list of values below*)
17+
* normal
18+
* verbose
19+
* very verbose
20+
* debug
21+
* quiet
22+
* file(*optional*) - Filename of deployer configuration. For default deployer takes deploy.php if this field is not specified
23+
24+
#Sample configuration
25+
```
26+
\Ket4yii\PHPCensor\Deployer\Plugin\Deployer:
27+
development: # branch name
28+
task: sample-task # optional, default task is deploy
29+
stage: dev # required, name of stage or server
30+
verbose: debug # optional, default is normal(no verbosity)
31+
file: .deploy_config.php # optional, deployer takes the deploy.php file for default
32+
master:
33+
stage: prod #required, name of stage or server
34+
```

‎composer.json‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "ket4yii/phpcensor-deployer-plugin",
3+
"description": "Simple deployer(deployer.org) plugin for PHPCensor",
4+
"license": "MIT",
5+
"authors": [
6+
{
7+
"name": "Alexey Boyko",
8+
"email": "ket4yiit@gmail.com"
9+
}
10+
],
11+
"require": {},
12+
"scripts": {
13+
"lint": "./vendor/bin/parallel-lint . --exclude vendor"
14+
},
15+
"autoload": {
16+
"psr-4": {
17+
"Ket4yii\\PHPCensor\\Deployer\\": ""
18+
}
19+
},
20+
"require-dev": {
21+
"jakub-onderka/php-parallel-lint": "^0.9.2"
22+
},
23+
"extra": {
24+
"phpci": {
25+
"pluginNamespace": "Ket4yii\\PHPCensor\\Deployer\\Plugin",
26+
"suppliedPlugins": [
27+
{
28+
"name": "PhpDeployer",
29+
"class": "Deployer"
30+
}
31+
]
32+
}
33+
}
34+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /