PHP code example of acelaya / zsm-annotated-services

1. Go to this page and download the library: Download acelaya/zsm-annotated-services 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/ */

    

acelaya / zsm-annotated-services example snippets


namespace Acelaya;

use Interop\Container\ContainerInterface;

class MyFactory
{
    public funciton __invoke(ContainerInterface $container, $requestedName)
    {
        $foo = $container->get(Foo::class);
        $bar = $container->get('bar');

        return new MyService($foo, $bar);
    }
}

namespace Acelaya;

use Acelaya\ZsmAnnotatedServices\Annotation\Inject;

class MyService
{
    /**
     * @Inject({Foo::class, "bar"})
     */
    public function __construct($foo, $bar)
    {
        // [...]
    }

    // [...]
}

use Acelaya\MyService;
use Acelaya\ZsmAnnotatedServices\Factory\V3\AnnotatedFactory;
use Zend\ServiceManager\ServiceManager;

$sm = new ServiceManager([
    'factories' => [
        MyService::class => AnnotatedFactory::class,
    ],
]);

use Acelaya\MyService;
use Acelaya\ZsmAnnotatedServices\Factory\V3\AnnotatedFactory;
use Zend\ServiceManager\ServiceManager;

$sm = new ServiceManager([
    'services' => [
        'config' => [
            'mail' => [
                'smtp' => [
                    // [...]
                ],
                'from' => '[email protected]',
                'subject' => 'Welcome!',
            ],
            'logger' => [
                'file' => '/var/log/my_log.log'
            ],
        ],
    ],
    'factories' => [
        MyService::class => AnnotatedFactory::class,
    ],
]);

namespace Acelaya;

use Acelaya\ZsmAnnotatedServices\Annotation\Inject;

class MyService
{
    /**
     * @Inject({"config.mail.from"})
     */
    public function __construct($from)
    {
        // The value of $from will be '[email protected]'
    }
}