PHP code example of mattjmattj / manioc

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

    

mattjmattj / manioc example snippets


use Manioc\Container;
[...]

$container = new Container();

// A Manioc container is a Pimple 3 container
$container['feature.foo.enabled'] = false;

$container['Cache'] = function($c) {
	new Cache();
}

// ...but with Maybe! Here we use a feature switch to build an instance of Foo
// and wrap it with Maybe. If feature.foo is disabled, Maybe will provide a fake
// object
$container['Foo'] = $container->maybe('Foo',function($c) {
	if ($c['feature.foo.enabled']) {
		return new Foo();
	}
});

// we can also register factories:
$container['Foo'] = $container->maybeFactory('Foo',function($c) {
	if ($c['feature.foo.enabled']) {
		return new Foo();
	}
});