백엔드 개발 PHP 튜토리얼 Zend Framework에서 Zend_Controller_Plugin 플러그인 사용

Zend Framework에서 Zend_Controller_Plugin 플러그인 사용

Jun 22, 2018 am 10:12 AM
framework zend 플러그인

이 글은 Zend Framework 튜토리얼에서 Zend_Controller_Plugin 플러그인의 사용법을 주로 소개하고 있으며, Zend_Controller_Plugin 플러그인의 원리와 사용법, 관련 주의사항을 예시 형식으로 자세히 분석하고 있습니다.

이 문서에서는 Zend Framework 튜토리얼 Zend_Controller_Plugin을 예제와 함께 설명합니다. 참고할 수 있도록 모든 사람과 공유하세요. 세부 사항은 다음과 같습니다.

Zend_Controller_Plugin을 통해 프런트엔드 컨트롤러에 추가 기능을 추가할 수 있습니다. 일부 특수 기능에 편리합니다. 다음은 Zend_Controller_Plugin에 대한 간략한 소개입니다.

Zend_Controller_Plugin 기본 구현

├── Plugin
│ ├── Abstract.php
│ ├── ActionStack.php
│ ├── Broker.php
│ ├── ErrorHandler.php
│ └ ─ ─PutHandler.php

Zend_Controller_Plugin_Abstract

abstract class Zend_Controller_Plugin_Abstract
{
 protected $_request;
 protected $_response;
 public function setRequest(Zend_Controller_Request_Abstract $request)
 {
  $this->_request = $request;
  return $this;
 }
 public function getRequest()
 {
  return $this->_request;
 }
 public function setResponse(Zend_Controller_Response_Abstract $response)
 {
  $this->_response = $response;
  return $this;
 }
 public function getResponse()
 {
  return $this->_response;
 }
 /**
  * Called before Zend_Controller_Front begins evaluating the
  * request against its routes.
  *
  * @param Zend_Controller_Request_Abstract $request
  * @return void
  */
 public function routeStartup(Zend_Controller_Request_Abstract $request)
 {}
 /**
  * Called after Zend_Controller_Router exits.
  *
  * Called after Zend_Controller_Front exits from the router.
  *
  * @param Zend_Controller_Request_Abstract $request
  * @return void
  */
 public function routeShutdown(Zend_Controller_Request_Abstract $request)
 {}
 /**
  * Called before Zend_Controller_Front enters its dispatch loop.
  *
  * @param Zend_Controller_Request_Abstract $request
  * @return void
  */
 public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
 {}
 /**
  * Called before an action is dispatched by Zend_Controller_Dispatcher.
  *
  * This callback allows for proxy or filter behavior. By altering the
  * request and resetting its dispatched flag (via
  * {@link Zend_Controller_Request_Abstract::setDispatched() setDispatched(false)}),
  * the current action may be skipped.
  *
  * @param Zend_Controller_Request_Abstract $request
  * @return void
  */
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {}
 /**
  * Called after an action is dispatched by Zend_Controller_Dispatcher.
  *
  * This callback allows for proxy or filter behavior. By altering the
  * request and resetting its dispatched flag (via
  * {@link Zend_Controller_Request_Abstract::setDispatched() setDispatched(false)}),
  * a new action may be specified for dispatching.
  *
  * @param Zend_Controller_Request_Abstract $request
  * @return void
  */
 public function postDispatch(Zend_Controller_Request_Abstract $request)
 {}
 /**
  * Called before Zend_Controller_Front exits its dispatch loop.
  *
  * @return void
  */
 public function dispatchLoopShutdown()
 {}
}
로그인 후 복사

Zend_Controller_Plugin_Abstract 문은 Zend_Controller 실행 프로세스 중 여러 주요 이벤트 위치를 정의합니다. 사용자는 지정된 방법을 통해 지정된 위치 및 해당 개체의 요청에 대해 관련 작업을 수행할 수 있습니다.

Zend_Controller_Plugin_Abstract의 메소드에 대한 설명은 다음과 같습니다.

routeStartup()은 Zend_Controller_Front가 등록된 라우터에 요청을 보내기 전에 호출됩니다.
routeShutdown()은 라우터가 요청 라우팅을 완료한 후에 호출됩니다.
dispatchLoopStartup()은 Zend_Controller_Front가 디스패치 루프에 들어가기 전에 호출됩니다.
preDispatch()는 디스패처가 작업을 전달하기 전에 호출됩니다. 이 콜백 메서드는 프록시 또는 필터링 동작을 허용합니다. 요청을 수정하고 디스패치 플래그를 재설정함으로써(Zend_Controller_Request_Abstract::setDispatched(false) 사용) 현재 작업을 건너뛰거나 교체할 수 있습니다.
postDispatch()는 디스패처가 작업을 전달한 후에 호출됩니다. 이 콜백 메서드는 프록시 또는 필터링 동작을 허용합니다. 요청을 수정하고 배포 플래그를 재설정하여(Zend_Controller_Request_Abstract::setDispatched(false) 사용) 배포를 위한 새 작업을 지정할 수 있습니다.
dispatchLoopShutdown()은 Zend_Controller_Front가 디스패치 루프를 시작한 후에 호출됩니다.

