PHP code example of mizmoz / container

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

    

mizmoz / container example snippets


use Mizmoz\Container;
$container = new Container;

// Add an item to the container
$container->add(MyClass::class, function () {
    return new MyClass('some', 'params');
});

// get the item
$myClass = $container->get(MyClass::class);

// Add a shared item
$container->addShared(MyClass::class, function () {
    return new MyClass();
}, Container::SHARED);

// get the shared item
$container->get(MyClass::class) === $container->get(MyClass::class);

// check if an item exists in the container
$container->has(MyClass::class);

// add an alias for easy access to items
$container->addAlias(SomeLogger::class, 'log');


// Pass the resolver in to the container
$container = new Container(new Resolver);

// silly example
$date = $container->get(DateTime::class);

// add entries to the container to have interfaces resolved
$container->add(SomeInterface::class, function () { return new Some(); });

// add a raw value to the container, these are always treated as shared objects.
$container->addValue('config', new Config());

// now auto resolve the class that