1. Go to this page and download the library: Download pierredup/di 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/ */
pierredup / di example snippets
namespace Foo {
class Bar
{
public function __construct(Baz $baz)
{
// ...
}
}
class Baz {
}
}
$object = Di::get('Foo\Bar');
var_dump($object);
$object = Di::get('Foo\Bar', Di::NEW_INSTANCE);
$object = Di::get('Foo\Bar', Di::DEEP);
class Db
{
public function __construct($host, $username, $password)
{
// ...
}
}
Di::map(array(
'host' => 'localhost',
'username' => 'user',
'host' => 'password',
));
$object = Di::get('Db');
namespace Foo {
class Bar
{
}
}
namespace Baz {
use Foo\Bar;
class FooBar extends Bar
{
}
}
Di::map(array(
'Foo\Bar' => 'Baz\FooBar'
));
$object = Di::get('Foo\Bar'); // will return an instance of `Baz\FooBar`
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.