namespace Blog\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
/**
* PostsController controller.
*
* Handles the PostsController requests for the Blog module.
*
* @package Blog\Controller
*/
class PostsController extends AbstractActionController
{
/**
* Traits.
*/
use \Fork\Zend\ServiceManager\Traits\ServiceManagerAwareTrait;
use \Blog\View\Traits\PostsViewAwareTrait;
/**
* indexAction action.
*
* @return mixed
*/
public function indexAction()
{ /** Retrieve services and plugins. */
$postsView = $this->getPostsView();
/** Creates and settings view model. */
return (new ViewModel())
->setVariables($postsView->getListVariables())
->setVariables($postsView->getPaginationVariables())
;
}
}
namespace Blog\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
/**
* PostController controller.
*
* Handles the PostController requests for the Blog module.
*
* @package Blog\Controller
*/
class PostController extends AbstractActionController
{
/**
* Traits.
*/
use \Fork\Zend\ServiceManager\Traits\ServiceManagerAwareTrait;
use \Blog\View\Traits\PostViewAwareTrait;
/**
* indexAction action.
*
* @return mixed
*/
public function indexAction()
{ /** Retrieve services and plugins. */
$postView = $this->getPostView();
/** Retrieve request parameters. */
if (!empty($this->params('slugPost'))) {
/** Fetches entity corresponding request parameters. */
if (!empty($postViewVariables = $postView->getVariables())) {
return new ViewModel($postViewVariables);
} else { /** If entity not exists - return page "404". */
return $this->CreateHttpNotFoundModel($this->getResponse());
};
} else { /** Redirect to posts controller. */
return $this->redirect()->toRoute('posts');
};
}
}
<img src="/img/my_picture.jpg">
class IndexController extends AbstractActionController
{
use \Fork\Zend\ServiceManager\Traits\ServiceManagerAwareTrait;
...
}
'controllers' => [
'delegators' => [
Controller\IndexController::class => [ServiceManagerAwareDelegator::class],
],
],
Не совсем понял суть вашего ответа?
Можно пример? И где именно там контракт?
В трейте спокойно фиксируете проверку типов.
Например: