Skip to content

Commit 559fdf3

Browse files
authored
Merge pull request #9 from Lansoweb/php-8
update to php 8 and add new config key los -> basepath
2 parents 3a14a4d + 397c366 commit 559fdf3

12 files changed

Lines changed: 97 additions & 88 deletions

.github/workflows/validate.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,4 @@ jobs:
212212
run: "composer update --no-interaction --no-progress"
213213

214214
- name: "Run static analysis"
215-
run: "vendor/bin/psalm analyse --output-format=github"
215+
run: "vendor/bin/psalm --output-format=github"

.gitignore

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
._*
2-
.~lock.*
3-
.buildpath
4-
.project
5-
.settings
6-
vendor
7-
/composer.lock
8-
/build
9-
/.php_cs.cache
1+
/vendor
2+
composer.lock
3+
.phpunit.result.cache
4+
.php_cs.cache

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Every request with `/site` prefix will be replaced:
2727
```
2828

2929

30-
### Mezzio (formely Zend Expressive)
30+
### Mezzio (formerly Zend Expressive)
3131

3232
If you are using [mezzio-skeleton](https://github.com/mezzio/mezzio-skeleton),
3333
you can copy `config/los-basepath.global.php.dist` to `config/autoload/los-basepath.global.php`
@@ -45,9 +45,12 @@ This can be achieved with the following code in your configuration file:
4545

4646
```php
4747
$scriptPath = dirname($_SERVER['SCRIPT_NAME']);
48+
4849
return [
4950
// Use directory of script path if available, otherwise default to empty string.
50-
'los_basepath' => strlen($scriptPath) > 1 ? $scriptPath : '',
51+
'los' => [
52+
'basepath' => strlen($scriptPath) > 1 ? $scriptPath : '',
53+
],
5154

5255
// rest of the configuration ...
5356
];

config/los-basepath.global.php.dist

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22
return [
3-
'los_basepath' => '',
3+
'los' => [
4+
'basepath' => '',
5+
],
46
'dependencies' => [
57
'factories' => [
68
LosMiddleware\BasePath\BasePathMiddleware::class => LosMiddleware\BasePath\BasePathMiddlewareFactory::class

phpcs.xml.dist

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
<?xml version="1.0"?>
2-
<ruleset name="Laminas Coding Standard">
3-
<rule ref="LaminasCodingStandard"/>
2+
<ruleset name="Library Coding Standard">
43

54
<!-- Paths to check -->
65
<file>config</file>
76
<file>src</file>
7+
8+
<rule ref="Doctrine"/>
9+
<rule ref="Generic.Metrics.CyclomaticComplexity"/>
10+
<rule ref="Generic.Metrics.NestingLevel"/>
811
</ruleset>

phpstan.neon.dist

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
parameters:
2+
level: max
3+
paths:
4+
- src
5+
- config
6+
includes:
7+
- vendor/phpstan/phpstan/conf/bleedingEdge.neon

phpunit.xml

Lines changed: 0 additions & 13 deletions
This file was deleted.

phpunit.xml.dist

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0"?>
2+
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
5+
colors="true"
6+
>
7+
<coverage processUncoveredFiles="true">
8+
<include>
9+
<directory suffix=".php">src</directory>
10+
</include>
11+
<report>
12+
<text outputFile="php://stdout" showOnlySummary="true"/>
13+
</report>
14+
</coverage>
15+
<testsuites>
16+
<testsuite name="LosMiddleware\\BasePathTest">
17+
<directory>./test</directory>
18+
</testsuite>
19+
</testsuites>
20+
</phpunit>

psalm.xml.dist

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
totallyTyped="true"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns="https://getpsalm.org/schema/config"
6+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
7+
>
8+
<projectFiles>
9+
<directory name="config" />
10+
<directory name="src" />
11+
<ignoreFiles>
12+
<directory name="vendor" />
13+
</ignoreFiles>
14+
</projectFiles>
15+
</psalm>

src/BasePathMiddleware.php

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,33 @@
11
<?php
2+
3+
declare(strict_types=1);
4+
25
namespace LosMiddleware\BasePath;
36

7+
use Mezzio\Helper\UrlHelper;
48
use Psr\Http\Message\ResponseInterface;
59
use Psr\Http\Message\ServerRequestInterface;
610
use Psr\Http\Server\MiddlewareInterface;
711
use Psr\Http\Server\RequestHandlerInterface;
8-
use Mezzio\Helper\UrlHelper;
12+
13+
use function strlen;
14+
use function strpos;
15+
use function substr;
916

1017
final class BasePathMiddleware implements MiddlewareInterface
1118
{
12-
const BASE_PATH = 'los-basepath';
13-
14-
/**
15-
* @var string
16-
*/
17-
private $basePath;
18-
19-
/**
20-
* @var UrlHelper
21-
*/
22-
private $urlHelper;
23-
24-
/**
25-
* @param string $basePath
26-
* @param UrlHelper $urlHelper
27-
*/
28-
public function __construct(string $basePath = '', UrlHelper $urlHelper = null)
19+
public const BASE_PATH = 'los-basepath';
20+
21+
private string $basePath;
22+
23+
private ?UrlHelper $urlHelper;
24+
25+
public function __construct(string $basePath, ?UrlHelper $urlHelper)
2926
{
30-
$this->basePath = $basePath;
27+
$this->basePath = $basePath;
3128
$this->urlHelper = $urlHelper;
3229
}
3330

34-
/**
35-
* @param ServerRequestInterface $request
36-
* @param RequestHandlerInterface $handler
37-
* @return ResponseInterface
38-
*/
3931
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
4032
{
4133
$uri = $request->getUri();
@@ -49,7 +41,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
4941
$path = substr($path, strlen($this->basePath)) ?: '/';
5042

5143
$request = $request->withUri($uri->withPath($path));
52-
$request = $request->withAttribute(static::BASE_PATH, $this->basePath . $path);
44+
$request = $request->withAttribute(self::BASE_PATH, $this->basePath . $path);
5345

5446
if ($this->urlHelper instanceof UrlHelper) {
5547
$this->urlHelper->setBasePath($this->basePath);

0 commit comments

Comments
 (0)