Skip to content

Commit b234d91

Browse files
authored
Merge pull request ipublikuj-archive#12 from elcheco/nette3
Upgrade to Nette3
2 parents cfdc3a9 + 93b73b2 commit b234d91

File tree

10 files changed

+81
-75
lines changed

10 files changed

+81
-75
lines changed

.scrutinizer.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ checks:
44
build:
55
environment:
66
php:
7-
version: 7.1
7+
version: 7.2
88
variables:
99
NETTE: default
1010

.travis.composer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
$file = __DIR__ . '/composer.json';
1212
$content = file_get_contents($file);
13-
$composer = json_decode($content, TRUE);
13+
$composer = json_decode($content, true);
1414
$composer['require']['nette/application'] = $version;
1515
$composer['require']['nette/di'] = $version;
1616
$composer['require']['nette/http'] = $version;

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ language: php
22

33
env:
44
- NETTE=default
5-
- NETTE=~2.4.0
5+
- NETTE=~3.0.0
66

77
php:
8-
- 7.1
98
- 7.2
9+
- 7.3
1010

1111
before_install:
1212
- composer self-update

composer.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,26 +57,26 @@
5757
},
5858

5959
"require": {
60-
"php" : ">=7.1.0",
60+
"php" : ">=7.2.0",
6161

62-
"nette/application" : "~2.4",
63-
"nette/di" : "~2.4",
64-
"nette/http" : "~2.4",
65-
"nette/utils" : "~2.4",
62+
"nette/application" : "~3.0",
63+
"nette/di" : "~3.0",
64+
"nette/http" : "~3.0",
65+
"nette/utils" : "~3.0",
6666

67-
"latte/latte" : "~2.4",
67+
"latte/latte" : "~2.5",
6868

6969
"jenssegers/agent" : "~2.5"
7070
},
7171

7272
"require-dev": {
73-
"nette/bootstrap" : "~2.4",
74-
"nette/mail" : "~2.4",
75-
"nette/robot-loader" : "~2.4",
76-
"nette/safe-stream" : "~2.3",
77-
"nette/tester" : "~2.0",
73+
"nette/bootstrap" : "~3.0",
74+
"nette/mail" : "~3.0",
75+
"nette/robot-loader" : "~3.0",
76+
"nette/safe-stream" : "~2.4",
77+
"nette/tester" : "~2.3",
7878

79-
"tracy/tracy" : "~2.4",
79+
"tracy/tracy" : "~2.6",
8080

8181
"pds/skeleton" : "~1.0"
8282
},

