PHP code example of thecodingmachine / common-factories

1. Go to this page and download the library: Download thecodingmachine/common-factories 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/ */

    

thecodingmachine / common-factories example snippets


public function getFactories() {
    return [
        'myAlias' => new Alias('myService')
    ]
}

public function getFactories() {
    return [
        'myAlias' => function(ContainerInterface $container) {
            return $container->get('myService');
        }
    ]
}

public function getFactories() {
    return [
        'DB_HOST' => new Parameter('localhost')
    ]
}

public function getFactories() {
    return [
        'DB_HOST' => function() {
            return 'localhost';
        }
    ]
}

public function getExtensions() {
    return [
        MyTwigExtension::class => function() {
            return new MyTwigExtension();
        },
        'twig.extensions' => new AddToArray(MyTwigExtension::class)
    ]
}

public function getExtensions() {
    return [
        MyTwigExtension::class => function() {
            return new MyTwigExtension();
        },
        'twig.extensions' => function(ContainerInterface $container, array $extensions = []) {
            $extensions[] = $container->get(MyTwigExtension::class);
            return $extensions;
        }
    ]
}