Skip to content

Commit b06966b

Browse files
authored
Merge pull request #12 from peckadesign/3800-php8
pdp#3800: Podpora PHP 8
2 parents 3d2e0ef + 4ad27d4 commit b06966b

14 files changed

+183
-115
lines changed

.github/workflows/php-package-ci.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
runs-on: ubuntu-latest
1010
strategy:
1111
matrix:
12-
php: [ 7.1, 7.2, 7.3, 7.4 ]
12+
php: [ 7.4, 8.0 ]
1313
steps:
1414
- uses: actions/checkout@v2
1515
- uses: shivammathur/setup-php@v2
@@ -18,5 +18,6 @@ jobs:
1818

1919
- run: make composer
2020

21-
- if: matrix.php == '7.4'
22-
run: make phpstan
21+
- run: make phpstan
22+
23+
- run: make tester

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@ composer:
33
composer update --no-interaction --prefer-dist
44

55
phpstan:
6-
vendor/bin/phpstan analyse -l 5 src/ --no-progress --error-format github
6+
vendor/bin/phpstan analyse -l 6 src/ --no-progress --error-format github
7+
8+
tester:
9+
vendor/bin/tester tests

composer.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@
2323
}
2424
],
2525
"require": {
26-
"php": "~7.1",
27-
"nette/application": "~2.4.14|~3.0.0",
28-
"nette/di": "~2.4.14|~3.0.0",
29-
"kdyby/console": "~2.7.1|dev-master",
30-
"supervisorphp/configuration": "~0.2.1"
26+
"php": "^7.4 | ^8.0",
27+
"nette/application": "^3.0.0",
28+
"nette/di": "~3.0.0",
29+
"kdyby/console": "~4.2.0|dev-master",
30+
"supervisorphp/configuration": "^0.3"
3131
},
3232
"require-dev": {
33-
"phpstan/phpstan": "0.12.76"
33+
"phpstan/phpstan": "0.12.88",
34+
"nette/tester": "^2.4"
3435
},
3536
"autoload": {
3637
"psr-4": {

src/Adapter/Nette/DI/CompilerExtensionAdapter.php

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

src/Adapter/Nette/DI/DiStatementFactory.php

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

src/Console/RenderCommand.php

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
namespace Pd\Supervisor\Console;
44

5-
use Nette\DI\Container;
6-
use Supervisor\Configuration\Configuration;
7-
use Supervisor\Configuration\Writer\HasIniRenderer;
85
use Symfony\Component\Console\Command\Command;
96
use Symfony\Component\Console\Input\InputInterface;
107
use Symfony\Component\Console\Output\OutputInterface;
@@ -13,35 +10,33 @@
1310
final class RenderCommand extends Command
1411
{
1512

16-
use HasIniRenderer;
13+
private \Supervisor\Configuration\Configuration $configuration;
1714

18-
/**
19-
* @var Container
20-
*/
21-
private $container;
15+
private \Indigo\Ini\Renderer $renderer;
2216

2317

24-
public function __construct(string $name, Container $container)
18+
public function __construct(
19+
string $name,
20+
\Supervisor\Configuration\Configuration $configuration,
21+
\Indigo\Ini\Renderer $renderer
22+
)
2523
{
2624
parent::__construct($name);
27-
$this->container = $container;
25+
$this->configuration = $configuration;
26+
$this->renderer = $renderer;
2827
}
2928

3029

31-
protected function configure()
30+
protected function configure(): void
3231
{
3332
parent::configure();
3433
$this->setDescription('Renders supervisor configuration');
3534
}
3635

3736

38-
protected function execute(InputInterface $input, OutputInterface $output)
37+
protected function execute(InputInterface $input, OutputInterface $output): int
3938
{
40-
/**
41-
* @var Configuration $configuration
42-
*/
43-
$configuration = $this->container->getByType(Configuration::class);
44-
$output->write($this->getRenderer()->render($configuration->toArray()));
39+
$output->write($this->renderer->render($this->configuration->toArray()));
4540

4641
return 0;
4742
}

src/Console/WriteCommand.php

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22

33
namespace Pd\Supervisor\Console;
44

5-
use League\Flysystem\Adapter\Local;
6-
use League\Flysystem\Filesystem;
7-
use Nette\DI\Container;
8-
use Supervisor\Configuration\Configuration;
95
use Supervisor\Configuration\Exception\LoaderException;
106
use Supervisor\Configuration\Loader\IniFileLoader;
117
use Supervisor\Configuration\Writer\IniFileWriter;
@@ -19,20 +15,17 @@
1915
final class WriteCommand extends Command
2016
{
2117

22-
/**
23-
* @var Container
24-
*/
25-
private $container;
18+
private \Supervisor\Configuration\Configuration $configuration;
2619

2720

28-
public function __construct(string $name, Container $container)
21+
public function __construct(string $name, \Supervisor\Configuration\Configuration $configuration)
2922
{
3023
parent::__construct($name);
31-
$this->container = $container;
24+
$this->configuration = $configuration;
3225
}
3326

3427

35-
protected function configure()
28+
protected function configure(): void
3629
{
3730
parent::configure();
3831
$this->setDescription('Writes supervisor configuration to file');
@@ -41,30 +34,28 @@ protected function configure()
4134
}
4235

4336

44-
protected function execute(InputInterface $input, OutputInterface $output)
37+
protected function execute(InputInterface $input, OutputInterface $output): int
4538
{
46-
$filesystemAdapter = new Local(getcwd());
47-
$filesystem = new Filesystem($filesystemAdapter);
4839
$file = $input->getArgument('file');
49-
$writer = new IniFileWriter($filesystem, $file);
50-
/**
51-
* @var Configuration $configuration
52-
*/
53-
$configuration = $this->container->getByType(Configuration::class);
40+
$writer = new IniFileWriter($file);
41+
5442
if ($input->getOption('merge')) {
55-
$loader = new IniFileLoader($filesystem, $file);
43+
$loader = new IniFileLoader($file);
5644
try {
57-
$loader->load($configuration);
45+
$loader->load($this->configuration);
5846
} catch (LoaderException $exception) {
5947
$output->writeln($exception->getMessage());
6048

6149
return 1;
6250
}
6351
}
64-
if ($writer->write($configuration)) {
65-
$output->writeln(sprintf('Supervisor configuration has been successfully written to file %s', $filesystemAdapter->applyPathPrefix($file)));
52+
try {
53+
$writer->write($this->configuration);
54+
$output->writeln(sprintf('Supervisor configuration has been successfully written to file %s', $file));
6655

6756
return 0;
57+
} catch (\Supervisor\Configuration\Exception\WriterException $e) {
58+
$output->writeln($e->getMessage());
6859
}
6960

7061
return 1;

src/DI/IConfigurationProvider.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,9 @@
55
interface IConfigurationProvider
66
{
77

8+
/**
9+
* @return array<string, mixed>
10+
*/
811
public function getSupervisorConfiguration(): array;
12+
913
}

src/DI/SupervisorExtension.php

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,11 @@
1515
final class SupervisorExtension extends CompilerExtension
1616
{
1717

18-
const DEFAULTS = [
19-
'prefix' => NULL,
20-
'configuration' => [],
21-
'defaults' => [],
22-
'group' => NULL,
23-
];
24-
25-
26-
public function loadConfiguration()
18+
public function loadConfiguration(): void
2719
{
2820
$builder = $this->getContainerBuilder();
2921

30-
$config = \Pd\Supervisor\Adapter\Nette\DI\CompilerExtensionAdapter::mergeConfigWithDefaults($this, self::DEFAULTS);
22+
$config = $this->getConfig();
3123

3224
if ( ! isset($config['prefix'])) {
3325
throw new \Pd\Supervisor\DI\MissingConfigurationValueException(
@@ -48,6 +40,12 @@ public function loadConfiguration()
4840
isset($config['group']) ? (string) $config['group'] : NULL
4941
);
5042

43+
$builder->addDefinition($this->prefix('renderer'))
44+
->setFactory(\Indigo\Ini\Renderer::class, [
45+
\Indigo\Ini\Renderer::ARRAY_MODE_CONCAT | \Indigo\Ini\Renderer::BOOLEAN_MODE_BOOL_STRING,
46+
])
47+
;
48+
5149
$builder->addDefinition($this->prefix('renderCommand'))
5250
->setFactory(RenderCommand::class, [strtr($this->prefix('render'), '.', ':')])
5351
->addTag(ConsoleExtension::TAG_COMMAND)
@@ -59,7 +57,22 @@ public function loadConfiguration()
5957
}
6058

6159

62-
private function loadSupervisorConfiguration(array $config, array $defaults = [], string $prefix, string $group = NULL)
60+
public function getConfigSchema(): \Nette\Schema\Schema
61+
{
62+
return \Nette\Schema\Expect::structure([
63+
'prefix' => \Nette\Schema\Expect::string()->nullable(),
64+
'configuration' => \Nette\Schema\Expect::array(),
65+
'defaults' => \Nette\Schema\Expect::array(),
66+
'group' => \Nette\Schema\Expect::string()->nullable(),
67+
]);
68+
}
69+
70+
71+
/**
72+
* @param array<string, mixed> $config
73+
* @param array<string, mixed> $defaults
74+
*/
75+
private function loadSupervisorConfiguration(array $config, array $defaults, string $prefix, ?string $group): void
6376
{
6477
$builder = $this->getContainerBuilder();
6578

@@ -75,15 +88,15 @@ private function loadSupervisorConfiguration(array $config, array $defaults = []
7588
foreach ((array) $sectionConfig as $name => $properties) {
7689
$name = $this->prepareName($name, $prefix);
7790
$configuration->addSetup('addSection', [
78-
\Pd\Supervisor\Adapter\Nette\DI\DiStatementFactory::createDiStatement($sectionClass, [
91+
new \Nette\DI\Definitions\Statement($sectionClass, [
7992
$name,
8093
isset($defaults[$sectionName]) ? $this->mergeProperties($properties, $defaults[$sectionName]) : $properties,
8194
]),
8295
]);
8396
}
8497
} else {
8598
$configuration->addSetup('addSection', [
86-
\Pd\Supervisor\Adapter\Nette\DI\DiStatementFactory::createDiStatement(
99+
new \Nette\DI\Definitions\Statement(
87100
$sectionClass, [
88101
isset($defaults[$sectionName]) ? $this->mergeProperties($sectionConfig, $defaults[$sectionName]) : $sectionConfig,
89102
]),
@@ -95,6 +108,11 @@ private function loadSupervisorConfiguration(array $config, array $defaults = []
95108
}
96109

97110

111+
/**
112+
* @param array<string, mixed> $properties
113+
* @param array<string, mixed> $defaults
114+
* @return array<string, mixed>
115+
*/
98116
private function mergeProperties(array $properties, array $defaults = []): array
99117
{
100118
foreach ($defaults as $key => $value) {
@@ -121,9 +139,10 @@ private function prepareName(string $name, string $prefix): string
121139

122140

123141
/**
142+
* @param array<string, mixed> $config
124143
* @param \Nette\DI\ServiceDefinition|\Nette\DI\Definitions\ServiceDefinition $configuration
125144
*/
126-
private function prepareGroup(array $config, $configuration, string $prefix, string $group = NULL): void
145+
private function prepareGroup(array $config, $configuration, string $prefix, ?string $group): void
127146
{
128147
if ( ! $group) {
129148
return;
@@ -135,7 +154,7 @@ private function prepareGroup(array $config, $configuration, string $prefix, str
135154

136155
$sectionClass = (new Configuration)->findSection('group');
137156
$configuration->addSetup('addSection', [
138-
\Pd\Supervisor\Adapter\Nette\DI\DiStatementFactory::createDiStatement(
157+
new \Nette\DI\Definitions\Statement(
139158
$sectionClass,
140159
[
141160
$group,

tests/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
output
2+
Console/output.ini

tests/Console/DebugOutput.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PdTests\Supervisor\Console;
4+
5+
class DebugOutput extends \Symfony\Component\Console\Output\Output
6+
{
7+
8+
private string $output = '';
9+
10+
protected function doWrite($message, $newline)
11+
{
12+
$this->output .= $message.($newline ? "\n" : '');
13+
}
14+
15+
16+
public function getOutput(): string
17+
{
18+
return $this->output;
19+
}
20+
21+
}

0 commit comments

Comments
 (0)