PHP code example of n7olkachev / php-simple-delegator
1. Go to this page and download the library: Download n7olkachev/php-simple-delegator library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
n7olkachev / php-simple-delegator example snippets
class User extends Model
{
protected $fillable = [
'name',
];
}
class UserPresenter
{
use SimpleDelegator;
protected $user;
public function __construct($user)
{
$this->user = $user;
}
protected function delegatee()
{
return $this->user;
}
public function formattedName()
{
return 'Decorated ' . $this->user->name;
}
}
$decoratedUser = new UserPresenter($user);
$decoratedUser->formattedName() // call to decorator method
$decoratedUser->name // gets original name from User model
class NotifyingThread
{
protected $thread;
public function __construct($thread)
{
$this->thread = $thread;
}
public function addReply()
{
$reply = $this->thread->addReply();
Notification::send(
$reply->mentionedUsers(),
new YouWereMentioned($reply)
);
}
}
$thread = new NotifyingThread($thread);
$thread->addReply($data); // default logic + sending notification
use SimpleDelegator;
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.