1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Ember Db - An embeddable document database for php. |
4
|
|
|
* Copyright (C) 2016 Alexander During |
5
|
|
|
* |
6
|
|
|
* This program is free software: you can redistribute it and/or modify |
7
|
|
|
* it under the terms of the GNU General Public License as published by |
8
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
9
|
|
|
* (at your option) any later version. |
10
|
|
|
* |
11
|
|
|
* This program is distributed in the hope that it will be useful, |
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14
|
|
|
* GNU General Public License for more details. |
15
|
|
|
* |
16
|
|
|
* You should have received a copy of the GNU General Public License |
17
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
18
|
|
|
* |
19
|
|
|
* @link http://github.com/alexanderduring/php-ember-db |
20
|
|
|
* @copyright Copyright (C) 2016 Alexander During |
21
|
|
|
* @license http://www.gnu.org/licenses GNU General Public License v3.0 |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
namespace EmberDb\Client; |
25
|
|
|
|
26
|
|
|
use EmberDb\Client\LineReader\InjectLineReaderTrait; |
27
|
|
|
use EmberDb\Client\Parser\InjectParserTrait; |
28
|
|
|
use EmberDb\Logger; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* The main responsibility of the class Client is to continuously read |
32
|
|
|
* input lines from the user and forward them to the interpreter until |
33
|
|
|
* the exit command is given. |
34
|
|
|
* A second responsibility is to handle command line options. |
35
|
|
|
*/ |
36
|
|
|
class Client |
37
|
|
|
{ |
38
|
|
|
use InjectLineReaderTrait; |
39
|
|
|
use InjectOptionsTrait; |
40
|
|
|
use InjectParserTrait; |
41
|
|
|
use InjectServiceLocatorTrait; |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
|
45
|
|
|
public static function create() |
46
|
|
|
{ |
47
|
|
|
$serviceLocator = new ServiceLocator(); |
48
|
|
|
$client = $serviceLocator->getClient(); |
49
|
|
|
|
50
|
|
|
return $client; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
|
55
|
|
|
public function bootstrap() |
56
|
|
|
{ |
57
|
|
|
$workingDirectory = $this->options->workingDirectory; |
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
|
62
|
|
|
public function start() |
63
|
|
|
{ |
64
|
|
|
// Echo greeting |
65
|
|
|
echo "\nEmberDb command line client.\n"; |
66
|
|
|
echo "Type your command followed by <return>. Type 'help' to get a command overview or 'exit' to leave the client.\n\n"; |
67
|
|
|
|
68
|
|
|
// Start command input loop |
69
|
|
|
$quit = false; |
70
|
|
|
while (!$quit) { |
71
|
|
|
$inputLine = $this->lineReader->readline(); |
72
|
|
|
if ($inputLine == 'exit') { |
73
|
|
|
$quit = true; |
74
|
|
|
$output = "Closing EmberDb command line client.\n\n"; |
75
|
|
|
} else { |
76
|
|
|
Logger::log("Starting execution of '" . $inputLine . "'.\n"); |
77
|
|
|
$output = $this->parser->execute($inputLine); |
78
|
|
|
Logger::log("Execution finished.\n\n"); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
echo $output; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.