1. Go to this page and download the library: Download ifcanduela/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/ */
use function ifcanduela\container\raw;
$container->raw("rand", function (int $max) {
return random_int(0, $max);
});
// using the helper
$container->set("rand", raw(function (...) {...}));
// using array index notation
$container["rand"] = raw(function (...) {...});
$rand = $container->get("rand");
echo $rand(100);
$container->set("logger", function (Container $c) {
return new Logger($c->get("log_path"));
});
// using array index notation
$container["logger"] = function (...) {...};
$logger = $container->get("logger");
$logger->log(Logger::INFO, "I'm the logger");
use function ifcanduela\container\factory;
$container->factory("rand", function (Container $c) {
return random_int(0, $c->get("max_random_number"));
});
// using the helper
$container->set("rand", factory(function (...) {...}));
// using array index notation
$container["rand"] = factory(function (...) {...});
echo $container->get("rand"); // => 24
echo $container->get("rand"); // => 71
echo $container->get("rand"); // => 13