A
A
Alexander2016-03-19 22:23:49
CodeIgniter
Alexander, 2016-03-19 22:23:49

The parameter controller, which is an object, should be typehinted. Cook better to do?

protected function tryRunMethod($controller, $method)
    {
        try {
            $controller->$method();
        } catch (\Exception $e) {
            $this->sandResponseCode(Response::HTTP_METHOD_NOT_ALLOWED);
            throw new \Exception($e);
        }
    }

How to make this piece better and get rid of this recommendatory inscription?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Ernest Faizullin, 2016-03-19
@OxGroup

i would try that

protected function tryRunMethod(Object $controller, $method)
    {
        try {
            $controller->$method();
        } catch (\Exception $e) {
            $this->sandResponseCode(Response::HTTP_METHOD_NOT_ALLOWED);
            throw new \Exception($e);
        }
    }

or better yet, specify which class $controller is an instance of
protected function tryRunMethod(ControllerClass $controller, $method)
    {
     ...
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question