Skip to content

Commit

Permalink
Merge branch '3.0' into maintenance/http-php-81
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk authored Mar 31, 2022
2 parents 050b200 + 33244a6 commit 6d85520
Show file tree
Hide file tree
Showing 164 changed files with 902 additions and 2,841 deletions.
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,33 @@
added return type `mixed` to the method `offsetGet`, added return type `mixed` and `mixed` parameter type
of `$default` to the method `get` in `Spiral\Http\Request\InputBag` class.
- [spiral/http] Added return type `bool` to the method `emit` in `Spiral\Http\EmitterInterface` interface.
- [spiral/config] Added return type `void` to the method `setDefaults` in `Spiral\Config\ConfiguratorInterface` interface.
- [spiral/core] Added return type `mixed` to the method `runScope` in `Spiral\Core\ScopeInterface` interface.
- [spiral/core] Added return type `mixed` and `array|callable|string` parameter type of `$target`
to the method `invoke` in `Spiral\Core\InvokerInterface` interface.
- [spiral/core] Added return type `mixed` to the method `make` in `Spiral\Core\FactoryInterface` interface.
- [spiral/core] Added `string|array|callable|object` parameter type of `$resolver` in the method `bind`,
added `string|array|callable|object` parameter type of `$resolver` in the method `bindSingleton` in `Spiral\Core\BinderInterface` interface.
- [spiral/core] Added return type `object` to the method `createInjection` in `Spiral\Core\Container\InjectorInterface` interface.
- [spiral/boot] Added return type `self` to the method `set` in `Spiral\Boot\DirectoriesInterface` interface.
- [spiral/boot] Added return type `mixed` and `mixed` parameter type of `$default` to the method `get`,
added in `Spiral\Boot\EnvironmentInterface` interface.
- [spiral/boot] Added return type `static` to the method `addFinalizer`,
added return type `void` to the method `finalize` in `Spiral\Boot\FinalizerInterface` interface.
- [spiral/boot] Added return type `self` to the method `addDispatcher`,
added return type `mixed` to the method `serve` in `Spiral\Boot\KernelInterface` interface.
- [spiral/boot] Added return type `mixed` to the method `loadData`,
added return type `void` and `mixed` parameter type of `$data` to the method `saveData` in `Spiral\Boot\MemoryInterface` interface.
- [spiral/console] Added return type `void` to the method `writeHeader`, added return type `void` to the method `execute`,
method `whiteFooter` renamed to `writeFooter`, added return type `void` to the method `writeFooter`
in `Spiral\Console\SequenceInterface` interface.
- [spiral/files] Added return type `bool` to the method `delete`, added return type `bool` to the method `deleteDirectory`,
added return type `bool` to the method `touch`, added return type `bool` to the method `setPermissions` in `Spiral\Files\FilesInterface`.
- **Medium Impact Changes**
- A minimal version of `PHP` increased to `^8.1`
- A minimal version of `symfony/finder` increased to `^5.3`
- A minimal version of `league/flysystem` increased to `^2.3`
- A minimal version of `symfony/console` increased to `^6.0`
- **Other Features**

## v2.11.0 - Unreleased
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
"psr/http-message": "^1.0",
"psr/http-server-middleware": "^1.0",
"psr/log": "^1.0",
"psr/simple-cache": "1 - 2",
"psr/simple-cache": "2 - 3",
"spiral/composer-publish-plugin": "^1.0",
"symfony/console": "^5.3.7|^6.0",
"symfony/console": "^6.0",
"symfony/finder": "^5.3.7|^6.0",
"symfony/mailer": "^5.1|^6.0",
"symfony/polyfill-php73": "^1.22",
Expand Down
2 changes: 1 addition & 1 deletion src/AnnotatedRoutes/tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ protected function makeApp(array $env): App
'app' => __DIR__ . '/App',
];

return App::init($config, new Environment($env), false);
return (App::create($config, false))->run(new Environment($env));
}
}
69 changes: 16 additions & 53 deletions src/Boot/src/AbstractKernel.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\Boot;
Expand All @@ -31,31 +24,25 @@ abstract class AbstractKernel implements KernelInterface
*/
protected const LOAD = [];

/** @var Container */
protected $container;

/** @var FinalizerInterface */
protected $finalizer;

/** @var BootloadManager */
protected $bootloader;
protected FinalizerInterface $finalizer;
protected BootloadManager $bootloader;

/** @var DispatcherInterface[] */
protected $dispatchers = [];
protected array $dispatchers = [];

/** @var array<Closure> */
private $startingCallbacks = [];
private array $startingCallbacks = [];

/** @var array<Closure> */
private $startedCallbacks = [];
private array $startedCallbacks = [];

