PHP code example of acelaya / slim-container-sm

1. Go to this page and download the library: Download acelaya/slim-container-sm 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 / slim-container-sm example snippets


use Acelaya\SlimContainerSm\Container;
use Slim\Slim;
use Vendor\ComplexClass;
use Vendor\MyAbstractFactory;
use Zend\ServiceManager\Factory\InvokableFactory;
use Zend\ServiceManager\ServiceManager;

// Create a ServiceManager that is going to be used by the application and add some services to it
$sm = new ServiceManager([
    'factories' => [
        'complex_service' => function ($sm) {
            // Do stuff...
            
            return new ComplexClass();
        },
        'foo_invokable' => InvokableFactory::class,
    ],
    'abstract_factories' => [
        MyAbstractFactory::class
    ],
    'aliases' => [
        'foo' => 'foo_invokable'
    ]
]);
// Inject the ServiceManager in the new container
$container = new Container($sm);

// Create Slim object which will initialize its container
$app = new Slim();
// Inject default Slim services into our container
$container->consumeSlimContainer($app->container);
// Override Slim's container with the new one
$app->container = $container;