bytic /
controllers
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | namespace Nip\Controllers\View; |
||||||
| 4 | |||||||
| 5 | use Nip\Controllers\Controller; |
||||||
| 6 | use Nip\Http\Request; |
||||||
| 7 | use Nip\Utility\Container; |
||||||
| 8 | use Nip\View\View; |
||||||
| 9 | |||||||
| 10 | /** |
||||||
| 11 | * Class ControllerViewHydrator |
||||||
| 12 | * @package Nip\Controllers\View |
||||||
| 13 | */ |
||||||
| 14 | class ControllerViewHydrator |
||||||
| 15 | { |
||||||
| 16 | |||||||
| 17 | /** |
||||||
| 18 | * @param View $view |
||||||
| 19 | * @param null $controller |
||||||
|
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||||||
| 20 | * @return mixed |
||||||
| 21 | */ |
||||||
| 22 | public static function initContentBlocks($view, $controller = null) |
||||||
| 23 | { |
||||||
| 24 | $action = inflector()->underscore($controller->getAction()); |
||||||
|
0 ignored issues
–
show
The method
getAction() does not exist on null.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||||
| 25 | $controller = $controller->getName(); |
||||||
| 26 | |||||||
| 27 | $view->setBlock('content', $controller . '/' . $action); |
||||||
| 28 | |||||||
| 29 | return $view; |
||||||
| 30 | } |
||||||
| 31 | |||||||
| 32 | /** |
||||||
| 33 | * @param $view |
||||||
| 34 | * @param null|Controller $controller |
||||||
| 35 | * @return mixed |
||||||
| 36 | */ |
||||||
| 37 | public static function initVars($view, $controller = null) |
||||||
| 38 | { |
||||||
| 39 | $request = static::detectRequest($controller); |
||||||
| 40 | if (method_exists($view, 'setRequest')) { |
||||||
| 41 | if ($request instanceof Request) { |
||||||
| 42 | $view->setRequest($request); |
||||||
| 43 | } |
||||||
| 44 | } |
||||||
| 45 | |||||||
| 46 | $view->set('controller', $controller->getName()); |
||||||
| 47 | $view->set('action', $controller->getAction()); |
||||||
| 48 | |||||||
| 49 | return $view; |
||||||
| 50 | } |
||||||
| 51 | |||||||
| 52 | /** |
||||||
| 53 | * @param $view |
||||||
| 54 | * @param void|Controller $controller |
||||||
| 55 | * @return mixed |
||||||
| 56 | */ |
||||||
| 57 | 1 | public static function populatePath($view, $controller = null) |
|||||
| 58 | { |
||||||
| 59 | 1 | $path = ViewPathDetector::for($controller); |
|||||
| 60 | 1 | if (is_dir($path)) { |
|||||
|
0 ignored issues
–
show
$path of type boolean is incompatible with the type string expected by parameter $filename of is_dir().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 61 | 1 | $view->setBasePath($path); |
|||||
| 62 | } |
||||||
| 63 | |||||||
| 64 | 1 | if (method_exists($controller, 'registerViewPaths')) |
|||||
| 65 | { |
||||||
| 66 | $controller->registerViewPaths($view); |
||||||
|
0 ignored issues
–
show
The method
registerViewPaths() does not exist on Nip\Controllers\Controller. Since you implemented __call, consider adding a @method annotation.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 67 | } |
||||||
| 68 | |||||||
| 69 | return $view; |
||||||
| 70 | } |
||||||
| 71 | |||||||
| 72 | /** |
||||||
| 73 | * @param null|Controller $controller |
||||||
| 74 | * @return array|Request|\Nip\Request|string|null |
||||||
| 75 | */ |
||||||
| 76 | protected static function detectRequest($controller = null) |
||||||
| 77 | { |
||||||
| 78 | if ($controller instanceof Controller && $controller->hasRequest()) { |
||||||
| 79 | return $controller->getRequest(); |
||||||
| 80 | } |
||||||
| 81 | if (function_exists('request') && Container::container()->has('request')) { |
||||||
| 82 | $request = request(); |
||||||
| 83 | if ($request instanceof Request) { |
||||||
| 84 | return $request; |
||||||
| 85 | } |
||||||
| 86 | } |
||||||
| 87 | return null; |
||||||
| 88 | } |
||||||
| 89 | } |
||||||
| 90 |