PHP code example of matejicekvojtech / service-registry-bundle

1. Go to this page and download the library: Download matejicekvojtech/service-registry-bundle 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/ */

    

matejicekvojtech / service-registry-bundle example snippets


# config/bundles.php


return [
// ...
    \MV\ServiceRegistryBundle\ServiceRegistryBundle::class => ['all' => true],
];



namespace App;

use MV\ServiceRegistryBundle\Attribute\ServiceInRegistry;

#[ServiceInRegistry(registry: 'some_registry_id', priority: 10 /* default 0 */)]
class SomeClass implements SomeInterface {
/* ... */
}


namespace App;

use MV\ServiceRegistryBundle\Registry\ServiceRegistryInterface;

class ClassUsingRegistry {
    /**
     * @param ServiceRegistryInterface<SomeInterface> $serviceRegistry
     */
    public function __construct(
        private ServiceRegistryInterface $serviceRegistry,
    )
    
    public function useAllFromRegistry(): void
    {
        foreach ($this->serviceRegistry->all() as $service) {
            /* some logic here */
        }
    }
    
    public function useCertainFromRegistry(): void
    {
        $service = $this->serviceRegistry->get(App\SomeClass::class);
        /* some logic here */
    }
}