Skip to content

Instantly share code, notes, and snippets.

@rizqidjamaluddin
Last active August 29, 2015 14:05
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 rizqidjamaluddin/72f5cc7fc22f336dac7a to your computer and use it in GitHub Desktop.
Save rizqidjamaluddin/72f5cc7fc22f336dac7a to your computer and use it in GitHub Desktop.
Experimental cross-package decoration
<?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("foo@bar.com", "12345");
$user->sendReminderEmail();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment