Answer the question
In order to leave comments, you need to log in
How to implement such a fluent interface in php?
I really liked the idea of a fluid interface that is used in Laravel 4 and Yii2. But, unfortunately, I cannot fully understand how such things are implemented.
Here is an example:
Route::get('/page/{id}', '[email protected]')->where(['id' => $id]);
Route::set('11', '22')->where('33');
class Route
{
public static function set($uri, $action)
{
return new Router($uri, $action);
}
}
class Router
{
private $params;
private $uri;
private $action;
public function __construct($uri, $action)
{
$this->uri = $uri;
$this->action = $action;
$this->master();
}
public function where($params)
{
$this->params = $params;
}
public function master()
{
echo $this->uri . ' | ' . $this->action . ' | ' . $this->params;
}
// ... ниже геттеры-сеттеры
Answer the question
In order to leave comments, you need to log in
Как реализовать подобное?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question