Skip to content

Instantly share code, notes, and snippets.

@shin1x1
Created February 16, 2014 04:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shin1x1/9029416 to your computer and use it in GitHub Desktop.
Save shin1x1/9029416 to your computer and use it in GitHub Desktop.
<?php
require __DIR__.'/vendor/autoload.php';
interface Greetable
{
public function greet();
}
class Hello implements Greetable
{
/**
*
*/
public function greet()
{
echo 'Hello';
}
}
class Bye implements Greetable
{
/**
*
*/
public function greet()
{
echo 'Bye';
}
}
class Bar
{
/**
* @var Greetable
*/
protected $greeter;
/**
* @param Greetable $greeter
*/
public function __construct(Greetable $greeter)
{
$this->greeter = $greeter;
}
/**
*
*/
public function say()
{
$this->greeter->greet();
echo PHP_EOL;
}
}
$app = new \Illuminate\Foundation\Application();
//$app->make('Bar')->say();
// bind Greetable class name
$app->bind('Greetable', 'Hello');
$app->make('Bar')->say();
// bind Greetable factory
$app->bind('Greetable', function($app) {
return new Hello();
});
$app->make('Bar')->say();
// bind Bar factory
$app->bind('Bar', function($app) {
return new Bar($app->make('Hello'));
});
$app->make('Bar')->say();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment