Repository navigation
v3.7.0
New Features
1. Added the ability to push objects to a queue
Previously, only arrays could be pushed to the queue, but with this feature, developers can now push any other types, such as objects, strings, etc. Now you can use various serializers like Symfony Serializer, Valinor, and Protobuf to serialize and deserialize objects. For example, using a more efficient and compact serialization format like Protobuf can help reduce the size of the data being pushed to the queue, resulting in faster processing times and lower storage costs.
Note
Read more about jobs payload serialization on official documentation
2. Added the ability to guess option mode in by property type console commands
This makes it easier for developers to define command options by allowing them to simply define the property type and the console command will automatically guess the appropriate mode for the option.
namespace App\Endpoint\Console;
use Spiral\Console\Attribute\AsCommand;
use Spiral\Console\Attribute\Option;
use Spiral\Console\Command;
#[AsCommand(name: 'create:user', description: 'Create a new user')]
class CreateUserCommand extends Command
{
#[Option]
private bool $active; // InputOption::VALUE_NEGATABLE
#[Option]
private int $age; // InputOption::VALUE_REQUIRED
#[Option]
private int $friends = 0; // InputOption::VALUE_OPTIONAL (property have a default value)
#[Option]
private ?string $address = null; // InputOption::VALUE_OPTIONAL (nullable property)
#[Option]
private array $groups; // InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY
#[Option]
private array $phones = []; // InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY
#[Option]
private ?array $emails; // InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY
public function __invoke(): int
{
// ...
}
}Note
Read more about console commands on official documentation
3. Added the ability to override Scaffolder config partially
Previously, if a developer wanted to customize the scaffolder configuration, they had to override the entire default configuration in the scaffolder.php config file.
With this feature, developers can configure only specific options for each declaration type.
return [
'namespace' => 'App',
'declarations' => [
Declaration\BootloaderDeclaration::TYPE => [
'namespace' => 'Application\Bootloader',
],
Declaration\ConfigDeclaration::TYPE => [
'namespace' => 'Application\Config',
],
Declaration\ControllerDeclaration::TYPE => [
'namespace' => 'Endpoint\Web',
],
Declaration\MiddlewareDeclaration::TYPE => [
'class' => Declaration\MiddlewareDeclaration::class,
'namespace' => 'Application\Http\Middleware',
],
Declaration\CommandDeclaration::TYPE => [
'namespace' => 'Endpoint\Console',
],
Declaration\JobHandlerDeclaration::TYPE => [
'namespace' => 'Endpoint\Job',
'postfix' => 'Job',
],
],
];It allows developers to customize only the specific declaration types they need, without having to override the entire default declaration configuration. This can make the configuration process simpler and reduce the risk of errors.
Note
Read more about scaffolding on official documentation
4. Refactored scaffolder commands
create:bootloadercommand now has an ability to create a domain bootloader with interceptors using the -d option.create:command- command has been improved with several changes, such as adding the final keyword for class and using PHP attributes for command definition and console command declaration. The command now also has the ability to add arguments and options to the generated console command.
// Generate command with arguments and options
php app.php create:command UserRegister -a username -a password -o isAdmin -d "Register a new user"Will generate
<?php
declare(strict_types=1);
namespace App\Api\Cli\Command;
use Spiral\Console\Attribute\Argument;
use Spiral\Console\Attribute\AsCommand;
use Spiral\Console\Attribute\Option;
use Spiral\Console\Attribute\Question;
use Spiral\Console\Command;
#[AsCommand(name: 'user:register', description: 'Register a new user')]
final class UserRegisterCommand extends Command
{
#[Argument(description: 'Argument description')]
#[Question(question: 'What would you like to name the username argument?')]
private string $username;
#[Argument(description: 'Argument description')]
#[Question(question: 'What would you like to name the password argument?')]
private string $password;
#[Option(description: 'Argument description')]
private bool $isAdmin;
public function __invoke(): int
{
// Put your command logic here
$this->info('Command logic is not implemented yet');
return self::SUCCESS;
}
}create:filtercommand has also been added for filters declaration, which allows developers to generate filters with validation rules.
php app.php create:filter CreateUser -p username:post -p tags:post:array -p ip:ip -p token:header -p status:query:intWill generate
<?php
declare(strict_types=1);
namespace App\Api\Web\Filter;
use Spiral\Filters\Attribute\Input\Header;
use Spiral\Filters\Attribute\Input\Post;
use Spiral\Filters\Attribute\Input\Query;
use Spiral\Filters\Attribute\Input\RemoteAddress;
use Spiral\Filters\Model\Filter;
final class CreateUserFilter extends Filter
{
#[Post(key: 'username')]
public string $username;
#[Post(key: 'tags')]
public array $tags;
#[RemoteAddress(key: 'ip')]
public string $ip;
#[Header(key: 'token')]
public string $token;
#[Query(key: 'status')]
public int $status;
}There is also an ability to use validator to validate filter
php app.php create:filter CreateUser -p ... -sWill generate
<?php
declare(strict_types=1);
namespace App\Api\Web\Filter;
use Spiral\Filters\Attribute\Input\Header;
use Spiral\Filters\Attribute\Input\Post;
use Spiral\Filters\Attribute\Input\Query;
use Spiral\Filters\Attribute\Input\RemoteAddress;
use Spiral\Filters\Model\Filter;
use Spiral\Filters\Model\FilterDefinitionInterface;
use Spiral\Filters\Model\HasFilterDefinition;
use Spiral\Validator\FilterDefinition;
final class CreateUserFilter extends Filter implements HasFilterDefinition
{
#[Post(key: 'username')]
public string $username;
#[Post(key: 'tags')]
public array $tags;
#[RemoteAddress(key: 'ip')]
public string $ip;
#[Header(key: 'token')]
public string $token;
#[Query(key: 'status')]
public int $status;
public function filterDefinition(): FilterDefinitionInterface
{
return new FilterDefinition(validationRules: [
// Put your validation rules here
]);
}
}All these improvements can help to streamline the process of generating classes using the scaffolder component, making it easier and more efficient for developers to generate the necessary classes for their application.
Note
Read more about scaffolding on official documentation
by @butschster in #902
Improvements
- Updated Psalm up to v5 by @msmakouz in #906
- Added support for
doctrine/annotations:2.xpackage by @msmakouz in #897
Bug Fixes
- Fixed problem with displaying console commands description when it was defined via
DESCRIPTIONconstant by @msmakouz in #889 - Fixed applying setters during validation filter objects by @msmakouz in #891
- Fixed the problem with using named parameters in class located by a tokenizer by @butschster in #895
- Fixed elapsed time calculation for LogTracer in spiral/telemetry component by @gam6itko in #919