Skip to content

Commit 40573c2

Browse files
authored
Merge pull request #10 from SimpleREST/develop
Develop
2 parents 258d88e + 270534e commit 40573c2

File tree

3 files changed

+53
-47
lines changed

3 files changed

+53
-47
lines changed

src/Console/Base/Output.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ public function write($message, bool $newline = false)
2929

3030
public function writeln($message)
3131
{
32-
echo $message;
33-
echo "\r\n";
32+
if (is_array($message)){
33+
var_dump($message);
34+
} else {
35+
echo $message;
36+
echo "\r\n";
37+
}
38+
3439
}
3540
}

src/Main/Application.php

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace Stub\Framework\Main;
44

5-
use Stub\Framework\Console\Base\Input;
6-
use Stub\Framework\Console\Base\Output;
75
use Stub\Framework\Contracts\Main\Application as BaseApplicationContract;
86

97
/**
@@ -17,7 +15,7 @@ class Application implements BaseApplicationContract
1715
*
1816
* @var string
1917
*/
20-
const VERSION = '0.0.7';
18+
const VERSION = '0.0.8';
2119

2220
/**
2321
* Массив конфигурационных параметров заглушки
@@ -39,32 +37,17 @@ class Application implements BaseApplicationContract
3937
*/
4038
protected $namespace;
4139

42-
/**
43-
* Поток ввода.
44-
*
45-
* @var Input
46-
*/
47-
private static $input;
48-
49-
/**
50-
* Поток вывода.
51-
*
52-
* @var Output
53-
*/
54-
private static $output;
5540

5641
/**
5742
* Конструктор экземпляра класса приложения
5843
* @param $basePath
5944
*/
6045
public function __construct($basePath)
6146
{
62-
// self::$input = Input::getInstance();
63-
// self::$output = Output::getInstance();
64-
$this->params = include_once('./../config/config.php');
6547
if ($basePath) {
6648
$this->basePath = rtrim($basePath, '\/');
6749
}
50+
$this->params = include_once($this->basePath.'\config\config.php');
6851
}
6952

7053
/**
@@ -81,22 +64,6 @@ public function version(): string
8164
return $formattedVersionString;
8265
}
8366

84-
/**
85-
* @return Input|null
86-
*/
87-
public static function getInput(): Input
88-
{
89-
return self::$input;
90-
}
91-
92-
/**
93-
* @return Output
94-
*/
95-
public static function getOutput(): Output
96-
{
97-
return self::$output;
98-
}
99-
10067
public function terminate(): string
10168
{
10269
return "Работа приложения завершается!";

src/Main/Console/Kernel.php

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
namespace Stub\Framework\Main\Console;
44

55
use DateTime;
6-
use Stub\Framework\Contracts\Console\Input;
7-
use Stub\Framework\Contracts\Console\Output;
6+
use Stub\Framework\Console\Base\Command;
7+
use Stub\Framework\Console\Base\Input;
8+
use Stub\Framework\Console\Base\Output;
9+
use Stub\Framework\Contracts\Console\Input as InputContract;
10+
use Stub\Framework\Contracts\Console\Output as OutputContract;
811
use Stub\Framework\Contracts\Main\Application;
912
use Throwable;
1013

@@ -25,6 +28,16 @@ class Kernel implements \Stub\Framework\Contracts\Console\Kernel
2528
*/
2629
protected $commandStartedDateTime;
2730

31+
/**
32+
* @var InputContract
33+
*/
34+
protected $input;
35+
36+
/**
37+
* @var OutputContract
38+
*/
39+
protected $output;
40+
2841
/**
2942
* Создает новый экземпляр ядра консоли
3043
* @param Application $app
@@ -33,25 +46,46 @@ class Kernel implements \Stub\Framework\Contracts\Console\Kernel
3346
public function __construct(Application $app)
3447
{
3548
$this->app = $app;
36-
self::hendle($app::getInput(), $app::getOutput());
49+
$this->input = Input::getInstance();
50+
$this->output = Output::getInstance();
51+
self::handle();
3752
}
3853

39-
public function hendle(Input $input, Output $output)
54+
public function handle()
4055
{
4156
$this->commandStartedDateTime = new DateTime();
4257
try {
43-
echo "Из потока ввода беру набор команд т.е. конкретно то, что мне выдаст метод ";
44-
echo "И именно под защитой данной конструкции выполняем непосредственно передачу команды
45-
на отработку приложению";
58+
$this->output->writeln($this->input->getArguments()[1]);
59+
$className = "Stub\Framework\Console\Commands\\".$this->input->getArguments()[1] . 'Command';
60+
$this->output->writeln($className);
61+
$this->execute(new $className());
4662
} catch (Throwable $e) {
47-
echo "Это на случай если ошибка возникнет, ее нужно передать на обработку (оформление) добавить к ней
48-
данные разные окружения и уже потом выдать на гора...";
63+
$this->output->writeln("Это на случай если ошибка возникнет, ее нужно передать на обработку (оформление) добавить к ней
64+
данные разные окружения и уже потом выдать на гора...");
4965
}
5066
}
5167

68+
protected function execute(Command $command)
69+
{
70+
$this->output->writeln("Выполняю конкретную команду");
71+
$this->output->writeln($command->getName());
72+
$this->output->writeln("Завершаю выполнение команды");
73+
}
74+
5275
public function sayHello(): string
5376
{
54-
echo "Hello!! It is Console Kernel...";
77+
$this->output->writeln("Hello!! It is Console Kernel...");
5578
return "Hi!! It is Console Kernel...";
5679
}
80+
81+
/**
82+
* Завершение работы приложения вывод результата пользователю
83+
* @param $request
84+
* @param $response
85+
* @return void
86+
*/
87+
public function terminate($request, $response)
88+
{
89+
exit($response);
90+
}
5791
}

0 commit comments

Comments
 (0)