/**
* @throws \Throwable
*/
public function __construct(Container $container, array $directories)
{
$this->container = $container;

public function __construct(
protected Container $container,
array $directories
) {
$this->container->bindSingleton(KernelInterface::class, $this);
$this->container->bindSingleton(self::class, $this);
$this->container->bindSingleton(static::class, $this);
Expand All @@ -80,31 +67,6 @@ public function __destruct()
$this->finalizer->finalize(true);
}

/**
* Create and initiate an application instance.
*
* @param array<string,string> $directories Directory map, "root" is required.
* @param EnvironmentInterface|null $environment Application specific environment if any.
* @param bool $handleErrors Enable global error handling.
* @return self|static
*
* @throws \Throwable
*
* @deprecated since 3.0. Use Kernel::create(...)->run() instead.
*/
public static function init(
array $directories,
EnvironmentInterface $environment = null,
bool $handleErrors = true
): ?self {
$core = self::create(
$directories,
$handleErrors
);

return $core->run($environment);
}

/**
* Create an application instance.
* @throws \Throwable
Expand Down Expand Up @@ -133,7 +95,7 @@ public static function create(
*/
public function run(?EnvironmentInterface $environment = null): ?self
{
$environment = $environment ?? new Environment();
$environment ??= new Environment();
$this->container->bindSingleton(EnvironmentInterface::class, $environment);

try {
Expand Down Expand Up @@ -190,26 +152,27 @@ public function started(Closure ...$callbacks): void
* Add new dispatcher. This method must only be called before method `serve`
* will be invoked.
*/
public function addDispatcher(DispatcherInterface $dispatcher): void
public function addDispatcher(DispatcherInterface $dispatcher): self
{
$this->dispatchers[] = $dispatcher;

return $this;
}

/**
* Start application and serve user requests using selected dispatcher or throw
* an exception.
*
* @return mixed
* @throws BootException
* @throws \Throwable
*/
public function serve()
public function serve(): mixed
{
foreach ($this->dispatchers as $dispatcher) {
if ($dispatcher->canServe()) {
return $this->container->runScope(
[DispatcherInterface::class => $dispatcher],
[$dispatcher, 'serve']
static fn () => $dispatcher->serve()
);
}
}
Expand All @@ -220,7 +183,7 @@ public function serve()
/**
* Bootstrap application. Must be executed before serve method.
*/
abstract protected function bootstrap();
abstract protected function bootstrap(): void;

/**
* Normalizes directory list and adds all required aliases.
Expand Down
19 changes: 5 additions & 14 deletions src/Boot/src/BootloadManager.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\Boot;
Expand All @@ -22,15 +15,13 @@
*/
final class BootloadManager implements Container\SingletonInterface
{
/* @var Container @internal */
protected $container;

/** @var array<class-string> */
private $classes = [];
private array $classes = [];

public function __construct(Container $container)
{
$this->container = $container;
public function __construct(
/* @internal */
private readonly Container $container
) {
}

/**
Expand Down
20 changes: 2 additions & 18 deletions src/Boot/src/Bootloader/Bootloader.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\Boot\Bootloader;
Expand All @@ -23,31 +16,22 @@
abstract class Bootloader implements BootloaderInterface, DependedInterface
{
/** @var array<string, class-string|callable> */
protected const BINDINGS = [];
protected const BINDINGS = [];
/** @var array<string, class-string|callable> */
protected const SINGLETONS = [];
protected const SINGLETONS = [];
/** @var array<int, class-string<BootloaderInterface|DependedInterface>> */
protected const DEPENDENCIES = [];

/**
* {@inheritdoc}
*/
public function defineBindings(): array
{
return static::BINDINGS;
}

/**
* {@inheritdoc}
*/
public function defineSingletons(): array
{
return static::SINGLETONS;
}

/**
* {@inheritdoc}
*/
public function defineDependencies(): array
{
return static::DEPENDENCIES;
Expand Down
7 changes: 0 additions & 7 deletions src/Boot/src/Bootloader/BootloaderInterface.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\Boot\Bootloader;
Expand Down
28 changes: 7 additions & 21 deletions src/Boot/src/Bootloader/ConfigurationBootloader.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\Boot\Bootloader;
Expand All @@ -33,33 +26,26 @@ final class ConfigurationBootloader extends Bootloader
ConfigManager::class => [self::class, 'configManager'],
];

/** @var ConfiguratorInterface */
private $configurator;
private ConfiguratorInterface $configurator;

/** @var FileLoaderInterface[] */
private $loaders;
private array $loaders;

/** @var DirectoriesInterface */
private $directories;

/** @var Container */
private $container;

public function __construct(DirectoriesInterface $directories, Container $container)
{
public function __construct(
private readonly DirectoriesInterface $directories,
private readonly Container $container
) {
$this->loaders = [
'php' => $container->get(PhpLoader::class),
'json' => $container->get(JsonLoader::class),
];

$this->directories = $directories;
$this->container = $container;
$this->configurator = $this->createConfigManager();
}

public function addLoader(string $ext, FileLoaderInterface $loader): void
{
if (!isset($this->loaders[$ext]) || get_class($this->loaders[$ext]) !== get_class($loader)) {
if (!isset($this->loaders[$ext]) || $this->loaders[$ext]::class !== $loader::class) {
$this->loaders[$ext] = $loader;
$this->container->bindSingleton(ConfigManager::class, $this->createConfigManager());
}
Expand Down
7 changes: 0 additions & 7 deletions src/Boot/src/Bootloader/CoreBootloader.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\Boot\Bootloader;
Expand Down
7 changes: 0 additions & 7 deletions src/Boot/src/Bootloader/DependedInterface.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\Boot\Bootloader;
Expand Down
Loading

0 comments on commit 6d85520

Please sign in to comment.