Skip to content

Commit 018b4b3

Browse files
committed
- set required php 7
- update readme - update phpDoc
1 parent 98cb09a commit 018b4b3

File tree

3 files changed

+41
-13
lines changed

3 files changed

+41
-13
lines changed

DeployApplication.php

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
/**
1212
* Main class for deploying
13-
* Example for use it:
13+
* Usage example:
1414
*
1515
* ```php
1616
* // Run default commands
@@ -42,13 +42,24 @@ class DeployApplication
4242

4343
/** @var boolean */
4444
private $hasAccess;
45-
private $is_first = true;
4645

47-
public function __construct($securityKey, $project_root = '.', $logFileName = 'git-deploy-log.txt')
46+
/** @var boolean */
47+
private $isFirstLogging = true;
48+
49+
/** @var boolean */
50+
private $logError = false;
51+
52+
/**
53+
* DeployApplication constructor.
54+
* @param string $securityKey string key for protect application
55+
* @param string $workPath set working path for executing all commands
56+
* @param string $logFileName path to a log file
57+
*/
58+
public function __construct(string $securityKey, string $workPath = '.', string $logFileName = 'git-deploy-log.txt')
4859
{
4960
$this->securityKey = $securityKey;
5061
$this->logFileName = getcwd() . '/' . $logFileName;
51-
chdir($project_root);
62+
chdir($workPath);
5263
putenv('HOME=' . getcwd());
5364
}
5465

@@ -63,13 +74,20 @@ public function run(array $customCommands = [])
6374
$this->end();
6475
}
6576

77+
/**
78+
* Begin log file
79+
*/
6680
public function begin()
6781
{
6882
if ($this->checkSecurity()) {
6983
$this->logDated('SESSION START');
7084
}
7185
}
7286

87+
/**
88+
* Executing command like a command lines
89+
* @param array $customCommands you can execute custom commands
90+
*/
7391
public function execute(array $customCommands = [])
7492
{
7593
if (!$this->checkSecurity()) {
@@ -82,17 +100,23 @@ public function execute(array $customCommands = [])
82100
}
83101
}
84102

103+
/**
104+
* Finish logging and output all content from the log file
105+
*/
85106
public function end()
86107
{
87108
if ($this->checkSecurity()) {
88109
$this->logDated('SESSION END');
89110
}
90-
if (file_exists($this->logFileName)) {
111+
112+
if ($this->logError) {
113+
echo 'Write log failed';
114+
} else if (file_exists($this->logFileName)) {
91115
echo '<h1>LOG </h1><pre>';
92116
echo file_get_contents($this->logFileName);
93117
echo '</pre>';
94118
} else {
95-
echo 'log not found';
119+
echo 'A log file not found';
96120
}
97121
}
98122

@@ -155,9 +179,9 @@ private function exec(array $commands)
155179

156180
private function logDated(string $message)
157181
{
158-
if ($this->is_first) {
182+
if ($this->isFirstLogging) {
159183
$this->log("\n==============================\n");
160-
$this->is_first = false;
184+
$this->isFirstLogging = false;
161185
}
162186

163187
$this->log(date('Y.m.d H:i:s') . "\t" . $message . "\n");
@@ -168,8 +192,10 @@ private function log(string $message)
168192
if (empty($this->logFileName)) {
169193
return;
170194
}
171-
172-
file_put_contents($this->logFileName, $message, FILE_APPEND | LOCK_EX);
173-
flush();
195+
if (file_put_contents($this->logFileName, $message, FILE_APPEND | LOCK_EX) === false) {
196+
$this->logError = true;
197+
} else {
198+
flush();
199+
}
174200
}
175201
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ It does auto deploy your site to hosting
2828

2929
http://your.domain/deploy.php?key=ytJHvMHFdTYUryDhmJkjFjFiYk
3030

31-
4. Visit page ``http://your.domain/deploy.php`` for check log history
31+
4. Visit page ``http://your.domain/deploy.php`` to check log history
3232

3333
Do not forget to change the secret code ``ytJHvMHFdTYUryDhmJkjFjFiYk``
3434

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,7 @@
2929
"dev-master": "1.2.x-dev"
3030
}
3131
},
32-
"require": {}
32+
"require": {
33+
"php": "^7.0"
34+
}
3335
}

0 commit comments

Comments
 (0)