laravel — метод проверки переменных класса PHP методом

Я хочу нажать массив в метод массива запроса методом внутри класса.
так что я пишу это примерно так:

class Check {
protected $request;

function __construct($request) {
$this->request = $request;
}

public function author($request) {
$this->request->merge(['author' => 1 ]);
$this->identifier($this->request);
}

public function identifier($request) {
$this->request->merge(['identifier' => 'test' ]);
$this->kip($this->request);
}

public function kip($request) {
$this->request->merge(['kip' => 1 ]);
$this->NextMethodName($this->request);
}
// many more methods here that should merge to $request variable
}

Есть ли чистый способ предотвратить повторение $ this-> NextMethodName ($ this-> request)?

0

Решение

Ну, есть хитрый способ сделать что-то вроде этого

function __construct($request) {

$this->request = $request;

// get class methods

$methods = get_class_methods($this);

// remove constructor and static call method

$methods = array_diff($methods, [ '__construct', 'create_save_request']);

// execute every methods for $request to prepare save request array

foreach ($methods as $method) call_user_func([$this, $method]);

}
2

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector