Skip to content

Releases: spiral/framework

v3.6.1

20 Feb 15:42
Compare
Choose a tag to compare

What's Changed

Full Changelog: 3.6.0...3.6.1

v3.6.0

16 Feb 21:23
Compare
Choose a tag to compare

Spiral Framework 3.6 has been released, introducing a range of new features, performance improvements, and bug fixes.

What's Changed

1. Container

One notable change is the introduction of a new and improved container, which offers isolated memory scopes for more fine-grained control over how dependencies are resolved. This is useful in situations where you want to ensure that certain dependencies are only used within a specific context and do not bleed over to other parts of the application.

PR: #870

Container scopes

The Container::scope() method is used to run a true isolated scope, and it takes a callable as its first argument. The callable is executed within the scope, and any bindings passed as the second argument will only be used within that scope.

Named scopes can also be used. This is useful for cases where you have multiple scopes with similar dependencies, but with some variations. Parallel named scopes are also allowed.

When a scope is finished callback execution, all the dependencies that were created in that scope will be destroyed, including singletons. This means that any instances of objects that were created within the scope will no longer be available.

Additionally, the container that was used to run the scope will also be destroyed, which means that any attempts to use the container after the scope has finished execution will result in an exception being thrown.

If you create a named scope using Container::scope() method, you can access and modify the default bindings for that scope by calling Container::getBinder(string $scope) method and using the returned Binder instance to make new bindings.

$container = new Container();
// Configure `root` scope bindings (the current instance)
$container->bindSingleton(Interface::class, Implementation::class);

// Configure `request` scope default bindings
// Prefer way to make many bindings
$binder = $container->getBinder('request');
$binder->bindSingleton(Interface::class, Implementation::class);
$binder->bind(Interface::class, factory(...));

New attributes

Here's an overview of the new attributes in Spiral's new container:

#[Singleton]: This attribute is used to mark a class as a singleton. This attribute can be used in addition to the traditional bindSingleton() method.

#[Scope(string $name)]: This attribute is used to set a scope in which a dependency can be resolved.

#[Finalize(string $method)]: This an experimental attribute is used to define a finalize method for a class. The finalize method will be called before the scope is being destroyed. This can be used to perform any necessary cleanup operations.

PHP 8.2 Fibers support

And also it's now fully compatible with PHP 8.2 Fibers. The static class \Spiral\Core\ContainerScope::getContainer()
will return correct container instance for the current fiber and scope.

2. Improved performance of Tokenizer component

Additionally, We improved application performance when utilizing tokenizer components. Specifically, the introduction of a TOKENIZER_CACHE_TARGETS environment variable now allows for tokenizer listener caching. Upon the initial application bootstrapping, all found classes for each tokenizer listener will be cached. Subsequent bootstrapping processes will then retrieve the cached data, leading to faster and more efficient performance.

PR: #878

3. Console commands base on attributes

Developers can now create console commands using attributes.

PR: #872

4

Furthermore, if required arguments are not provided when calling a console command, the framework will prompt users to input the missing arguments rather than displaying an error. This is particularly useful for scaffolder commands like php app.php create:controller, where developers previously needed to remember which arguments were required. With this new feature, all required arguments will be automatically prompted for, streamlining the development process.

console-prompt

When creating a console command, developers can use the Spiral\Console\Attribute\Question attribute to specify the question text that should be displayed when the command is run and a required argument is missing.

final class CreateUser extends Command
{
    #[Argument]
    #[Question(question: 'Provide the User Email')]
    private string $email;
}

4. Repeatable setters for filters

Another update is that the Setter attribute for the spiral/filters component is now repeatable. This means that it can be used multiple times on the same property, enabling more flexible and powerful filtering options.

class StoreUserFilter extends Filter
{
    #[Post]
    #[Setter(filter: 'strval')]
    #[Setter('ltrim', '-')]
    #[Setter('rtrim', ' ')]
    #[Setter('htmlspecialchars')]
    public string $name;
}

PR: #874

5. Cache key prefixes

Spiral also includes a new feature for cache storage aliases. Developers can now configure a key prefix for each alias, providing more granular control over caching options.

PR: #869

return [
    'aliases' => [
        'user-data' => [
            'storage' => 'in-memory',
            'prefix' => 'user_'
        ],
        'blog-data' => [
            'storage' => 'in-memory',
            'prefix' => 'blog_'
        ],
    ],
    'storages' => [
        'in-memory' => [
            'type' => 'roadrunner-local'
        ],
    ],
];

This allows developers to use the same cache storage for multiple purposes while still maintaining separate cache keys for each purpose. The prefix option can be used to differentiate cache keys and ensure that they do not overlap, improving the reliability and accuracy of caching in the application.

// Cache Manager $cache
$cache->storage('user-data')->set('data', 'foo');
$cache->storage('blog-data')->set('data', 'bar');

// Result
array:2 [
  "user_data" => array:2 [
    "value" => "foo"
    "timestamp" => 1677694480
  ]
  "blog_data" => array:2 [
    "value" => "bar"
    "timestamp" => 1677694480
  ]
]

6. Custom mail transport

Another new feature is the ability to register a custom mail transport factory via Bootloader. This can be useful in cases where developers want to use a non-standard mail transport with the SendIt component.

PR: #873

To register a new mail transport factory, developers can create a new Bootloader class

use Spiral\Boot\Bootloader\Bootloader;
use Spiral\SendIt\TransportRegistryInterface;
use Symfony\Component\Mailer\Transport\c;

class AppBootloader extends Bootloader 
{
    public function boot(TransportRegistryInterface $registry): void
    {
        $registry->registerTransport(new SendmailTransportFactory(...));
    }
}

Bug fixes

Spiral Framework 3.6 also includes several bug fixes to improve the reliability and stability of the framework.

  1. The first bug fix addresses a problem with the container factory where previously created objects were sometimes used instead of creating new objects with the provided arguments. This issue could cause unexpected behavior and was fixed.
$service = new Service();
$container->bindSingleton(Service::class, $service);

$service === $container->make(Service::class);                   // true
$service === $container->make(Service::class, ['foo' => 'bar']); // false

PR: #862

  1. The second bug fix resolves an error message that could occur in the Prototype component when updating a DOCComment. The error message Updating PrototypeTrait DOCComment... DOCComment is missing no longer appears.

PR: #865

  1. The third bug fix addresses a problem with validation nested filters. This issue could cause validation errors to be missed or incorrectly reported.

PR: #868


New Contributors

Full Changelog: 3.5.0...3.6.0

v3.5.0

23 Dec 14:11
Compare
Choose a tag to compare

What's Changed

  • Improved the exception trace output for both the plain and console renderers to provide more detailed information about previous exceptions. by @butschster in #853
  • Added named route patterns registry Spiral\Router\Registry\RoutePatternRegistryInterface to allow for easier management of route patterns. by @kastahov in #847
  • Made the Verbosity enum injectable to allow for easier customization and management of verbosity levels from env variable VERBOSITY_LEVEL. by @kastahov in #846
  • Deprecated Kernel constants and add new function defineSystemBootloaders to allow for more flexibility in defining system bootloaders. by @kastahov in #845

Full Changelog: 3.4.0...3.5.0

v3.4.0

08 Dec 18:41
Compare
Choose a tag to compare

What's Changed

  • Medium Impact Changes
    • [spiral/boot] Class Spiral\Boot\BootloadManager\BootloadManager is deprecated. Will be removed in version v4.0. #840
    • [spiral/stempler] Adds null locale processor to remove brackets [[ ... ]] when don't use Translator component by @butschster in #843
  • Other Features
    • [spiral/session] Added session handle with cache driver by @kastahov in #835
    • [spiral/router] Added routes with PATCH method into route:list command by @gam6itko in #839
    • [spiral/boot] Added Spiral\Boot\BootloadManager\InitializerInterface. This will allow changing the implementation
      of this interface by the developer by @msmakouz #840
    • [spiral/boot] Added Spiral\Boot\BootloadManager\StrategyBasedBootloadManager. It allows the implementation of a
      custom bootloaders loading strategy by @msmakouz #840
    • [spiral/boot] Added the ability to register application bootloaders via object instance or anonymous object.
    • [spiral/boot] Removed final from the Spiral\Boot\BootloadManager\Initializer class by @msmakouz #840
  • Bug Fixes
    • [spiral/views] Fixes problem with using view context with default value by @butschster in #842
    • [spiral/queue] Added Spiral\Telemetry\Bootloader\TelemetryBootloader dependency to QueueBootloader by @butschster in #837
    • [spiral/core] (PHP 8.2 support) Fixed problem with dynamic properties in Spiral\Core\Container by @msmakouz in #844

Full Changelog: 3.3.0...3.4.0

v3.3.0

17 Nov 16:27
Compare
Choose a tag to compare

What's Changed

  • New [spiral/telemetry] component and spiral/otel-bridge by @butschster in #816
  • Added Spiral\Auth\Middleware\Firewall\RedirectFirewall by @msmakouz in #827
  • Created TokenStorageProvider to able manage token storages by @kastahov in #826
  • Fixed error suppressing in the Spiral\Http\Middleware\ErrorHandlerMiddleware by @msmakouz in #833
  • Router improvements by @msmakouz in #831
  • Changed where Tokenizer listener events are called by @msmakouz in #825

New Contributors

Full Changelog: 3.2.0...3.3.0

v3.2.0

21 Oct 10:10
Compare
Choose a tag to compare

What's Changed

Full Changelog: 3.1.0...3.2.0

v3.1.0

29 Sep 14:55
Compare
Choose a tag to compare

What's Changed

Features

  • Added the ability to configure default validator by @msmakouz in #805
  • Added ValidationHandlerMiddleware for handling filter validation exception. by @butschster in #803

Bugfixes

Full Changelog: 3.0.0...3.1.0

v3.0.2

29 Sep 14:38
Compare
Choose a tag to compare

What's Changed

Full Changelog: 3.0.0...3.0.2

v3.0.0

13 Sep 16:06
Compare
Choose a tag to compare

What's Changed

  • Increased min PHP version up to 8.1 by @msmakouz in #595
  • [spiral/data-grid] moved into a standalone package by @msmakouz in #655
  • New error handler by @roxblnfk in #659
  • [spiral/boot] Disabled overwriting of env variables by @msmakouz in #664
  • Nyholm Psr17Factory used by default in the framework by @msmakouz in #667
  • [spiral/http] SAPI moved to standalone package sapi-bridge by @msmakouz in #666
  • [spiral/monolog-bridge] Added the ability to configure the default channel by @msmakouz in #675
  • [spiral/boot] Added automatic booting of bootloaders in the init and boot methods by @msmakouz in #672
  • [spiral/filters] Added method Spiral\Filters\InputInterface::hasValue() by @only-viktor in #470
  • [spiral/dumper] Removed component by @roxblnfk in #679
  • [spiral/boot] Renamed starting/started into booting/booted methods by @msmakouz in #686
  • [spiral/core] Refactored the container by @roxblnfk in #670
  • [spiral/core] The container made replaceable in the App by @roxblnfk in #689
  • [spiral/filters] Refactored component by @butschster in #663
  • [spiral/console] Refactored component by @butschster in #685
  • [spiral/core] Added typization for $config property in Spiral\Core\InjectableConfig by @msmakouz in #694
  • [spiral/boot] Added Spiral\Boot\Injector\EnumInjector for enums by @butschster in #693
  • [spiral/http] Added the ability to add input bags by @msmakouz in #698
  • [spiral/attributes] component moved into a standalone package by @msmakouz in #699
  • [spiral/scaffolder] Added the ability to override the base namespace by @msmakouz in #705
  • Replaced laminas/diactoros to nyholm/psr7 by @msmakouz in #704
  • [spiral/boot] Added callbacks appBooting and appBooted for App bootloaders by @msmakouz in #703
  • [spiral/monolog-bridge] Fixed the problem with finalizing monolog logger during application destruction. by @butschster in #710
  • Removed bin/spiral by @msmakouz in #714
  • [spiral/router] Refactored component by @msmakouz in #709
  • [spiral/console] Added ApplicationInProduction confirmation class for console commands by @butschster in #713
  • [spiral/exceptions] Added LoggerReporter by @msmakouz in #716
  • [spiral/serializer] Added Serializer component with interface and simple implementation by @msmakouz in #712
  • [spiral/auth] Added AuthTransportMiddleware by @msmakouz in #717
  • [spiral/boot] Added a new callback running for Kernel class by @butschster in #720
  • Replaced $env->get('DEBUG') with $debugMode->isEnabled() by @msmakouz in #722
  • [spiral/queue] Removed method pushCallable by @msmakouz in #723
  • [spiral/router] Added the ability to register middleware via Autowire by @msmakouz in #726
  • [spiral/exceptions] Improved Spiral\Http\ErrorHandler\RendererInterface class. by @butschster in #727
  • [spiral/router] Improved route group middleware by @butschster in #730
  • [spiral/core] Added the ability to check if class or interface has registered injector by @butschster in #734
  • [spiral/console] Added interceptors for Console command by @butschster in #732
  • [spiral/queue] Removed opis/closure by @msmakouz in #744
  • [spiral/serializer] Changing folder name from Dto to Model in Filters by @msmakouz in #746
  • [spiral/views] Added the ability to register template global variables by @butschster in #742
  • [spiral/queue] Added the ability to configure serializers for different types of jobs by @msmakouz in #749
  • [spiral/queue] Added interceptors for consumers by @butschster in #739
  • [spiral/tokenizer] Added ext-tokenizer dependency to composer requirements by @butschster in #762
  • [spiral/boot] Preventing bootload abstract bootloaders by @msmakouz in #766
  • psalm level increased up to 4 by @roxblnfk and @butschster in #764
  • [spiral/http] Fixed default behaviour for InputBag when it checks key with null value by @butschster in #770
  • [spiral/queue] Added defaultSerializer in queue config by @msmakouz in #768
  • [spiral/sendit] Added the ability to use custom transports for Symfony Mailer by @butschster in #774
  • [spiral/events] Added PSR-14 Event dispatcher by @butschster and @msmakouz in #769
  • [spiral/tokenizer] Added tokenizer listeners by @butschster in #763
  • [spiral/exceptions] Added FileReporter by @msmakouz in #779
  • Use container interfaces instead of container class into by @butschster in #780
  • [spiral/boot] Added the ability to use custom bootload manager by @butschster in #781
  • [spiral/events] Use tokenizer listeners for registering event dispatcher listeners via attributes. by @butschster in #785
  • [spiral/router] Fixed problem with subdomain patterns. by @butschster in #786

Full Changelog: 2.11.0...3.0.0

v2.14.1

12 Sep 15:20
Compare
Choose a tag to compare

What's Changed

Full Changelog: 2.14.0...2.14.1