PHP code example of archict / brick

1. Go to this page and download the library: Download archict/brick library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

archict / brick example snippets




use Archict\Brick\Service;

#[Service]
final class MyService {}



use Archict\Brick\Service;

#[Service]
final readonly class MyService 
{
    public function __construct(
        private AnotherService $another_service,
    ) {}
}



final readonly class MyConfiguration 
{
    public function __construct(
        public int $nb_workers,
    ) {}
}



use Archict\Brick\Service;

#[Service(MyConfiguration::class)]
final readonly class MyService 
{
    public function __construct(
        private MyConfiguration $config,
    ) {}
}



use Archict\Brick\Service;

#[Service(MyConfiguration::class, 'foo.yml')]
final readonly class MyService 
{
}



use Archict\Brick\ListeningEvent;
use Archict\Brick\Service;

#[Service]
final class MyService
{
    #[ListeningEvent]
    public function fooBarBaz(MyEvent $event): void
    {
        // Do something with $event
    }
}



final class MyEvent {}



use Archict\Brick\Service;
use Archict\Core\Event\EventDispatcher;

#[Service]
final readonly class MyService
{
    public function __construct(
        private EventDispatcher $dispatcher,
    ) {}
    
    public function someMethod(): void
    {
        $this->dispatcher->dispatch(new MyEvent());
    }
}