Last active
August 29, 2015 14:05
-
-
Save rizqidjamaluddin/72f5cc7fc22f336dac7a to your computer and use it in GitHub Desktop.
Experimental cross-package decoration
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 | |
// part of "Users" package | |
/* | |
* The drawback here is that the User class must be moved into the userland space so the developers can attach | |
* decorating packages to it. Maybe this could be set up automatically via a (laravel-specific) config var? | |
*/ | |
class User { | |
// something like this could also be bound via the IoC container instead of the constructor | |
public static function make($email, $password) { | |
// developers customize this as a way of "I want to use that package on this model" | |
return new RemindableUserDecorator(new static($email, $password)); | |
} | |
public function getEmail(){} | |
public function matchPassword(){} | |
// ... | |
} | |
// part of "Remindable Users" package | |
class RemindableUserDecorator { | |
public function __construct($user){ | |
$this->user = $user; | |
} | |
public function sendReminderEmail(){} | |
// decorator __call method etc | |
// ... | |
} | |
// in use | |
$user = User::make("[email protected]", "12345"); | |
$user->sendReminderEmail(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment