Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,9 @@ jobs:
with:
php: "8.2"

test81:
name: "Nette Tester"
uses: contributte/.github/.github/workflows/nette-tester.yml@master
with:
php: "8.1"

testlower:
name: "Nette Tester"
uses: contributte/.github/.github/workflows/nette-tester.yml@master
with:
php: "8.1"
php: "8.2"
composer: "composer update --no-interaction --no-progress --prefer-dist --prefer-stable --prefer-lowest"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ For details on how to use this package, check out our [documentation](.docs).

| State | Version | Branch | Nette | PHP |
|--------|-----------|----------|--------|---------|
| dev | `^0.11.0` | `master` | `3.2+` | `>=8.1` |
| dev | `^0.11.0` | `master` | `3.2+` | `>=8.2` |
| stable | `^0.10.0` | `master` | `3.2+` | `>=8.1` |


Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@
}
],
"require": {
"php": ">=8.1",
"php": ">=8.2",
"nette/di": "^3.1.8",
"symfony/console": "^6.4.2 || ^7.0.2"
"symfony/console": "^6.4.2 || ^7.0.2 || ^8.0.0"
},
"require-dev": {
"nette/http": "^3.2.3",
"contributte/qa": "^0.4",
"contributte/tester": "^0.4",
"contributte/phpstan": "^0.1",
"mockery/mockery": "^1.6.7",
"symfony/event-dispatcher": "^6.4.2 || ^7.0.2"
"contributte/phpstan": "^0.2",
"mockery/mockery": "^1.6.12",
"symfony/event-dispatcher": "^6.4.2 || ^7.0.2 || ^8.0.0"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ includes:

parameters:
level: 9
phpVersion: 80100
phpVersion: 80200

scanDirectories:
- src
Expand Down
2 changes: 1 addition & 1 deletion ruleset.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="Contributte" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
<!-- Rulesets -->
<rule ref="./vendor/contributte/qa/ruleset-8.0.xml"/>
<rule ref="./vendor/contributte/qa/ruleset-8.2.xml"/>

<!-- Rules -->
<rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName">
Expand Down
12 changes: 4 additions & 8 deletions src/CommandLoader/ContainerCommandLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,14 @@
class ContainerCommandLoader implements CommandLoaderInterface
{

private Container $container;

/** @var array<string> */
private array $commandMap;

/**
* @param array<string> $commandMap
*/
public function __construct(Container $container, array $commandMap)
public function __construct(
private readonly Container $container,
private readonly array $commandMap,
)
{
$this->container = $container;
$this->commandMap = $commandMap;
}

public function get(string $name): Command
Expand Down
32 changes: 24 additions & 8 deletions src/DI/ConsoleExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
use Nette\Schema\Expect;
use Nette\Schema\Schema;
use Nette\Utils\Arrays;
use ReflectionClass;
use ReflectionProperty;
use stdClass;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\CommandLoader\CommandLoaderInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
Expand All @@ -25,11 +28,10 @@
class ConsoleExtension extends CompilerExtension
{

private bool $cliMode;

public function __construct(bool $cliMode = false)
public function __construct(
private readonly bool $cliMode = false,
)
{
$this->cliMode = $cliMode;
}

public function getConfigSchema(): Schema
Expand Down Expand Up @@ -158,17 +160,31 @@ public function beforeCompile(): void
}

$aliases = [];
// Try to detect command name from Command::getDefaultName()
if ($commandName === null) {
$commandName = call_user_func([$service->getType(), 'getDefaultName']); // @phpstan-ignore-line
if ($commandName === null) {
// Try to detect command name from Command::getDefaultName() or Command::defaultName property
if (!is_string($commandName) || $commandName === '') {
/** @var class-string $className */
$className = $service->getType();
$reflection = new ReflectionClass($className);
$attributes = $reflection->getAttributes(AsCommand::class);

if ($attributes !== []) {
$commandName = $attributes[0]->newInstance()->name;
} elseif (method_exists($className, 'getDefaultName')) {
$commandName = call_user_func([$service->getType(), 'getDefaultName']); // @phpstan-ignore-line
} elseif (property_exists($className, 'defaultName')) {
$rp = new ReflectionProperty($className, 'defaultName');
$commandName = $rp->getValue();
}

if (!is_string($commandName) || $commandName === '') {
throw new ServiceCreationException(
sprintf(
'Command "%s" missing #[AsCommand] attribute',
$service->getType(),
)
);
}

$aliases = explode('|', $commandName);
$commandName = array_shift($aliases);
if ($commandName === '') {
Expand Down
7 changes: 3 additions & 4 deletions src/Http/ConsoleRequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
class ConsoleRequestFactory extends RequestFactory
{

private string $url;

public function __construct(string $url)
public function __construct(
private readonly string $url,
)
{
$this->url = $url;
}

public function fromGlobals(): Request
Expand Down