PHP code example of davidecesarano / embryo-container
1. Go to this page and download the library: Download davidecesarano/embryo-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/ */
davidecesarano / embryo-container example snippets
class Person
{
public function getName()
{
return 'David';
}
}
class Hello
{
public $name;
public function __construct(Person $person)
{
$this->name = $person->getName();
}
public function getHello()
{
return 'Hello '.$this->name;
}
}
$container = new \Embryo\Container\ContainerBuilder;
$hello = $container->get('Hello');
echo $hello->getHello(); // Hello David
use Embryo\Container\ContainerBuilder;
use Embryo\Container\ServiceProvider;
class TestServiceProvider extends ServiceProvider
{
public function register()
{
$this->container->set('testService', function($container){
$other = $container->get('otherService');
return 'This is a Test Service! '.$other;
});
}
}
$container = new ContainerBuilder;
$test_service_provider = new TestServiceProvider($container);
$test_service_provider->register();
echo $container['testService']; // This is a Test Service!
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.