本文整理汇总了PHP中Zend\View\ViewEvent::getRequest方法的典型用法代码示例。如果您正苦于以下问题:PHP ViewEvent::getRequest方法的具体用法?PHP ViewEvent::getRequest怎么用?PHP ViewEvent::getRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\View\ViewEvent
的用法示例。
在下文中一共展示了ViewEvent::getRequest方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: injectResponse
/**
* @param ViewEvent $e
*
* @return null
*
* @throws \Zend\Config\Exception\RuntimeException
* @throws \Zend\Http\Exception\InvalidArgumentException
*/
public function injectResponse(ViewEvent $e)
{
$model = $e->getModel();
if (!$model instanceof ApiProblemModel) {
// Model is not an ApiProblemModel; we cannot handle it here
return null;
}
/** @var Request $request */
$request = $e->getRequest();
/** @var Accept $accept */
$accept = $request->getHeader('Accept');
if (!($accept instanceof Accept && $accept->hasMediaType('text/xml'))) {
return null;
}
$problem = $model->getApiProblem();
$statusCode = $this->getStatusCodeFromApiProblem($problem);
$contentType = 'text/xml';
/** @var Response $response */
$response = $e->getResponse();
$problemData = $problem->toArray();
$xmlWriter = new XmlWriter();
$output = $xmlWriter->processConfig($problemData);
$response->setStatusCode($statusCode);
$response->setContent($output);
$headers = $response->getHeaders();
$headers->addHeaderLine('Content-Type', $contentType);
}
示例2: selectRenderer
/**
* Detect if we should use the FeedRenderer based on model type and/or
* Accept header
*
* @param ViewEvent $e
* @return null|FeedRenderer
*/
public function selectRenderer(ViewEvent $e)
{
$model = $e->getModel();
if ($model instanceof Model\FeedModel) {
// FeedModel found
return $this->renderer;
}
$request = $e->getRequest();
if (!$request instanceof HttpRequest) {
// Not an HTTP request; cannot autodetermine
return;
}
$headers = $request->getHeaders();
if ($headers->has('accept')) {
$accept = $headers->get('accept');
foreach ($accept->getPrioritized() as $mediaType) {
if (0 === strpos($mediaType, 'application/rss+xml')) {
// application/rss+xml Accept header found
$this->renderer->setFeedType('rss');
return $this->renderer;
}
if (0 === strpos($mediaType, 'application/atom+xml')) {
// application/atom+xml Accept header found
$this->renderer->setFeedType('atom');
return $this->renderer;
}
}
}
// Not matched!
return;
}
示例3: selectRenderer
/**
* Detect if we should use the FeedRenderer based on model type and/or
* Accept header
*
* @param ViewEvent $e
* @return null|FeedRenderer
*/
public function selectRenderer(ViewEvent $e)
{
$model = $e->getModel();
if ($model instanceof Model\FeedModel) {
// FeedModel found
return $this->renderer;
}
$request = $e->getRequest();
if (!$request instanceof HttpRequest) {
// Not an HTTP request; cannot autodetermine
return;
}
$headers = $request->getHeaders();
if (!$headers->has('accept')) {
return;
}
$accept = $headers->get('accept');
if (($match = $accept->match('application/rss+xml, application/atom+xml')) == false) {
return;
}
if ($match->getTypeString() == 'application/rss+xml') {
$this->renderer->setFeedType('rss');
return $this->renderer;
}
if ($match->getTypeString() == 'application/atom+xml') {
$this->renderer->setFeedType('atom');
return $this->renderer;
}
}
示例4: selectRenderer
/**
* Detect if we should use the JsonRenderer based on model type and/or
* Accept header
*
* @param ViewEvent $e
* @return null|JsonRenderer
*/
public function selectRenderer(ViewEvent $e)
{
$model = $e->getModel();
if ($model instanceof Model\JsonModel) {
// JsonModel found
return $this->renderer;
}
$request = $e->getRequest();
if (!$request instanceof HttpRequest) {
// Not an HTTP request; cannot autodetermine
return;
}
$headers = $request->getHeaders();
if (!$headers->has('accept')) {
return;
}
$accept = $headers->get('Accept');
if (($match = $accept->match('application/json, application/javascript')) == false) {
return;
}
if ($match->getTypeString() == 'application/json') {
// application/json Accept header found
return $this->renderer;
}
if ($match->getTypeString() == 'application/javascript') {
// application/javascript Accept header found
if (false != ($callback = $request->getQuery()->get('callback'))) {
$this->renderer->setJsonpCallback($callback);
}
return $this->renderer;
}
}
示例5: selectRenderer
/**
* Detect if we should use the JsonRenderer based on model type and/or
* Accept header
*
* @param ViewEvent $e
* @return null|JsonRenderer
*/
public function selectRenderer(ViewEvent $e)
{
$model = $e->getModel();
if ($model instanceof Model\JsonModel) {
// JsonModel found
return $this->renderer;
}
$request = $e->getRequest();
if (!$request instanceof HttpRequest) {
// Not an HTTP request; cannot autodetermine
return;
}
$headers = $request->getHeaders();
if ($headers->has('accept')) {
$accept = $headers->get('Accept');
foreach ($accept->getPrioritized() as $mediaType) {
if (0 === strpos($mediaType, 'application/json')) {
// application/json Accept header found
return $this->renderer;
}
if (0 === strpos($mediaType, 'application/javascript')) {
// application/javascript Accept header found
if (false != ($callback = $request->getQuery()->get('callback'))) {
$this->renderer->setJsonpCallback($callback);
}
return $this->renderer;
}
}
}
// Not matched!
return;
}
示例6: selectRenderer
/**
* @param ViewEvent $e
* @return null|JsonRenderer
*/
public function selectRenderer(ViewEvent $e)
{
$model = $e->getModel();
if (!$model instanceof ApiBlueprintModel) {
return;
}
$this->renderer->setRequestUri($e->getRequest()->getUri());
$this->model = $model;
return $this->renderer;
}
开发者ID:weierophinney,项目名称:zf-apigility-documentation-apiblueprint,代码行数:14,代码来源:ApiBlueprintViewStrategy.php
示例7: selectRenderer
/**
* Detect if we should use the UploaderRenderer based on model type and/or
* Accept header
*
* @param ViewEvent $e
* @return null | RendererInterface
*/
public function selectRenderer(ViewEvent $e)
{
$model = $e->getModel();
if (!$model instanceof UploaderModelInterface) {
return null;
}
$this->renderer = $this->rendererFactory->createRenderer($e->getRequest()->getQuery());
// JsonModel found
return $this->renderer;
}
示例8: selectRenderer
/**
* Select the ViewRenderer
*
* @param ViewEvent $e
* @return ViewRenderer
*/
public function selectRenderer(ViewEvent $e)
{
if ($this->enhanced == false) {
$request = $e->getRequest();
$model = $e->getModel();
// this happens if the route is not matched properly
if (!$request instanceof Request) {
$request = new Request();
$e->setRequest($request);
}
// add base elements
$model->setVariable("base_url", $request->getServerUrl() . $request->getBaseUrl());
$model->setVariable("request", $request);
$model->setVariable("config", Registry::getInstance());
// add navigation
$nav = new Navigation($e);
$model->setVariable("navbar", $nav->getNavbar());
// show internal xml
if ($request->getParam('format') == 'xerxes') {
$this->renderer->setFormat('xml');
} else {
// determine which view script to use
if ($e->getResponse()->getStatusCode() != 200) {
$model->setVariable("display_exceptions", true);
$model->setTemplate('error/index.phtml');
} else {
// determine which view script to use
$script = $request->getControllerMap()->getView($request->getParam('format'));
// test view chosen
// header("Content-type: text/xml"); echo $request->getControllerMap()->saveXML(); echo "<!-- $script -->"; exit;
$model->setTemplate($script);
}
// render it
$display_as = "html";
if ($request->getParam('format') == 'json') {
$display_as = "json";
}
$this->renderer->setFormat($display_as);
}
$this->enhanced = true;
}
return $this->renderer;
}
示例9: selectRenderer
/**
* @param ViewEvent $e The ViewEvent instance
* @return RendererInterface
*/
public function selectRenderer($e)
{
$request = $e->getRequest();
$headers = $request->getHeaders();
$model = $e->getModel();
// No Accept header? return PhpRenderer
if (!$headers->has('accept')) {
return $this->phpRenderer;
}
$accept = $headers->get('accept');
/* @var $mediaType \Zend\Http\Header\Accept\FieldValuePart\AcceptFieldValuePart */
foreach ($accept->getPrioritized() as $mediaType) {
$mediaSubtype = $mediaType->getSubtype();
if ($mediaSubtype === 'json') {
if (!$model instanceof JsonModel && ($children = $model->getChildrenByCaptureTo('content', false))) {
$this->jsonRenderer->setMergeUnnamedChildren(true);
foreach ($children as $child) {
if (!$child instanceof JsonModel) {
$child->setCaptureTo(null);
}
}
}
return $this->jsonRenderer;
}
if ($mediaSubtype === 'rss+xml' || $mediaSubtype === 'atom+xml') {
$this->feedRenderer->setFeedType(substr($mediaSubtype, 0, strpos($mediaSubtype, '+')));
if (!$model instanceof FeedModel && ($children = $model->getChildrenByCaptureTo('content', false))) {
foreach ($children as $child) {
if (!$child instanceof FeedModel) {
$child->setCaptureTo(null);
}
}
}
return $this->feedRenderer;
}
}
// Nothing matched; return PhpRenderer. Technically, we should probably
// return an HTTP 415 Unsupported response.
return $this->phpRenderer;
}
示例10: selectRenderer
/**
* Detect if we should use the XmlRenderer based on model type and/or
* Accept header
*
* @param ViewEvent $e
* @return null|XmlRenderer
*/
public function selectRenderer(ViewEvent $e)
{
$model = $e->getModel();
$request = $e->getRequest();
if (!$request instanceof HttpRequest) {
// Not an HTTP request; cannot autodetermine
return $model instanceof Model\XmlModel ? $this->renderer : null;
}
$headers = $request->getHeaders();
if (!$headers->has('accept')) {
return $model instanceof Model\XmlModel ? $this->renderer : null;
}
$accept = $headers->get('Accept');
if (($match = $accept->match('application/xml')) == false) {
return $model instanceof Model\XmlModel ? $this->renderer : null;
}
#if ($match->getTypeString() == 'application/xml') {
# // application/xml Accept header found
# return $this->renderer;
#}
return $model instanceof Model\XmlModel ? $this->renderer : null;
}
示例11: selectRenderer
/**
* Select the ViewRenderer
*
* @param ViewEvent $e
* @return ViewRenderer
*/
public function selectRenderer(ViewEvent $e)
{
if ($this->enhanced == false) {
$request = $e->getRequest();
$model = $e->getModel();
$registry = Registry::getInstance();
// this happens if the route is not matched properly
if (!$request instanceof Request) {
$request = new Request();
$e->setRequest($request);
}
// add base elements
$model->setVariable("base_url", $request->getServerUrl() . $request->getBaseUrl());
$model->setVariable("request", $request);
$model->setVariable("config", $registry);
// add navigation
$nav = new Navigation($e);
$model->setVariable("navbar", $nav->getNavbar());
### flatten model
// @todo this seems really hacky, but our view renderer
// has no notion of children, so this makes our lives easier
foreach ($model->getChildren() as $child) {
// template specified
$model->setTemplate($child->getTemplate());
// terminate this?
$model->setTerminal($child->terminate());
// options
$options = $child->getOptions();
foreach ($options as $id => $value) {
$model->setOption($id, $value);
}
// variables
$child_variables = $child->getVariables();
foreach ($child_variables as $id => $value) {
$model->setVariable($id, $value);
}
}
// show internal xml
if ($request->getParam('format') == 'xerxes') {
$this->renderer->setFormat('xml');
} else {
// error
if ($e->getResponse()->getStatusCode() != 200) {
$display_excpetions = false;
if ($_SERVER['APPLICATION_ENV'] == 'development' || $registry->getConfig('DISPLAY_ERRORS', false, false) == true) {
$display_excpetions = true;
}
$model->setVariable("display_exceptions", $display_excpetions);
if ($e->getResponse()->getStatusCode() == 404) {
$model->setTemplate('error/404.phtml');
} else {
$model->setTemplate('error/index.phtml');
}
} elseif (!strstr($model->getTemplate(), '.')) {
$script = $request->getControllerMap()->getView($request->getParam('format'));
// test view chosen
// header("Content-type: text/xml"); echo $request->getControllerMap()->saveXML(); echo "<!-- $script -->"; exit;
$model->setTemplate($script);
}
// render it
$display_as = "html";
if ($request->getParam('format') == 'json') {
$display_as = "json";
}
$this->renderer->setFormat($display_as);
}
$this->enhanced = true;
}
return $this->renderer;
}
示例12: __construct
public function __construct(ViewEvent $e)
{
$this->request = $e->getRequest();
$this->registry = Registry::getInstance();
}
示例13: selectRenderer
/**
* Check if JsCustomStrategy has to be used (MVC action = \AssetsBundle\Mvc\Controller\AbstractActionController::JS_CUSTOM_ACTION)
* @param \Zend\View\ViewEvent $oEvent
* @throws \LogicException
* @return void|\AssetsBundle\View\Renderer\JsRenderer
*/
public function selectRenderer(\Zend\View\ViewEvent $oEvent)
{
$oRouter = $this->getRouter();
if (($oRequest = $oEvent->getRequest()) instanceof \Zend\Http\Request && ($oRouteMatch = $oRouter->match($oRequest)) instanceof \Zend\Mvc\Router\RouteMatch && $oRouteMatch->getParam('action') === \AssetsBundle\Mvc\Controller\AbstractActionController::JS_CUSTOM_ACTION) {
if (!($oViewModel = $oEvent->getModel()) instanceof \Zend\View\Model\ViewModel) {
throw new \UnexpectedValueException(sprintf('Event model expects an instance of "Zend\\View\\Model\\ViewModel", "%s" given', is_object($oViewModel) ? get_class($oViewModel) : gettype($oViewModel)));
} elseif (($oException = $oViewModel->getVariable('exception')) instanceof \Exception) {
return;
}
//jsCustomFiles is empty
if (!is_array($aJsCustomFiles = $oEvent->getModel()->getVariable('jsCustomFiles'))) {
$oEvent->getModel()->setVariable('jsCustomFiles', array());
}
return $this->getRenderer();
}
}