Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/3.0' into maintenance/debug-php-81
Browse files Browse the repository at this point in the history
  • Loading branch information
msmakouz committed Mar 25, 2022
2 parents 9ac92bc + 06a5b93 commit e2ab6d8
Show file tree
Hide file tree
Showing 115 changed files with 506 additions and 3,124 deletions.
1 change: 1 addition & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
risky: false
version: 8.1
preset: psr12
enabled:
# Risky Fixers
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@
- [spiral/validation] Removed deprecated methods `datetime` and `timezone` in the
`Spiral\Validation\Checker\TypeChecker` class. Use `Spiral\Validation\Checker\DatetimeChecker::valid()` and
`Spiral\Validation\Checker\DatetimeChecker::timezone()` instead.
- [spiral/validation] Added return type `array|callable|string` to the method `parseCheck`
in `Spiral\Validation\ParserInterface` interface.
- [spiral/validation] Added `array|string|\Closure` parameter type of `$rules` to the method `getRules`
in `Spiral\Validation\RulesInterface` interface.
- [spiral/validation] Added `array|\ArrayAccess` parameter type of `$data` to the method `validate`
in `Spiral\Validation\ValidationInterface` interface.
- [spiral/validation] Added return type `mixed` to the method `getValue`,
added `mixed` parameter type of `$default` to the method `getValue`,
added `mixed` parameter type of `$context` to the method `withContext`,
added return type `mixed` to the method `getContext` in `Spiral\Validation\ValidatorInterface` interface.
- [spiral/filters] Added return type `void` and `mixed` parameter type of `$context` to the method `setContext`,
added return type `mixed` to the method `getContext` in `Spiral\Filters\FilterInterface` interface.
Added return type `mixed` to the method `getValue` in `Spiral\Filters\InputInterface`.
- [spiral/http] Config `Spiral\Config\JsonPayloadConfig` moved to the `Spiral\Bootloader\Http\JsonPayloadConfig`.
- **Medium Impact Changes**
- A minimal version of `PHP` increased to `^8.1`
- A minimal version of `symfony/finder` increased to `^5.3`
Expand Down
72 changes: 9 additions & 63 deletions src/AnnotatedRoutes/src/Annotation/Route.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
<?php

/**
* Spiral Framework.
*
* @license MIT
* @author Anton Titov (Wolfy-J)
*/

declare(strict_types=1);

namespace Spiral\Router\Annotation;
Expand Down Expand Up @@ -35,68 +28,21 @@ final class Route
{
public const DEFAULT_GROUP = 'default';

/**
* @var string
*/
public $route;

/**
* @var null|string
*/
public $name;

/**
* @var mixed
*/
public $methods = \Spiral\Router\Route::VERBS;

/**
* Default match options.
*
* @var array
*/
public $defaults = [];

/**
* Route group (set of middlewere), groups can be configured using MiddlewareRegistry.
*
* @var string
*/
public $group = self::DEFAULT_GROUP;

/**
* Route specific middleware set, if any.
*
* @var array
*/
public $middleware = [];

/**
* @var int
*/
public $priority;

/**
* @psalm-param non-empty-string $route
* @psalm-param non-empty-string|null $name
* @psalm-param non-empty-string|array<string> $methods
* @psalm-param non-empty-string $group
* @psalm-param non-empty-string $group Route group, groups can be configured using MiddlewareRegistry
* @param array $middleware Route specific middleware set, if any
*/
public function __construct(
string $route,
string $name = null,
$methods = \Spiral\Router\Route::VERBS,
array $defaults = [],
string $group = self::DEFAULT_GROUP,
array $middleware = [],
int $priority = 0
public readonly string $route,
public readonly ?string $name = null,
public readonly array|string $methods = \Spiral\Router\Route::VERBS,
public readonly array $defaults = [],
public readonly string $group = self::DEFAULT_GROUP,
public readonly array $middleware = [],
public readonly int $priority = 0
) {
$this->route = $route;
$this->name = $name;
$this->methods = $methods;
$this->defaults = $defaults;
$this->group = $group;
$this->middleware = $middleware;
$this->priority = $priority;
}
}
23 changes: 4 additions & 19 deletions src/AnnotatedRoutes/src/Bootloader/AnnotatedRoutesBootloader.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
<?php

/**
* Spiral Framework.
*
* @license MIT
* @author Anton Titov (Wolfy-J)
*/

declare(strict_types=1);

namespace Spiral\Router\Bootloader;

use Doctrine\Common\Annotations\AnnotationRegistry;
use Spiral\Boot\Bootloader\Bootloader;
use Spiral\Boot\EnvironmentInterface;
use Spiral\Boot\MemoryInterface;
Expand Down Expand Up @@ -40,24 +32,17 @@ final class AnnotatedRoutesBootloader extends Bootloader implements SingletonInt
GroupRegistry::class => [self::class, 'getGroups'],
];

/** @var MemoryInterface */
private $memory;

/** @var GroupRegistry */
private $groups;

public function __construct(MemoryInterface $memory, GroupRegistry $groupRegistry)
{
$this->memory = $memory;
$this->groups = $groupRegistry;
public function __construct(
private readonly MemoryInterface $memory,
private readonly GroupRegistry $groups
) {
}

public function boot(ConsoleBootloader $console, EnvironmentInterface $env, RouteLocator $locator): void
{
$console->addCommand(ResetCommand::class);

$cached = $env->get('ROUTE_CACHE', !$env->get('DEBUG'));
AnnotationRegistry::registerLoader('class_exists');

$schema = $this->memory->loadData(self::MEMORY_SECTION);
if (empty($schema) || !$cached) {
Expand Down
7 changes: 0 additions & 7 deletions src/AnnotatedRoutes/src/Command/ResetCommand.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
<?php

/**
* Spiral Framework.
*
* @license MIT
* @author Anton Titov (Wolfy-J)
*/

declare(strict_types=1);

namespace Spiral\Router\Command;
Expand Down
27 changes: 6 additions & 21 deletions src/AnnotatedRoutes/src/RouteLocator.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
<?php

/**
* Spiral Framework.
*
* @license MIT
* @author Anton Titov (Wolfy-J)
*/

declare(strict_types=1);

namespace Spiral\Router;
Expand All @@ -17,15 +10,10 @@

final class RouteLocator
{
private ScopedClassesInterface $locator;

/** @var ReaderInterface */
private $reader;

public function __construct(ScopedClassesInterface $locator, ReaderInterface $reader)
{
$this->locator = $locator;
$this->reader = $reader;
public function __construct(
private readonly ScopedClassesInterface $locator,
private readonly ReaderInterface $reader
) {
}

/**
Expand Down Expand Up @@ -54,8 +42,7 @@ public function findDeclarations(): array
continue;
}

$route->name = $route->name ?? $this->generateName($route);
$result[$route->name] = [
$result[$route->name ?? $this->generateName($route)] = [
'pattern' => $route->route,
'controller' => $class->getName(),
'action' => $method->getName(),
Expand All @@ -68,9 +55,7 @@ public function findDeclarations(): array
}
}

\uasort($result, static function (array $route1, array $route2) {
return $route1['priority'] <=> $route2['priority'];
});
\uasort($result, static fn (array $route1, array $route2) => $route1['priority'] <=> $route2['priority']);

return $result;
}
Expand Down
3 changes: 1 addition & 2 deletions src/Attributes/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
"require": {
"php": ">=8.1",
"psr/cache": ">=1.0",
"psr/simple-cache": ">=1.0",
"nikic/php-parser": "^4.1"
"psr/simple-cache": ">=1.0"
},
"require-dev": {
"doctrine/annotations": "^1.12",
Expand Down
10 changes: 0 additions & 10 deletions src/Attributes/src/AnnotationReader.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
<?php

/**
* This file is part of Spiral Framework package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Spiral\Attributes;
Expand All @@ -17,9 +10,6 @@

final class AnnotationReader extends Decorator
{
/**
* @param Reader|null $reader
*/
public function __construct(Reader $reader = null)
{
parent::__construct(new DoctrineAnnotationReader($reader));
Expand Down
18 changes: 1 addition & 17 deletions src/Attributes/src/AttributeReader.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,17 @@
<?php

/**
* This file is part of Spiral Framework package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Spiral\Attributes;

use Spiral\Attributes\Internal\Decorator;
use Spiral\Attributes\Internal\FallbackAttributeReader;
use Spiral\Attributes\Internal\Instantiator\InstantiatorInterface;
use Spiral\Attributes\Internal\NativeAttributeReader;

final class AttributeReader extends Decorator
{
/**
* @param InstantiatorInterface|null $instantiator
*/
public function __construct(InstantiatorInterface $instantiator = null)
{
$reader = NativeAttributeReader::isAvailable()
? new NativeAttributeReader($instantiator)
: new FallbackAttributeReader($instantiator)
;

parent::__construct($reader);
parent::__construct(new NativeAttributeReader($instantiator));
}
}
42 changes: 6 additions & 36 deletions src/Attributes/src/Bridge/DoctrineReaderBridge.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
<?php

/**
* This file is part of Spiral Framework package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Spiral\Attributes\Bridge;
Expand Down Expand Up @@ -37,66 +30,43 @@
*/
final class DoctrineReaderBridge implements Reader
{
/**
* @var ReaderInterface
*/
private ReaderInterface $reader;

public function __construct(ReaderInterface $reader)
{
$this->reader = $reader;
public function __construct(
private readonly ReaderInterface $reader
) {
}

/**
* {@inheritDoc}
*/
public function getClassAnnotations(\ReflectionClass $class): array
{
return $this->iterableToArray(
$this->reader->getClassMetadata($class)
);
}

/**
* {@inheritDoc}
*/
public function getClassAnnotation(\ReflectionClass $class, $annotationName)
public function getClassAnnotation(\ReflectionClass $class, $annotationName): ?object
{
return $this->reader->firstClassMetadata($class, $annotationName);
}

/**
* {@inheritDoc}
*/
public function getMethodAnnotations(\ReflectionMethod $method): array
{
return $this->iterableToArray(
$this->reader->getFunctionMetadata($method)
);
}

/**
* {@inheritDoc}
*/
public function getMethodAnnotation(\ReflectionMethod $method, $annotationName)
public function getMethodAnnotation(\ReflectionMethod $method, $annotationName): ?object
{
return $this->reader->firstFunctionMetadata($method, $annotationName);
}

/**
* {@inheritDoc}
*/
public function getPropertyAnnotations(\ReflectionProperty $property): array
{
return $this->iterableToArray(
$this->reader->getPropertyMetadata($property)
);
}

/**
* {@inheritDoc}
*/
public function getPropertyAnnotation(\ReflectionProperty $property, $annotationName)
public function getPropertyAnnotation(\ReflectionProperty $property, $annotationName): ?object
{
return $this->reader->firstPropertyMetadata($property, $annotationName);
}
Expand Down
Loading

0 comments on commit e2ab6d8

Please sign in to comment.