src/IPub/MobileDetect/DI/MobileDetectExtension.php

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,37 +44,37 @@ final class MobileDetectExtension extends DI\CompilerExtension
4444
private $defaults = [
4545
'redirect' => [
4646
'mobile' => [
47-
'isEnabled' => FALSE,
48-
'host' => NULL,
47+
'isEnabled' => false,
48+
'host' => null,
4949
'statusCode' => 301,
5050
'action' => 'noRedirect', // redirect/noRedirect/redirectWithoutPath
5151
],
5252
'phone' => [
53-
'isEnabled' => FALSE,
54-
'host' => NULL,
53+
'isEnabled' => false,
54+
'host' => null,
5555
'statusCode' => 301,
5656
'action' => 'noRedirect', // redirect/noRedirect/redirectWithoutPath
5757
],
5858
'tablet' => [
59-
'isEnabled' => FALSE,
60-
'host' => NULL,
59+
'isEnabled' => false,
60+
'host' => null,
6161
'statusCode' => 301,
6262
'action' => 'noRedirect', // redirect/noRedirect/redirectWithoutPath
6363
],
64-
'detectPhoneAsMobile' => FALSE,
65-
'detectTabletAsMobile' => FALSE,
64+
'detectPhoneAsMobile' => false,
65+
'detectTabletAsMobile' => false,
6666
],
6767
'switchDeviceView' => [
68-
'saveRefererPath' => TRUE
68+
'saveRefererPath' => true
6969
],
7070
'switchParameterName' => 'device_view',
7171
'deviceViewCookie' => [
7272
'name' => 'device_view',
73-
'domain' => NULL,
73+
'domain' => null,
7474
'expireAfter' => '+1 month',
7575
'path' => '/',
76-
'secure' => FALSE,
77-
'httpOnly' => TRUE,
76+
'secure' => false,
77+
'httpOnly' => true,
7878
],
7979
'debugger' => '%debugMode%'
8080
];
@@ -86,8 +86,12 @@ public function loadConfiguration() : void
8686
{
8787
// Get container builder
8888
$builder = $this->getContainerBuilder();
89+
90+
// Set the default configuration
91+
$this->validateConfig($this->defaults);
92+
8993
// Get extension configuration
90-
$configuration = $this->getConfig($this->defaults);
94+
$configuration = $this->getConfig();
9195

9296
// Install mobile detect service
9397
$mobileDetect = $builder->addDefinition($this->prefix('mobileDetect'))
@@ -145,7 +149,7 @@ public function beforeCompile() : void
145149
// Install extension latte macros
146150
$latteFactory = $builder->getDefinition($builder->getByType(Bridges\ApplicationLatte\ILatteFactory::class) ?: 'nette.latteFactory');
147151

148-
$latteFactory
152+
$latteFactory->getResultDefinition()
149153
->addSetup('IPub\MobileDetect\Latte\Macros::install(?->getCompiler())', ['@self'])
150154
->addSetup('addFilter', ['isMobile', [$this->prefix('@helpers'), 'isMobile']])
151155
->addSetup('addFilter', ['isPhone', [$this->prefix('@helpers'), 'isPhone']])

src/IPub/MobileDetect/Events/OnRequestHandler.php

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ final class OnRequestHandler
4949
/**
5050
* @var bool
5151
*/
52-
public $isFullPath = TRUE;
52+
public $isFullPath = true;
5353

5454
/**
5555
* @var Http\IRequest
@@ -207,27 +207,27 @@ public function __invoke(Application\Application $application) : void
207207
private function hasPhoneRedirect() : bool
208208
{
209209
if (!$this->redirectConf['phone']['isEnabled']) {
210-
return FALSE;
210+
return false;
211211
}
212212

213213
$isPhone = $this->mobileDetect->isPhone();
214214

215-
if ($this->redirectConf['detectPhoneAsMobile'] === FALSE) {
215+
if ($this->redirectConf['detectPhoneAsMobile'] === false) {
216216
$isPhoneHost = ($this->getCurrentHost() === $this->redirectConf['phone']['host']);
217217

218218
if ($isPhone && !$isPhoneHost && ($this->getRoutingOption(self::PHONE) != self::NO_REDIRECT)) {
219-
return TRUE;
219+
return true;
220220
}
221221

222222
} else {
223223
$isMobileHost = ($this->getCurrentHost() === $this->redirectConf['mobile']['host']);
224224

225225
if ($isPhone && !$isMobileHost && ($this->getRoutingOption(self::PHONE) != self::NO_REDIRECT)) {
226-
return TRUE;
226+
return true;
227227
}
228228
}
229229

230-
return FALSE;
230+
return false;
231231
}
232232

233233
/**
@@ -238,27 +238,27 @@ private function hasPhoneRedirect() : bool
238238
private function hasTabletRedirect() : bool
239239
{
240240
if (!$this->redirectConf['tablet']['isEnabled']) {
241-
return FALSE;
241+
return false;
242242
}
243243

244244
$isTablet = $this->mobileDetect->isTablet();
245245

246-
if ($this->redirectConf['detectTabletAsMobile'] === FALSE) {
246+
if ($this->redirectConf['detectTabletAsMobile'] === false) {
247247
$isTabletHost = ($this->getCurrentHost() === $this->redirectConf['tablet']['host']);
248248

249249
if ($isTablet && !$isTabletHost && ($this->getRoutingOption(self::TABLET) != self::NO_REDIRECT)) {
250-
return TRUE;
250+
return true;
251251
}
252252

253253
} else {
254254
$isMobileHost = ($this->getCurrentHost() === $this->redirectConf['mobile']['host']);
255255

256256
if ($isTablet && !$isMobileHost && ($this->getRoutingOption(self::TABLET) != self::NO_REDIRECT)) {
257-
return TRUE;
257+
return true;
258258
}
259259
}
260260

261-
return FALSE;
261+
return false;
262262
}
263263

264264
/**
@@ -269,13 +269,13 @@ private function hasTabletRedirect() : bool
269269
private function hasMobileRedirect() : bool
270270
{
271271
if (!$this->redirectConf['mobile']['isEnabled']) {
272-
return FALSE;
272+
return false;
273273
}
274274

275-
if ($this->redirectConf['detectPhoneAsMobile'] === FALSE) {
275+
if ($this->redirectConf['detectPhoneAsMobile'] === false) {
276276
$isMobile = ($this->mobileDetect->isTablet() || ($this->mobileDetect->isMobile()) && !$this->mobileDetect->isPhone());
277277

278-
} elseif ($this->redirectConf['detectTabletAsMobile'] === FALSE) {
278+
} elseif ($this->redirectConf['detectTabletAsMobile'] === false) {
279279
$isMobile = ($this->mobileDetect->isPhone() || ($this->mobileDetect->isMobile()) && !$this->mobileDetect->isTablet());
280280

281281
} else {
@@ -285,10 +285,10 @@ private function hasMobileRedirect() : bool
285285
$isMobileHost = ($this->getCurrentHost() === $this->redirectConf['mobile']['host']);
286286

287287
if ($isMobile && !$isMobileHost && ($this->getRoutingOption(self::MOBILE) != self::NO_REDIRECT)) {
288-
return TRUE;
288+
return true;
289289
}
290290

291-
return FALSE;
291+
return false;
292292
}
293293

294294
/**
@@ -298,15 +298,15 @@ private function hasMobileRedirect() : bool
298298
*/
299299
private function needPhoneResponseModify() : bool
300300
{
301-
if (($this->deviceView->getViewType() === NULL || $this->deviceView->isPhoneView()) && $this->mobileDetect->isMobile() && !$this->mobileDetect->isTablet()) {
301+
if (($this->deviceView->getViewType() === null || $this->deviceView->isPhoneView()) && $this->mobileDetect->isMobile() && !$this->mobileDetect->isTablet()) {
302302
$this->onResponseHandler->modifyResponseClosure = function (Helpers\DeviceView $deviceView) : Http\IResponse {
303303
return $deviceView->modifyPhoneResponse();
304304
};
305305

306-
return TRUE;
306+
return true;
307307
}
308308

309-
return FALSE;
309+
return false;
310310
}
311311

312312
/**
@@ -316,15 +316,15 @@ private function needPhoneResponseModify() : bool
316316
*/
317317
private function needTabletResponseModify() : bool
318318
{
319-
if (($this->deviceView->getViewType() === NULL || $this->deviceView->isTabletView()) && $this->mobileDetect->isTablet()) {
319+
if (($this->deviceView->getViewType() === null || $this->deviceView->isTabletView()) && $this->mobileDetect->isTablet()) {
320320
$this->onResponseHandler->modifyResponseClosure = function (Helpers\DeviceView $deviceView) : Http\IResponse {
321321
return $deviceView->modifyTabletResponse();
322322
};
323323

324-
return TRUE;
324+
return true;
325325
}
326326

327-
return FALSE;
327+
return false;
328328
}
329329

330330
/**
@@ -334,15 +334,15 @@ private function needTabletResponseModify() : bool
334334
*/
335335
private function needMobileResponseModify() : bool
336336
{
337-
if (($this->deviceView->getViewType() === NULL || $this->deviceView->isMobileView()) && $this->mobileDetect->isMobile()) {
337+
if (($this->deviceView->getViewType() === null || $this->deviceView->isMobileView()) && $this->mobileDetect->isMobile()) {
338338
$this->onResponseHandler->modifyResponseClosure = function (Helpers\DeviceView $deviceView) : Http\IResponse {
339339
return $deviceView->modifyMobileResponse();
340340
};
341341

342-
return TRUE;
342+
return true;
343343
}
344344

345-
return FALSE;
345+
return false;
346346
}
347347

348348
/**
@@ -352,15 +352,15 @@ private function needMobileResponseModify() : bool
352352
*/
353353
private function needNotMobileResponseModify() : bool
354354
{
355-
if ($this->deviceView->getViewType() === NULL || $this->deviceView->isNotMobileView()) {
355+
if ($this->deviceView->getViewType() === null || $this->deviceView->isNotMobileView()) {
356356
$this->onResponseHandler->modifyResponseClosure = function (Helpers\DeviceView $deviceView) : Http\IResponse {
357357
return $deviceView->modifyNotMobileResponse();
358358
};
359359

360-
return TRUE;
360+
return true;
361361
}
362362

363-
return FALSE;
363+
return false;
364364
}
365365

366366
/**
@@ -371,12 +371,12 @@ private function needNotMobileResponseModify() : bool
371371
private function getRedirectResponseBySwitchParam() : Responses\RedirectResponse
372372
{
373373
// Generate full url path
374-
if ($this->isFullPath === TRUE) {
374+
if ($this->isFullPath === true) {
375375
// Get actual url
376376
$url = $this->httpRequest->getUrl();
377377

378378
// Remove switch param
379-
$url->setQueryParameter($this->deviceView->getSwitchParameterName(), NULL);
379+
$url->setQueryParameter($this->deviceView->getSwitchParameterName(), null);
380380

381381
// Create full path url
382382
$redirectUrl = $this->getCurrentHost() . $url->getRelativeUrl();
@@ -405,7 +405,7 @@ private function getDeviceRedirectResponse(string $device) : ?Responses\Redirect
405405
);
406406
}
407407

408-
return NULL;
408+
return null;
409409
}
410410

411411
/**
@@ -427,7 +427,7 @@ private function getRedirectUrl(string $platform) : ?string
427427
}
428428
}
429429

430-
return NULL;
430+
return null;
431431
}
432432

433433
/**
@@ -439,14 +439,14 @@ private function getRedirectUrl(string $platform) : ?string
439439
*/
440440
private function getRoutingOption(string $name) : ?string
441441
{
442-
$option = NULL;
442+
$option = null;
443443

444444
// Get actual route
445445
$request = $this->router->match($this->httpRequest);
446446

447447
if ($request instanceof Application\Request) {
448448
$params = $request->getParameters();
449-
$option = isset($params[$name]) ? $params[$name] : NULL;
449+
$option = isset($params[$name]) ? $params[$name] : null;
450450
}
451451

452452
if (!$option) {
@@ -457,7 +457,7 @@ private function getRoutingOption(string $name) : ?string
457457
return $option;
458458
}
459459

460-
return NULL;
460+
return null;
461461
}
462462

463463
/**

0 commit comments

Comments
 (0)