| 1 | <?php  | 
            ||
| 13 | trait ViewAwareTrait  | 
            ||
| 14 | { | 
            ||
| 15 | /**  | 
            ||
| 16 | * @var ViewResolver  | 
            ||
| 17 | */  | 
            ||
| 18 | protected $viewResolver;  | 
            ||
| 19 | |||
| 20 | /**  | 
            ||
| 21 | * @param ViewResolver $viewResolver  | 
            ||
| 22 | *  | 
            ||
| 23 | * @return ViewAwareTrait  | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 24 | * @required  | 
            ||
| 25 | */  | 
            ||
| 26 | public function setViewResolver(ViewResolver $viewResolver)  | 
            ||
| 32 | |||
| 33 | /**  | 
            ||
| 34 | * @param string $view A short notation view (a:b:c) "AppBundle:Default:homepage" or "homepage"  | 
            ||
| 35 | * (for same name view class as controller under View folder with suffix View instead of  | 
            ||
| 36 | * Controller for e.g. For AppBundle\Controller\DefaultController AppBundle\View\DefaultView  | 
            ||
| 37 | * @param mixed $data  | 
            ||
| 38 | *  | 
            ||
| 39 | * @return mixed  | 
            ||
| 40 | * @throws \InvalidArgumentException  | 
            ||
| 41 | */  | 
            ||
| 42 | protected function view($view, $data)  | 
            ||
| 54 | }  | 
            
In PHP traits cannot be used for type-hinting as they do not define a well-defined structure. This is because any class that uses a trait can rename that trait’s methods.
If you would like to return an object that has a guaranteed set of methods, you could create a companion interface that lists these methods explicitly.