Skip to content

Instantly share code, notes, and snippets.

View ismail1432's full-sized avatar
🏠
Looking for remote job

Smaine Milianni ismail1432

🏠
Looking for remote job
View GitHub Profile
<?php
namespace App\FeatureFlag\FeatureFlagEnum;
trait FeatureFlagEnumTrait
{
public static function names()
{
return array_column(self::cases(), 'name');
}
}
<?php
namespace App\FeatureFlag\Resolver;
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
// In order to tag all classes that implements this interface
#[AutoconfigureTag()]
interface FeatureFlagResolverInterface
{
public function isEnabled(string $name): bool;
<?php
namespace App;
class BaseHttpClient
{
implements HttpClientInterface
{
use AsyncDecoratorTrait;
public function request(string $method, string $url, array $options = []): ResponseInterface
# services.yaml
services:
    _defaults:
        autowire: true
        autoconfigure: true
        bind:
            $statusCodes: [400, 500]
            $logLevel: 'info'

Rename a column

We want to rename the column name to lastname in the table user

💡 The plan is to add a new column lastname, write in both from the codebase :bulb: Populate the new columns lastname with column name

Step 1

💡 Add the new column nullable 💡 Make the property nullable

Add a new column not null

We want to add the column age NOT NULL in the table user

Version 1.1

💡 Add the column nullable and write in with the code

💡 Make the property and the getter nullable

<?php
use App\Bus;
class HelloController extends AbstractController
{
#[Route('/hello', name: 'app_hello')]
public function hello(Bus $bus): Response
{
$bus->dispatch(new MyMessage());
<?php
// FooPreHandler.php
class FooPreHandler implements PreHandlerInterface
{
💡 // As it's a service you can inject what you want
public function __construct(DummyService $service) {}
public function preHandle(object $message)
{
# services.yaml
services:
_instanceof:
# Add a tag `app.pre_handler` to all classes that implements App\PreHandlerInterface
App\PreHandlerInterface:
tags: [ 'app.pre_handler' ]
# Add a tag `app.post_handler` to all classes that implements App\PostHandlerInterface
App\PostHandlerInterface:
tags: [ 'app.post_handler' ]
_defaults:
<?php
use Symfony\Component\Messenger\MessageBusInterface;
final class Bus
{
// The trait contains a `handle` method
// that dispatch the message and return the result.
use Symfony\Component\Messenger\HandleTrait;