Zend Framework教程之Zend_Controller_Plugin插件用法详解


Posted in PHP onMarch 07, 2016

本文实例讲述了Zend Framework教程之Zend_Controller_Plugin插件用法。分享给大家供大家参考,具体如下:

通过Zend_Controller_Plugin可以向前端控制器增加附加的功能。便于w一些特殊功能。以下是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 进入其分发循环(dispatch loop)前被调用。
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 'Zend/Controller/Plugin/Abstract.php';
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 'Zend/Controller/Exception.php';
   throw new Zend_Controller_Exception('Plugin already registered');
  }
  $stackIndex = (int) $stackIndex;
  if ($stackIndex) {
   if (isset($this->_plugins[$stackIndex])) {
    require_once 'Zend/Controller/Exception.php';
    throw new Zend_Controller_Exception('Plugin with stackIndex "' . $stackIndex . '" already registered');
   }
   $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 'Zend/Controller/Exception.php';
    throw new Zend_Controller_Exception('Plugin never registered.');
   }
   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 'Zend/Controller/Plugin/Abstract.php';
/** Zend_Registry */
require_once 'Zend/Registry.php';
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 = 'Zend_Controller_Plugin_ActionStack';
 /**
  * Valid keys for stack items
  * @var array
  */
 protected $_validKeys = array(
  'module',
  'controller',
  'action',
  'params'
 );
 /**
  * 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 'Zend/Controller/Exception.php';
   throw new Zend_Controller_Exception('ArrayStack should only contain request objects');
  }
  $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'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_Plugin_ErrorHandler

<?php
/** Zend_Controller_Plugin_Abstract */
require_once 'Zend/Controller/Plugin/Abstract.php';
class Zend_Controller_Plugin_ErrorHandler extends Zend_Controller_Plugin_Abstract
{
 /**
  * Const - No controller exception; controller does not exist
  */
 const EXCEPTION_NO_CONTROLLER = 'EXCEPTION_NO_CONTROLLER';
 /**
  * Const - No action exception; controller exists, but action does not
  */
 const EXCEPTION_NO_ACTION = 'EXCEPTION_NO_ACTION';
 /**
  * Const - No route exception; no routing was possible
  */
 const EXCEPTION_NO_ROUTE = 'EXCEPTION_NO_ROUTE';
 /**
  * Const - Other Exception; exceptions thrown by application controllers
  */
 const EXCEPTION_OTHER = 'EXCEPTION_OTHER';
 /**
  * Module to use for errors; defaults to default module in dispatcher
  * @var string
  */
 protected $_errorModule;
 /**
  * Controller to use for errors; defaults to 'error'
  * @var string
  */
 protected $_errorController = 'error';
 /**
  * Action to use for errors; defaults to 'error'
  * @var string
  */
 protected $_errorAction = 'error';
 /**
  * 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['module'])) {
   $this->setErrorHandlerModule($options['module']);
  }
  if (isset($options['controller'])) {
   $this->setErrorHandlerController($options['controller']);
  }
  if (isset($options['action'])) {
   $this->setErrorHandlerAction($options['action']);
  }
  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 'noErrorHandler' 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('noErrorHandler')) {
   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 'Zend_Controller_Router_Exception':
     if (404 == $exception->getCode()) {
      $error->type = self::EXCEPTION_NO_ROUTE;
     } else {
      $error->type = self::EXCEPTION_OTHER;
     }
     break;
    case 'Zend_Controller_Dispatcher_Exception':
     $error->type = self::EXCEPTION_NO_CONTROLLER;
     break;
    case 'Zend_Controller_Action_Exception':
     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('error_handler', $error)
     ->setModuleName($this->getErrorHandlerModule())
     ->setControllerName($this->getErrorHandlerController())
     ->setActionName($this->getErrorHandlerAction())
     ->setDispatched(false);
  }
 }
}

Zend_Controller_Plugin_PutHandler

<?php
require_once 'Zend/Controller/Plugin/Abstract.php';
require_once 'Zend/Controller/Request/Http.php';
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程序设计有所帮助。

PHP 相关文章推荐
文章推荐系统(三)
Oct 09 PHP
PHP+DBM的同学录程序(3)
Oct 09 PHP
PHP技术开发技巧分享
Mar 23 PHP
php smarty 二级分类代码和模版循环例子
Jun 01 PHP
PHP实现异步调用方法研究与分享
Oct 27 PHP
实测在class的function中include的文件中非php的global全局环境
Jul 15 PHP
PHP实现的多彩标签效果代码分享
Aug 21 PHP
PHP字符串比较函数strcmp()和strcasecmp()使用总结
Nov 19 PHP
PHP获取服务器端信息的方法
Nov 28 PHP
php简单生成一组与多组随机字符串的方法
May 09 PHP
PHP实现函数内修改外部变量值的方法示例
Dec 28 PHP
Laravel5.7 Eloquent ORM快速入门详解
Apr 12 PHP
Zend Framework教程之响应对象的封装Zend_Controller_Response实例详解
Mar 07 #PHP
Zend Framework教程之请求对象的封装Zend_Controller_Request实例详解
Mar 07 #PHP
Zend Framework教程之动作的基类Zend_Controller_Action详解
Mar 07 #PHP
Zend Framework教程之分发器Zend_Controller_Dispatcher用法详解
Mar 07 #PHP
Zend Framework教程之前端控制器Zend_Controller_Front用法详解
Mar 07 #PHP
在Yii2中使用Pjax导致Yii2内联脚本载入失败的原因分析
Mar 06 #PHP
Zend Framework动作助手Redirector用法实例详解
Mar 05 #PHP
You might like
thinkphp微信开发(消息加密解密)
2015/12/02 PHP
示例详解Laravel的注册重构
2016/08/14 PHP
jQuery 树形结构的选择器
2010/02/15 Javascript
JavaScript取得鼠标绝对位置程序代码介绍
2012/09/16 Javascript
js 判断文件类型并控制表单提交示例代码
2013/11/14 Javascript
node.js中的buffer.toString方法使用说明
2014/12/14 Javascript
jquery图形密码实现方法
2015/03/11 Javascript
js实现最短的XML格式化工具实例
2015/03/12 Javascript
jquery.validate提示错误信息位置方法
2016/01/22 Javascript
jquery+css3问卷答题卡翻页动画效果示例
2016/10/26 Javascript
JS 实现导航菜单中的二级下拉菜单的几种方式
2016/10/31 Javascript
ES6新特性四:变量的解构赋值实例
2017/04/21 Javascript
IE11下使用canvas.toDataURL报SecurityError错误的解决方法
2017/11/19 Javascript
详解angularjs 学习之 scope作用域
2018/01/15 Javascript
vue.js使用v-pre与v-html输出HTML操作示例
2018/07/07 Javascript
js canvas实现橡皮擦效果
2018/12/20 Javascript
js根据后缀判断文件文件类型的代码
2020/05/09 Javascript
python爬虫入门教程--快速理解HTTP协议(一)
2017/05/25 Python
Python实现基本数据结构中队列的操作方法示例
2017/12/04 Python
一条命令解决mac版本python IDLE不能输入中文问题
2018/05/15 Python
Django Admin实现三级联动的示例代码(省市区)
2018/06/22 Python
对python字典元素的添加与修改方法详解
2018/07/06 Python
Python Numpy库安装与基本操作示例
2019/01/08 Python
Django+python服务器部署与环境部署教程详解
2020/03/30 Python
Django自关联实现多级联动查询实例
2020/05/19 Python
Django创建一个后台的基本步骤记录
2020/10/02 Python
python实现移动木板小游戏
2020/10/09 Python
高三自我鉴定怎么写
2013/10/19 职场文书
应聘编辑职位自荐信范文
2014/01/05 职场文书
2014年三八妇女节活动总结
2014/03/01 职场文书
法学院毕业生求职信
2014/06/25 职场文书
住房租房协议书
2014/08/20 职场文书
大学军训自我鉴定大全
2014/09/18 职场文书
Python手拉手教你爬取贝壳房源数据的实战教程
2021/05/21 Python
springboot + mongodb 通过经纬度坐标匹配平面区域的方法
2021/11/01 MongoDB
Docker安装MySql8并远程访问的实现
2022/07/07 Servers