Zend_Controller_Plugin에서 제공하는 기본 플러그인:

Zend_Controller_Plugin_Broker: 맞춤형 Zend_Controller 플러그인을 등록하고 관리하는 데 사용되는 플러그인 브로커. 구체적인 사용법은 클래스 코드를 참고하세요.
Zend_Controller_Plugin_ActionStack: 액션 스택을 관리하는 데 사용됩니다. 구체적인 사용법은 클래스 코드를 참고하세요.
Zend_Controller_Plugin_ErrorHandler: 발생한 예외를 처리하는 데 사용됩니다. 구체적인 사용법은 클래스 코드를 참고하세요.
Zend_Controller_Plugin_PutHandler: 요청 작업 PUT을 처리하는 데 사용됩니다. 구체적인 사용법은 클래스 코드를 참고하세요.

Zend_Controller_Plugin_Broker

<?php
/** Zend_Controller_Plugin_Abstract */
require_once &#39;Zend/Controller/Plugin/Abstract.php&#39;;
class Zend_Controller_Plugin_Broker extends Zend_Controller_Plugin_Abstract
{
 protected $_plugins = array();
 /**
  * Register a plugin.
  *
  * @param Zend_Controller_Plugin_Abstract $plugin
  * @param int $stackIndex
  * @return Zend_Controller_Plugin_Broker
  */
 public function registerPlugin(Zend_Controller_Plugin_Abstract $plugin, $stackIndex = null)
 {
  if (false !== array_search($plugin, $this->_plugins, true)) {
   require_once &#39;Zend/Controller/Exception.php&#39;;
   throw new Zend_Controller_Exception(&#39;Plugin already registered&#39;);
  }
  $stackIndex = (int) $stackIndex;
  if ($stackIndex) {
   if (isset($this->_plugins[$stackIndex])) {
    require_once &#39;Zend/Controller/Exception.php&#39;;
    throw new Zend_Controller_Exception(&#39;Plugin with stackIndex "&#39; . $stackIndex . &#39;" already registered&#39;);
   }
   $this->_plugins[$stackIndex] = $plugin;
  } else {
   $stackIndex = count($this->_plugins);
   while (isset($this->_plugins[$stackIndex])) {
    ++$stackIndex;
   }
   $this->_plugins[$stackIndex] = $plugin;
  }
  $request = $this->getRequest();
  if ($request) {
   $this->_plugins[$stackIndex]->setRequest($request);
  }
  $response = $this->getResponse();
  if ($response) {
   $this->_plugins[$stackIndex]->setResponse($response);
  }
  ksort($this->_plugins);
  return $this;
 }
 /**
  * Unregister a plugin.
  *
  * @param string|Zend_Controller_Plugin_Abstract $plugin Plugin object or class name
  * @return Zend_Controller_Plugin_Broker
  */
 public function unregisterPlugin($plugin)
 {
  if ($plugin instanceof Zend_Controller_Plugin_Abstract) {
   // Given a plugin object, find it in the array
   $key = array_search($plugin, $this->_plugins, true);
   if (false === $key) {
    require_once &#39;Zend/Controller/Exception.php&#39;;
    throw new Zend_Controller_Exception(&#39;Plugin never registered.&#39;);
   }
   unset($this->_plugins[$key]);
  } elseif (is_string($plugin)) {
   // Given a plugin class, find all plugins of that class and unset them
   foreach ($this->_plugins as $key => $_plugin) {
    $type = get_class($_plugin);
    if ($plugin == $type) {
     unset($this->_plugins[$key]);
    }
   }
  }
  return $this;
 }
 /**
  * Is a plugin of a particular class registered?
  *
  * @param string $class
  * @return bool
  */
 public function hasPlugin($class)
 {
  foreach ($this->_plugins as $plugin) {
   $type = get_class($plugin);
   if ($class == $type) {
    return true;
   }
  }
  return false;
 }
 /**
  * Retrieve a plugin or plugins by class
  *
  * @param string $class Class name of plugin(s) desired
  * @return false|Zend_Controller_Plugin_Abstract|array Returns false if none found, plugin if only one found, and array of plugins if multiple plugins of same class found
  */
 public function getPlugin($class)
 {
  $found = array();
  foreach ($this->_plugins as $plugin) {
   $type = get_class($plugin);
   if ($class == $type) {
    $found[] = $plugin;
   }
  }
  switch (count($found)) {
   case 0:
    return false;
   case 1:
    return $found[0];
   default:
    return $found;
  }
 }
 /**
  * Retrieve all plugins
  *
  * @return array
  */
 public function getPlugins()
 {
  return $this->_plugins;
 }
 /**
  * Set request object, and register with each plugin
  *
  * @param Zend_Controller_Request_Abstract $request
  * @return Zend_Controller_Plugin_Broker
  */
 public function setRequest(Zend_Controller_Request_Abstract $request)
 {
  $this->_request = $request;
  foreach ($this->_plugins as $plugin) {
   $plugin->setRequest($request);
  }
  return $this;
 }
 /**
  * Get request object
  *
  * @return Zend_Controller_Request_Abstract $request
  */
 public function getRequest()
 {
  return $this->_request;
 }
 /**
  * Set response object
  *
  * @param Zend_Controller_Response_Abstract $response
  * @return Zend_Controller_Plugin_Broker
  */
 public function setResponse(Zend_Controller_Response_Abstract $response)
 {
  $this->_response = $response;
  foreach ($this->_plugins as $plugin) {
   $plugin->setResponse($response);
  }
  return $this;
 }
 /**
  * Get response object
  *
  * @return Zend_Controller_Response_Abstract $response
  */
 public function getResponse()
 {
  return $this->_response;
 }
 /**
  * Called before Zend_Controller_Front begins evaluating the
  * request against its routes.
  *
  * @param Zend_Controller_Request_Abstract $request
  * @return void
  */
 public function routeStartup(Zend_Controller_Request_Abstract $request)
 {
  foreach ($this->_plugins as $plugin) {
   try {
    $plugin->routeStartup($request);
   } catch (Exception $e) {
    if (Zend_Controller_Front::getInstance()->throwExceptions()) {
     throw new Zend_Controller_Exception($e->getMessage() . $e->getTraceAsString(), $e->getCode(), $e);
    } else {
     $this->getResponse()->setException($e);
    }
   }
  }
 }
 /**
  * Called before Zend_Controller_Front exits its iterations over
  * the route set.
  *
  * @param Zend_Controller_Request_Abstract $request
  * @return void
  */
 public function routeShutdown(Zend_Controller_Request_Abstract $request)
 {
  foreach ($this->_plugins as $plugin) {
   try {
    $plugin->routeShutdown($request);
   } catch (Exception $e) {
    if (Zend_Controller_Front::getInstance()->throwExceptions()) {
     throw new Zend_Controller_Exception($e->getMessage() . $e->getTraceAsString(), $e->getCode(), $e);
    } else {
     $this->getResponse()->setException($e);
    }
   }
  }
 }
 /**
  * Called before Zend_Controller_Front enters its dispatch loop.
  *
  * During the dispatch loop, Zend_Controller_Front keeps a
  * Zend_Controller_Request_Abstract object, and uses
  * Zend_Controller_Dispatcher to dispatch the
  * Zend_Controller_Request_Abstract object to controllers/actions.
  *
  * @param Zend_Controller_Request_Abstract $request
  * @return void
  */
 public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
 {
  foreach ($this->_plugins as $plugin) {
   try {
    $plugin->dispatchLoopStartup($request);
   } catch (Exception $e) {
    if (Zend_Controller_Front::getInstance()->throwExceptions()) {
     throw new Zend_Controller_Exception($e->getMessage() . $e->getTraceAsString(), $e->getCode(), $e);
    } else {
     $this->getResponse()->setException($e);
    }
   }
  }
 }
 /**
  * Called before an action is dispatched by Zend_Controller_Dispatcher.
  *
  * @param Zend_Controller_Request_Abstract $request
  * @return void
  */
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
  foreach ($this->_plugins as $plugin) {
   try {
    $plugin->preDispatch($request);
   } catch (Exception $e) {
    if (Zend_Controller_Front::getInstance()->throwExceptions()) {
     throw new Zend_Controller_Exception($e->getMessage() . $e->getTraceAsString(), $e->getCode(), $e);
    } else {
     $this->getResponse()->setException($e);
     // skip rendering of normal dispatch give the error handler a try
     $this->getRequest()->setDispatched(false);
    }
   }
  }
 }
 /**
  * Called after an action is dispatched by Zend_Controller_Dispatcher.
  *
  * @param Zend_Controller_Request_Abstract $request
  * @return void
  */
 public function postDispatch(Zend_Controller_Request_Abstract $request)
 {
  foreach ($this->_plugins as $plugin) {
   try {
    $plugin->postDispatch($request);
   } catch (Exception $e) {
    if (Zend_Controller_Front::getInstance()->throwExceptions()) {
     throw new Zend_Controller_Exception($e->getMessage() . $e->getTraceAsString(), $e->getCode(), $e);
    } else {
     $this->getResponse()->setException($e);
    }
   }
  }
 }
 /**
  * Called before Zend_Controller_Front exits its dispatch loop.
  *
  * @param Zend_Controller_Request_Abstract $request
  * @return void
  */
 public function dispatchLoopShutdown()
 {
  foreach ($this->_plugins as $plugin) {
   try {
    $plugin->dispatchLoopShutdown();
   } catch (Exception $e) {
    if (Zend_Controller_Front::getInstance()->throwExceptions()) {
     throw new Zend_Controller_Exception($e->getMessage() . $e->getTraceAsString(), $e->getCode(), $e);
    } else {
     $this->getResponse()->setException($e);
    }
   }
  }
 }
}
로그인 후 복사

Zend_Controller_Plugin_ActionStack

<?php
/** Zend_Controller_Plugin_Abstract */
require_once &#39;Zend/Controller/Plugin/Abstract.php&#39;;
/** Zend_Registry */
require_once &#39;Zend/Registry.php&#39;;
class Zend_Controller_Plugin_ActionStack extends Zend_Controller_Plugin_Abstract
{
 /** @var Zend_Registry */
 protected $_registry;
 /**
  * Registry key under which actions are stored
  * @var string
  */
 protected $_registryKey = &#39;Zend_Controller_Plugin_ActionStack&#39;;
 /**
  * Valid keys for stack items
  * @var array
  */
 protected $_validKeys = array(
  &#39;module&#39;,
  &#39;controller&#39;,
  &#39;action&#39;,
  &#39;params&#39;
 );
 /**
  * Flag to determine whether request parameters are cleared between actions, or whether new parameters
  * are added to existing request parameters.
  *
  * @var Bool
  */
 protected $_clearRequestParams = false;
 /**
  * Constructor
  *
  * @param Zend_Registry $registry
  * @param string $key
  * @return void
  */
 public function __construct(Zend_Registry $registry = null, $key = null)
 {
  if (null === $registry) {
   $registry = Zend_Registry::getInstance();
  }
  $this->setRegistry($registry);
  if (null !== $key) {
   $this->setRegistryKey($key);
  } else {
   $key = $this->getRegistryKey();
  }
  $registry[$key] = array();
 }
 /**
  * Set registry object
  *
  * @param Zend_Registry $registry
  * @return Zend_Controller_Plugin_ActionStack
  */
 public function setRegistry(Zend_Registry $registry)
 {
  $this->_registry = $registry;
  return $this;
 }
 /**
  * Retrieve registry object
  *
  * @return Zend_Registry
  */
 public function getRegistry()
 {
  return $this->_registry;
 }
 /**
  * Retrieve registry key
  *
  * @return string
  */
 public function getRegistryKey()
 {
  return $this->_registryKey;
 }
 /**
  * Set registry key
  *
  * @param string $key
  * @return Zend_Controller_Plugin_ActionStack
  */
 public function setRegistryKey($key)
 {
  $this->_registryKey = (string) $key;
  return $this;
 }
 /**
  * Set clearRequestParams flag
  *
  * @param bool $clearRequestParams
  * @return Zend_Controller_Plugin_ActionStack
  */
 public function setClearRequestParams($clearRequestParams)
 {
  $this->_clearRequestParams = (bool) $clearRequestParams;
  return $this;
 }
 /**
  * Retrieve clearRequestParams flag
  *
  * @return bool
  */
 public function getClearRequestParams()
 {
  return $this->_clearRequestParams;
 }
 /**
  * Retrieve action stack
  *
  * @return array
  */
 public function getStack()
 {
  $registry = $this->getRegistry();
  $stack = $registry[$this->getRegistryKey()];
  return $stack;
 }
 /**
  * Save stack to registry
  *
  * @param array $stack
  * @return Zend_Controller_Plugin_ActionStack
  */
 protected function _saveStack(array $stack)
 {
  $registry = $this->getRegistry();
  $registry[$this->getRegistryKey()] = $stack;
  return $this;
 }
 /**
  * Push an item onto the stack
  *
  * @param Zend_Controller_Request_Abstract $next
  * @return Zend_Controller_Plugin_ActionStack
  */
 public function pushStack(Zend_Controller_Request_Abstract $next)
 {
  $stack = $this->getStack();
  array_push($stack, $next);
  return $this->_saveStack($stack);
 }
 /**
  * Pop an item off the action stack
  *
  * @return false|Zend_Controller_Request_Abstract
  */
 public function popStack()
 {
  $stack = $this->getStack();
  if (0 == count($stack)) {
   return false;
  }
  $next = array_pop($stack);
  $this->_saveStack($stack);
  if (!$next instanceof Zend_Controller_Request_Abstract) {
   require_once &#39;Zend/Controller/Exception.php&#39;;
   throw new Zend_Controller_Exception(&#39;ArrayStack should only contain request objects&#39;);
  }
  $action = $next->getActionName();
  if (empty($action)) {
   return $this->popStack($stack);
  }
  $request = $this->getRequest();
  $controller = $next->getControllerName();
  if (empty($controller)) {
   $next->setControllerName($request->getControllerName());
  }
  $module = $next->getModuleName();
  if (empty($module)) {
   $next->setModuleName($request->getModuleName());
  }
  return $next;
 }
 /**
  * postDispatch() plugin hook -- check for actions in stack, and dispatch if any found
  *
  * @param Zend_Controller_Request_Abstract $request
  * @return void
  */
 public function postDispatch(Zend_Controller_Request_Abstract $request)
 {
  // Don&#39;t move on to next request if this is already an attempt to
  // forward
  if (!$request->isDispatched()) {
   return;
  }
  $this->setRequest($request);
  $stack = $this->getStack();
  if (empty($stack)) {
   return;
  }
  $next = $this->popStack();
  if (!$next) {
   return;
  }
  $this->forward($next);
 }
 /**
  * Forward request with next action
  *
  * @param array $next
  * @return void
  */
 public function forward(Zend_Controller_Request_Abstract $next)
 {
  $request = $this->getRequest();
  if ($this->getClearRequestParams()) {
   $request->clearParams();
  }
  $request->setModuleName($next->getModuleName())
    ->setControllerName($next->getControllerName())
    ->setActionName($next->getActionName())
    ->setParams($next->getParams())
    ->setDispatched(false);
 }
}
로그인 후 복사

Zend_Controller_P lugin_ErrorHandler

<?php
/** Zend_Controller_Plugin_Abstract */
require_once &#39;Zend/Controller/Plugin/Abstract.php&#39;;
class Zend_Controller_Plugin_ErrorHandler extends Zend_Controller_Plugin_Abstract
{
 /**
  * Const - No controller exception; controller does not exist
  */
 const EXCEPTION_NO_CONTROLLER = &#39;EXCEPTION_NO_CONTROLLER&#39;;
 /**
  * Const - No action exception; controller exists, but action does not
  */
 const EXCEPTION_NO_ACTION = &#39;EXCEPTION_NO_ACTION&#39;;
 /**
  * Const - No route exception; no routing was possible
  */
 const EXCEPTION_NO_ROUTE = &#39;EXCEPTION_NO_ROUTE&#39;;
 /**
  * Const - Other Exception; exceptions thrown by application controllers
  */
 const EXCEPTION_OTHER = &#39;EXCEPTION_OTHER&#39;;
 /**
  * Module to use for errors; defaults to default module in dispatcher
  * @var string
  */
 protected $_errorModule;
 /**
  * Controller to use for errors; defaults to &#39;error&#39;
  * @var string
  */
 protected $_errorController = &#39;error&#39;;
 /**
  * Action to use for errors; defaults to &#39;error&#39;
  * @var string
  */
 protected $_errorAction = &#39;error&#39;;
 /**
  * Flag; are we already inside the error handler loop?
  * @var bool
  */
 protected $_isInsideErrorHandlerLoop = false;
 /**
  * Exception count logged at first invocation of plugin
  * @var int
  */
 protected $_exceptionCountAtFirstEncounter = 0;
 /**
  * Constructor
  *
  * Options may include:
  * - module
  * - controller
  * - action
  *
  * @param Array $options
  * @return void
  */
 public function __construct(Array $options = array())
 {
  $this->setErrorHandler($options);
 }
 /**
  * setErrorHandler() - setup the error handling options
  *
  * @param array $options
  * @return Zend_Controller_Plugin_ErrorHandler
  */
 public function setErrorHandler(Array $options = array())
 {
  if (isset($options[&#39;module&#39;])) {
   $this->setErrorHandlerModule($options[&#39;module&#39;]);
  }
  if (isset($options[&#39;controller&#39;])) {
   $this->setErrorHandlerController($options[&#39;controller&#39;]);
  }
  if (isset($options[&#39;action&#39;])) {
   $this->setErrorHandlerAction($options[&#39;action&#39;]);
  }
  return $this;
 }
 /**
  * Set the module name for the error handler
  *
  * @param string $module
  * @return Zend_Controller_Plugin_ErrorHandler
  */
 public function setErrorHandlerModule($module)
 {
  $this->_errorModule = (string) $module;
  return $this;
 }
 /**
  * Retrieve the current error handler module
  *
  * @return string
  */
 public function getErrorHandlerModule()
 {
  if (null === $this->_errorModule) {
   $this->_errorModule = Zend_Controller_Front::getInstance()->getDispatcher()->getDefaultModule();
  }
  return $this->_errorModule;
 }
 /**
  * Set the controller name for the error handler
  *
  * @param string $controller
  * @return Zend_Controller_Plugin_ErrorHandler
  */
 public function setErrorHandlerController($controller)
 {
  $this->_errorController = (string) $controller;
  return $this;
 }
 /**
  * Retrieve the current error handler controller
  *
  * @return string
  */
 public function getErrorHandlerController()
 {
  return $this->_errorController;
 }
 /**
  * Set the action name for the error handler
  *
  * @param string $action
  * @return Zend_Controller_Plugin_ErrorHandler
  */
 public function setErrorHandlerAction($action)
 {
  $this->_errorAction = (string) $action;
  return $this;
 }
 /**
  * Retrieve the current error handler action
  *
  * @return string
  */
 public function getErrorHandlerAction()
 {
  return $this->_errorAction;
 }
 /**
  * Route shutdown hook -- Ccheck for router exceptions
  *
  * @param Zend_Controller_Request_Abstract $request
  */
 public function routeShutdown(Zend_Controller_Request_Abstract $request)
 {
  $this->_handleError($request);
 }
 /**
  * Pre dispatch hook -- check for exceptions and dispatch error handler if
  * necessary
  *
  * @param Zend_Controller_Request_Abstract $request
  */
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
  $this->_handleError($request);
 }
 /**
  * Post dispatch hook -- check for exceptions and dispatch error handler if
  * necessary
  *
  * @param Zend_Controller_Request_Abstract $request
  */
 public function postDispatch(Zend_Controller_Request_Abstract $request)
 {
  $this->_handleError($request);
 }
 /**
  * Handle errors and exceptions
  *
  * If the &#39;noErrorHandler&#39; front controller flag has been set,
  * returns early.
  *
  * @param Zend_Controller_Request_Abstract $request
  * @return void
  */
 protected function _handleError(Zend_Controller_Request_Abstract $request)
 {
  $frontController = Zend_Controller_Front::getInstance();
  if ($frontController->getParam(&#39;noErrorHandler&#39;)) {
   return;
  }
  $response = $this->getResponse();
  if ($this->_isInsideErrorHandlerLoop) {
   $exceptions = $response->getException();
   if (count($exceptions) > $this->_exceptionCountAtFirstEncounter) {
    // Exception thrown by error handler; tell the front controller to throw it
    $frontController->throwExceptions(true);
    throw array_pop($exceptions);
   }
  }
  // check for an exception AND allow the error handler controller the option to forward
  if (($response->isException()) && (!$this->_isInsideErrorHandlerLoop)) {
   $this->_isInsideErrorHandlerLoop = true;
   // Get exception information
   $error   = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS);
   $exceptions  = $response->getException();
   $exception  = $exceptions[0];
   $exceptionType = get_class($exception);
   $error->exception = $exception;
   switch ($exceptionType) {
    case &#39;Zend_Controller_Router_Exception&#39;:
     if (404 == $exception->getCode()) {
      $error->type = self::EXCEPTION_NO_ROUTE;
     } else {
      $error->type = self::EXCEPTION_OTHER;
     }
     break;
    case &#39;Zend_Controller_Dispatcher_Exception&#39;:
     $error->type = self::EXCEPTION_NO_CONTROLLER;
     break;
    case &#39;Zend_Controller_Action_Exception&#39;:
     if (404 == $exception->getCode()) {
      $error->type = self::EXCEPTION_NO_ACTION;
     } else {
      $error->type = self::EXCEPTION_OTHER;
     }
     break;
    default:
     $error->type = self::EXCEPTION_OTHER;
     break;
   }
   // Keep a copy of the original request
   $error->request = clone $request;
   // get a count of the number of exceptions encountered
   $this->_exceptionCountAtFirstEncounter = count($exceptions);
   // Forward to the error handler
   $request->setParam(&#39;error_handler&#39;, $error)
     ->setModuleName($this->getErrorHandlerModule())
     ->setControllerName($this->getErrorHandlerController())
     ->setActionName($this->getErrorHandlerAction())
     ->setDispatched(false);
  }
 }
}
로그인 후 복사

Zend_Controller_Plugin_PutHandler

<?php
require_once &#39;Zend/Controller/Plugin/Abstract.php&#39;;
require_once &#39;Zend/Controller/Request/Http.php&#39;;
class Zend_Controller_Plugin_PutHandler extends Zend_Controller_Plugin_Abstract
{
 /**
  * Before dispatching, digest PUT request body and set params
  *
  * @param Zend_Controller_Request_Abstract $request
  */
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
  if (!$request instanceof Zend_Controller_Request_Http) {
   return;
  }
  if ($this->_request->isPut()) {
   $putParams = array();
   parse_str($this->_request->getRawBody(), $putParams);
   $request->setParams($putParams);
  }
 }
}
로그인 후 복사

위 내용은 전체 내용입니다 이 글의 내용이 모든 분들의 학습에 도움이 되기를 바랍니다. 더 많은 관련 내용을 보시려면 PHP 중국어 웹사이트를 주목해주세요!

관련 권장 사항:

Zend Framework의 Zend_Config 구성 요소 사용 정보

Zend Framework의 Zend_Db_Table_Rowset 사용 정보

위 내용은 Zend Framework에서 Zend_Controller_Plugin 플러그인 사용의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

인기 기사

R.E.P.O. 에너지 결정과 그들이하는 일 (노란색 크리스탈)
3 몇 주 전 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 최고의 그래픽 설정
3 몇 주 전 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 아무도들을 수없는 경우 오디오를 수정하는 방법
3 몇 주 전 By 尊渡假赌尊渡假赌尊渡假赌

뜨거운 도구

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

PyCharm 초보자 가이드: 플러그인 설치에 대한 전반적인 이해! PyCharm 초보자 가이드: 플러그인 설치에 대한 전반적인 이해! Feb 25, 2024 pm 11:57 PM

PyCharm은 개발자가 코드를 보다 효율적으로 작성할 수 있도록 다양한 기능과 도구를 제공하는 강력하고 인기 있는 Python 통합 개발 환경(IDE)입니다. PyCharm의 플러그인 메커니즘은 기능을 확장하기 위한 강력한 도구입니다. 다양한 플러그인을 설치하면 PyCharm에 다양한 기능과 사용자 정의 기능을 추가할 수 있습니다. 따라서 PyCharm을 처음 접하는 사람이 플러그인을 이해하고 능숙하게 설치하는 것이 중요합니다. 이 문서에서는 PyCharm 플러그인의 전체 설치에 대해 자세히 소개합니다.

Illustrator에서 플러그인 로드 중 오류 발생 [수정됨] Illustrator에서 플러그인 로드 중 오류 발생 [수정됨] Feb 19, 2024 pm 12:00 PM

Adobe Illustrator를 시작할 때 플러그인 로딩 오류에 대한 메시지가 팝업됩니까? 일부 Illustrator 사용자는 응용 프로그램을 열 때 이 오류가 발생했습니다. 메시지 뒤에는 문제가 있는 플러그인 목록이 표시됩니다. 이 오류 메시지는 설치된 플러그인에 문제가 있음을 나타내지만 손상된 Visual C++ DLL 파일이나 손상된 기본 설정 파일과 같은 다른 이유로 인해 발생할 수도 있습니다. 이 오류가 발생하면 이 문서에서 문제 해결 방법을 안내하므로 아래 내용을 계속 읽어보세요. Illustrator에서 플러그인 로드 오류 Adobe Illustrator를 시작하려고 할 때 "플러그인 로드 오류" 오류 메시지가 표시되면 다음을 사용할 수 있습니다. 관리자로

Chrome 플러그인 확장 프로그램 설치 디렉터리는 무엇인가요? Chrome 플러그인 확장 프로그램 설치 디렉터리는 무엇인가요? Mar 08, 2024 am 08:55 AM

Chrome 플러그인 확장 프로그램 설치 디렉터리는 무엇인가요? 일반적인 상황에서 Chrome 플러그인 확장의 기본 설치 디렉터리는 다음과 같습니다. 1. windowsxp에서 Chrome 플러그인의 기본 설치 디렉터리 위치: C:\DocumentsandSettings\username\LocalSettings\ApplicationData\Google\Chrome\UserData\ Windows7의 Default\Extensions2.chrome 플러그인의 기본 설치 디렉터리 위치: C:\Users\username\AppData\Local\Google\Chrome\User

Edge 브라우저가 이 플러그인을 지원하지 않는 이유에 대한 세 가지 해결 방법을 공유하세요. Edge 브라우저가 이 플러그인을 지원하지 않는 이유에 대한 세 가지 해결 방법을 공유하세요. Mar 13, 2024 pm 04:34 PM

사용자가 Edge 브라우저를 사용할 때 더 많은 요구 사항을 충족하기 위해 일부 플러그인을 추가할 수 있습니다. 그런데 플러그인을 추가하면 해당 플러그인이 지원되지 않는다고 표시됩니다. 이 문제를 해결하는 방법은 무엇입니까? 오늘은 에디터가 세 가지 해결 방법을 알려드리겠습니다. 방법 1: 다른 브라우저를 사용해 보세요. 방법 2: 브라우저의 Flash Player가 오래되었거나 누락되어 플러그인이 지원되지 않을 수 있습니다. 공식 웹사이트에서 최신 버전을 다운로드할 수 있습니다. 방법 3: "Ctrl+Shift+Delete" 키를 동시에 누르세요. "데이터 지우기"를 클릭하고 브라우저를 다시 엽니다.

PyCharm Community Edition은 충분한 플러그인을 지원합니까? PyCharm Community Edition은 충분한 플러그인을 지원합니까? Feb 20, 2024 pm 04:42 PM

PyCharm Community Edition은 충분한 플러그인을 지원합니까? 구체적인 코드 예제가 필요 소프트웨어 개발 분야에서 Python 언어가 점점 더 널리 사용됨에 따라 전문적인 Python 통합 개발 환경(IDE)인 PyCharm이 개발자들에게 선호되고 있습니다. PyCharm은 Professional 버전과 Community 버전의 두 가지 버전으로 나누어집니다. Community 버전은 무료로 제공되지만 Professional 버전에 비해 플러그인 지원이 제한됩니다. 그렇다면 문제는 PyCharm Community Edition이 충분한 플러그인을 지원하느냐는 것입니다. 이 기사에서는 특정 코드 예제를 사용하여

WordPress 플러그인에 WeChat 미니 프로그램 기능을 추가하는 방법 WordPress 플러그인에 WeChat 미니 프로그램 기능을 추가하는 방법 Sep 06, 2023 am 09:03 AM

WordPress 플러그인에 WeChat 미니 프로그램 기능을 추가하는 방법 WeChat 미니 프로그램의 인기와 인기로 인해 점점 더 많은 웹사이트와 애플리케이션이 WeChat 미니 프로그램과의 통합을 고려하기 시작했습니다. 콘텐츠 관리 시스템으로 WordPress를 사용하는 웹사이트의 경우 WeChat 애플릿 기능을 추가하면 사용자에게 더욱 편리한 액세스 경험과 더 많은 기능적 선택권을 제공할 수 있습니다. 이 기사에서는 WordPress 플러그인에 WeChat 미니 프로그램 기능을 추가하는 방법을 소개합니다. 1단계: WeChat 미니 프로그램 계정을 등록하세요. 먼저 WeChat 앱을 열어야 합니다.

WordPress 플러그인을 사용하여 즉각적인 위치 지정 기능을 구현하는 방법 WordPress 플러그인을 사용하여 즉각적인 위치 지정 기능을 구현하는 방법 Sep 05, 2023 pm 04:51 PM

WordPress 플러그인을 사용하여 즉각적인 위치 기능을 구현하는 방법 모바일 장치의 인기로 인해 점점 더 많은 웹사이트가 위치정보 기반 서비스를 제공하기 시작했습니다. WordPress 웹사이트에서는 플러그인을 사용하여 즉각적인 위치 확인 기능을 구현하고 방문자에게 지리적 위치와 관련된 서비스를 제공할 수 있습니다. 1. 올바른 플러그인을 선택하세요. WordPress 플러그인 라이브러리에는 위치정보 서비스를 제공하는 플러그인이 많이 있습니다. 필요와 요구 사항에 따라 올바른 플러그인을 선택하는 것이 즉각적인 위치 지정 기능을 달성하는 열쇠입니다. 다음은 몇 가지입니다.

WordPress 플러그인을 사용하여 비디오 재생 기능을 구현하는 방법 WordPress 플러그인을 사용하여 비디오 재생 기능을 구현하는 방법 Sep 05, 2023 pm 12:55 PM

WordPress 플러그인을 사용하여 비디오 재생 기능을 구현하는 방법 1. 소개 웹 사이트와 블로그에서 비디오를 적용하는 것이 점점 더 보편화되고 있습니다. 고품질의 사용자 경험을 제공하기 위해 WordPress 플러그인을 사용하여 비디오 재생 기능을 구현할 수 있습니다. 이 기사에서는 WordPress 플러그인을 사용하여 비디오 재생 기능을 구현하는 방법을 소개하고 코드 예제를 제공합니다. 2. 플러그인 선택 WordPress에는 선택할 수 있는 다양한 비디오 재생 플러그인이 있습니다. 플러그인을 선택할 때 다음 측면을 고려해야 합니다. 호환성: 플러그인이 맞는지 확인하세요.

See all articles