Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
class EmailNotifier implements NotifierInterface {
public function send()
{
// send email.
}
}
<?php
interface NotifierInterface {
public function send();
}
<?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 */
<?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