Created
December 2, 2013 07:33
-
-
Save crynobone/7746273 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class EmailNotifier implements NotifierInterface { | |
public function send() | |
{ | |
// send email. | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
interface NotifierInterface { | |
public function send(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class User { | |
protected $notifier; | |
public function __construct(NotifierInterface $notifier) | |
{ | |
$this->notifier = $notifier; | |
} | |
public function update() | |
{ | |
// update user. | |
$this->notifier->send(); | |
} | |
} | |
App::bind('NotifierInterface', 'EmailNotifier'); | |
$user = App::make('User'); /* you can't use new User */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class User { | |
protected $notifier; | |
public function __construct() | |
{ | |
$this->notifier = App::make('NotifierInterface'); | |
} | |
public function update() | |
{ | |
// update user. | |
$this->notifier->send(); | |
} | |
} | |
App::bind('NotifierInterface', 'EmailNotifier'); | |
$user = App::make('User'); /* or new User */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment