Skip to content

Commit 49685b6

Browse files
authored
Merge pull request #8 from UrosPurtic/master
update runner with application version number
2 parents 2063493 + cff91aa commit 49685b6

4 files changed

Lines changed: 45 additions & 10 deletions

File tree

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
"g4/profiler" : ">=1.10.0",
3434
"g4/factory" : "1.*",
3535
"twig/twig" : "1.*",
36-
"twig/extensions": "^1.2"
36+
"twig/extensions": "^1.2",
37+
"g4/version": "^0.0.2"
3738
},
3839
"require-dev": {
3940
"phpunit/phpunit" : "5.*",
@@ -60,4 +61,4 @@
6061
"./vendor/bin/phpcbf --colors --standard=PSR2 src/"
6162
]
6263
}
63-
}
64+
}

src/Presenter/DataTransfer.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,32 @@ class DataTransfer
3030
*/
3131
private $response;
3232

33+
/**
34+
* @var string|null
35+
*/
36+
private $version;
3337

34-
public function __construct(HttpRequest $httpRequest, Profiler $profiler, Request $request, Response $response)
35-
{
38+
39+
public function __construct(
40+
HttpRequest $httpRequest,
41+
Profiler $profiler,
42+
Request $request,
43+
Response $response,
44+
string $version = null
45+
){
3646
$this->httpRequest = $httpRequest;
3747
$this->profiler = $profiler;
3848
$this->request = $request;
3949
$this->response = $response;
50+
$this->version = $version;
51+
}
52+
53+
/**
54+
* @return string|null
55+
*/
56+
public function getVersion()
57+
{
58+
return $this->version;
4059
}
4160

4261
/**
@@ -70,4 +89,4 @@ public function getResponse()
7089
{
7190
return $this->response;
7291
}
73-
}
92+
}

src/Presenter/Formatter/FormatterAbstract.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function getBasicData()
3030
return [
3131
'code' => $this->getDataTransfer()->getResponse()->getHttpResponseCode(),
3232
'message' => $this->getDataTransfer()->getResponse()->getHttpMessage(),
33+
'app_version' => $this->getDataTransfer()->getVersion(),
3334
'response' => $this->getDataTransfer()->getResponse()->getResponseObject(),
3435
'env' => defined(APPLICATION_ENV) ? APPLICATION_ENV : null,
3536
];

src/RunnerAbstract.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use G4\Runner\Presenter\HeaderAccept;
1212
use G4\Runner\Route\Route;
1313
use G4\Runner\Route\RouteFormatter;
14+
use G4\Version\Version;
1415

1516
abstract class RunnerAbstract implements RunnerInterface
1617
{
@@ -65,6 +66,11 @@ abstract class RunnerAbstract implements RunnerInterface
6566
*/
6667
private $route;
6768

69+
/**
70+
* @var string|null
71+
*/
72+
private $version;
73+
6874
public function __construct($headerAccept = null)
6975
{
7076
$this->profiler = new Profiler();
@@ -105,7 +111,7 @@ public function getApplicationService()
105111
*/
106112
public function getHttpRequest()
107113
{
108-
if(null === $this->httpRequest) {
114+
if (null === $this->httpRequest) {
109115
$this->httpRequest = new \G4\Http\Request();
110116
}
111117
return $this->httpRequest;
@@ -145,6 +151,12 @@ public function getRequestLogger()
145151
return $this->logger;
146152
}
147153

154+
public function setApplicationVersion(Version $version)
155+
{
156+
$this->version = $version->getVersionNumber();
157+
return $this;
158+
}
159+
148160
public function registerFormatterBasic(FormatterInterface $formatter)
149161
{
150162
$this->responseFormatter->addBasic($formatter);
@@ -158,7 +170,7 @@ public function registerFormatterVerbose(FormatterInterface $formatter)
158170
}
159171

160172
//TODO: Drasko: refactor this!
161-
public final function run()
173+
final public function run()
162174
{
163175
$this->route();
164176
$this->parseApplicationMethod();
@@ -169,7 +181,7 @@ public final function run()
169181

170182
$this->application->run();
171183

172-
if(!$this->headerAccept instanceof HeaderAccept) {
184+
if (!$this->headerAccept instanceof HeaderAccept) {
173185
$allowedMedia = $this->application->getBootstrapFactory()->getBootstrap()->getAllowedMedia();
174186
$this->headerAccept = new HeaderAccept($allowedMedia);
175187
}
@@ -198,13 +210,15 @@ private function getDataTransfer()
198210
$this->getHttpRequest(),
199211
$this->profiler,
200212
$this->application->getRequest(),
201-
$this->application->getResponse());
213+
$this->application->getResponse(),
214+
$this->version ?: null
215+
);
202216
}
203217

204218
private function getReqParams()
205219
{
206220
$params = $this->getHttpRequest()->getParams();
207-
if(isset($this->routerOptions['url_part']) && is_array($params)){
221+
if (isset($this->routerOptions['url_part']) && is_array($params)) {
208222
$params['url_part'] = $this->routerOptions['url_part'];
209223
}
210224
return $params;

0 commit comments

Comments
 (0)