Skip to content

Commit 258d88e

Browse files
authored
Merge pull request #8 from SimpleREST/develop
Develop
2 parents 8ab84ea + f7d4177 commit 258d88e

File tree

3 files changed

+65
-10
lines changed

3 files changed

+65
-10
lines changed

src/Contracts/Main/Application.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
namespace Stub\Framework\Contracts\Main;
44

5+
/**
6+
* Интерфейс приложения
7+
*/
58
interface Application
69
{
710
/**
@@ -40,6 +43,12 @@ public function getNamespace(): string;
4043
*/
4144
public function terminate();
4245

43-
public function get(string $string, string $string1);
46+
/**
47+
* Возвращает значение конфигурационного параметра заглушки по ключу
48+
* @param string $key
49+
* @param $default
50+
* @return mixed
51+
*/
52+
public function get(string $key, $default = null);
4453

4554
}

src/Main/Application.php

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,24 @@
66
use Stub\Framework\Console\Base\Output;
77
use Stub\Framework\Contracts\Main\Application as BaseApplicationContract;
88

9+
/**
10+
* Основной класс приложения (единый для консоли, http rest APi
11+
*
12+
*/
913
class Application implements BaseApplicationContract
1014
{
1115
/**
1216
* The SimpleStub framework version.
1317
*
1418
* @var string
1519
*/
16-
const VERSION = '0.0.6';
20+
const VERSION = '0.0.7';
21+
22+
/**
23+
* Массив конфигурационных параметров заглушки
24+
* @var array $params [mixed]
25+
*/
26+
private $params;
1727

1828
/**
1929
* The base path for the SimpleStub installation.
@@ -43,19 +53,32 @@ class Application implements BaseApplicationContract
4353
*/
4454
private static $output;
4555

56+
/**
57+
* Конструктор экземпляра класса приложения
58+
* @param $basePath
59+
*/
4660
public function __construct($basePath)
4761
{
4862
// self::$input = Input::getInstance();
4963
// self::$output = Output::getInstance();
64+
$this->params = include_once('./../config/config.php');
5065
if ($basePath) {
5166
$this->basePath = rtrim($basePath, '\/');
5267
}
5368
}
5469

70+
/**
71+
* Возвращает форматированную строку версии приложения / фреймворка
72+
* @return string
73+
*/
5574
public function version(): string
5675
{
57-
if (defined('STUB_APP_VERSION')) echo STUB_APP_VERSION;
58-
return static::VERSION;
76+
$formattedVersionString = "";
77+
if (defined('STUB_APP_VERSION')) {
78+
$formattedVersionString = STUB_APP_VERSION;
79+
};
80+
$formattedVersionString .= "/" . static::VERSION;
81+
return $formattedVersionString;
5982
}
6083

6184
/**
@@ -115,8 +138,15 @@ public function run(): int
115138
return 1;
116139
}
117140

118-
public function get(string $string, string $string1)
141+
/**
142+
* Gets the value of the configuration parameter.
143+
*
144+
* @param string $key
145+
* @param mixed $default
146+
* @return mixed
147+
*/
148+
function get(string $key, $default = null)
119149
{
120-
return "";
150+
return $this->params[$key] ?: $default;
121151
}
122152
}

src/Main/Http/Kernel.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,28 @@ public function hendle()
4646
*/
4747
public function sayHello(): string
4848
{
49-
// echo "Hello!! It is Console Kernel...";
50-
// return "Hi!! It is Console Kernel...";
49+
echo "Hello!! It is Console Kernel...";
50+
return "Hi!! It is Console Kernel...";
51+
}
52+
53+
/**
54+
* @return string
55+
*/
56+
public function getCurrentStub(): string
57+
{
5158
$stub = new Stub($this->app);
5259
$stub->generate($this->app);
53-
echo $stub->getDocumentResult();
60+
return $stub->getDocumentResult();
61+
}
5462

55-
return "";
63+
/**
64+
* Завершение работы приложения вывод результата пользователю
65+
* @param $request
66+
* @param $response
67+
* @return void
68+
*/
69+
public function terminate($request, $response)
70+
{
71+
exit($response);
5672
}
5773
}

0 commit comments

Comments
 (0)