Heim Backend-Entwicklung PHP-Tutorial Verwendung des Zend_Controller_Plugin-Plug-Ins im Zend Framework

Verwendung des Zend_Controller_Plugin-Plug-Ins im Zend Framework

Jun 22, 2018 am 10:12 AM
framework zend 插件

In diesem Artikel wird hauptsächlich die Verwendung des Zend_Controller_Plugin-Plug-Ins im Zend Framework-Tutorial vorgestellt. Er analysiert detailliert das Prinzip des Zend_Controller_Plugin-Plug-Ins in Form von Beispielen, wie man es verwendet und verwandte Vorsichtsmaßnahmen kann darauf verweisen

In diesem Artikel werden die Beispiele erläutert. Erfahren Sie im Zend Framework-Tutorial, wie Sie das Zend_Controller_Plugin-Plug-In verwenden. Teilen Sie es als Referenz mit allen. Die Details lauten wie folgt:

Zusätzliche Funktionen können dem Front-End-Controller über Zend_Controller_Plugin hinzugefügt werden. Praktisch für einige Sonderfunktionen. Das Folgende ist eine kurze Einführung in Zend_Controller_Plugin.

Grundlegende Implementierung von Zend_Controller_Plugin

├── Plugin
│ ├── Abstract.php
│ ├── ActionStack.php

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()
 {}
}
Nach dem Login kopieren


Die Zend_Controller_Plugin_Abstract-Anweisung definiert mehrere wichtige Ereignisorte während des laufenden Prozesses von Zend_Controller. Benutzer können über bestimmte Methoden verwandte Vorgänge für Anforderungen und entsprechende Objekte an bestimmten Orten ausführen.

Die Beschreibung der Methoden in Zend_Controller_Plugin_Abstract lautet wie folgt:

routeStartup() wird aufgerufen, bevor Zend_Controller_Front eine Anfrage an den registrierten Router sendet.

routeShutdown() wird aufgerufen, nachdem der Router die Weiterleitung der Anfrage abgeschlossen hat.

dispatchLoopStartup() wird aufgerufen, bevor Zend_Controller_Front in seine Dispatch-Schleife eintritt.

preDispatch() wird aufgerufen, bevor die Aktion vom Dispatcher versendet wird. Diese Rückrufmethode ermöglicht Proxy- oder Filterverhalten. Durch Ändern der Anfrage und Zurücksetzen des Dispatch-Flags (mithilfe von Zend_Controller_Request_Abstract::setDispatched(false)) kann die aktuelle Aktion übersprungen oder ersetzt werden.

postDispatch() wird aufgerufen, nachdem die Aktion vom Dispatcher versendet wurde. Diese Rückrufmethode ermöglicht Proxy- oder Filterverhalten. Neue Aktionen können für die Verteilung angegeben werden, indem die Anfrage geändert und das Verteilungs-Flag zurückgesetzt wird (mithilfe von Zend_Controller_Request_Abstract::setDispatched(false)).

dispatchLoopShutdown() wird aufgerufen, nachdem Zend_Controller_Front seine Dispatch-Schleife verlassen hat.

Von Zend_Controller_Plugin bereitgestellte Standard-Plug-Ins:


Zend_Controller_Plugin_Broker: Plug-In-Broker, der zum Registrieren und Verwalten benutzerdefinierter Zend_Controller-Plug-Ins verwendet wird. Informationen zur spezifischen Verwendung finden Sie im Klassencode.
Zend_Controller_Plugin_ActionStack: wird zum Verwalten von Aktionsstapeln verwendet. Informationen zur spezifischen Verwendung finden Sie im Klassencode.
Zend_Controller_Plugin_ErrorHandler: Wird zur Behandlung ausgelöster Ausnahmen verwendet. Informationen zur spezifischen Verwendung finden Sie im Klassencode.
Zend_Controller_Plugin_PutHandler: wird zur Verarbeitung der Anforderungsoperation PUT verwendet. Informationen zur spezifischen Verwendung finden Sie im Klassencode.

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);
    }
   }
  }
 }
}
Nach dem Login kopieren



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);
 }
}
Nach dem Login kopieren

Zend_Controller_Plugin_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);
  }
 }
}
Nach dem Login kopieren

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);
  }
 }
}
Nach dem Login kopieren

Das Obige ist der gesamte Inhalt dieses Artikels. Ich hoffe, er wird für das Studium aller hilfreich sein. Weitere verwandte Inhalte finden Sie auf der chinesischen PHP-Website. Verwandte Empfehlungen:

Über die Verwendung der Zend_Config-Komponente im Zend Framework

Über die Verwendung von Zend_Db_Table_Rowset im Zend Framework


Das obige ist der detaillierte Inhalt vonVerwendung des Zend_Controller_Plugin-Plug-Ins im Zend Framework. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn

Heiße KI -Werkzeuge

Undresser.AI Undress

Undresser.AI Undress

KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover

AI Clothes Remover

Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool

Undress AI Tool

Ausziehbilder kostenlos

Clothoff.io

Clothoff.io

KI-Kleiderentferner

AI Hentai Generator

AI Hentai Generator

Erstellen Sie kostenlos Ai Hentai.

Heißer Artikel

R.E.P.O. Energiekristalle erklärten und was sie tun (gelber Kristall)
3 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Beste grafische Einstellungen
3 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. So reparieren Sie Audio, wenn Sie niemanden hören können
3 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌

Heiße Werkzeuge

Notepad++7.3.1

Notepad++7.3.1

Einfach zu bedienender und kostenloser Code-Editor

SublimeText3 chinesische Version

SublimeText3 chinesische Version

Chinesische Version, sehr einfach zu bedienen

Senden Sie Studio 13.0.1

Senden Sie Studio 13.0.1

Leistungsstarke integrierte PHP-Entwicklungsumgebung

Dreamweaver CS6

Dreamweaver CS6

Visuelle Webentwicklungstools

SublimeText3 Mac-Version

SublimeText3 Mac-Version

Codebearbeitungssoftware auf Gottesniveau (SublimeText3)

PyCharm-Einsteigerhandbuch: Umfassendes Verständnis der Plug-In-Installation! PyCharm-Einsteigerhandbuch: Umfassendes Verständnis der Plug-In-Installation! Feb 25, 2024 pm 11:57 PM

PyCharm ist eine leistungsstarke und beliebte integrierte Entwicklungsumgebung (IDE) für Python, die eine Fülle von Funktionen und Tools bereitstellt, damit Entwickler Code effizienter schreiben können. Der Plug-In-Mechanismus von PyCharm ist ein leistungsstarkes Tool zur Erweiterung seiner Funktionen. Durch die Installation verschiedener Plug-Ins können PyCharm um verschiedene Funktionen und benutzerdefinierte Funktionen erweitert werden. Daher ist es für PyCharm-Neulinge von entscheidender Bedeutung, die Installation von Plug-Ins zu verstehen und zu beherrschen. In diesem Artikel erhalten Sie eine detaillierte Einführung in die vollständige Installation des PyCharm-Plug-Ins.

Fehler beim Laden des Plugins in Illustrator [Behoben] Fehler beim Laden des Plugins in Illustrator [Behoben] Feb 19, 2024 pm 12:00 PM

Erscheint beim Starten von Adobe Illustrator eine Meldung über einen Fehler beim Laden des Plug-Ins? Bei einigen Illustrator-Benutzern ist dieser Fehler beim Öffnen der Anwendung aufgetreten. Der Meldung folgt eine Liste problematischer Plugins. Diese Fehlermeldung weist darauf hin, dass ein Problem mit dem installierten Plug-In vorliegt, es kann jedoch auch andere Gründe haben, beispielsweise eine beschädigte Visual C++-DLL-Datei oder eine beschädigte Einstellungsdatei. Wenn dieser Fehler auftritt, werden wir Sie in diesem Artikel bei der Behebung des Problems unterstützen. Lesen Sie daher weiter unten weiter. Fehler beim Laden des Plug-Ins in Illustrator Wenn Sie beim Versuch, Adobe Illustrator zu starten, die Fehlermeldung „Fehler beim Laden des Plug-Ins“ erhalten, können Sie Folgendes verwenden: Als Administrator

Was ist das Installationsverzeichnis der Chrome-Plug-in-Erweiterung? Was ist das Installationsverzeichnis der Chrome-Plug-in-Erweiterung? Mar 08, 2024 am 08:55 AM

Was ist das Installationsverzeichnis der Chrome-Plug-in-Erweiterung? Unter normalen Umständen lautet das Standardinstallationsverzeichnis von Chrome-Plug-In-Erweiterungen wie folgt: 1. Der Standard-Installationsverzeichnis-Speicherort von Chrome-Plug-Ins in Windows XP: C:\DocumentsandSettings\Benutzername\LocalSettings\ApplicationData\Google\Chrome\UserData\ Default\Extensions2. Chrome in Windows7 Der Standardinstallationsverzeichnisspeicherort des Plug-Ins: C:\Benutzer\Benutzername\AppData\Local\Google\Chrome\User

Teilen Sie drei Lösungen mit, warum der Edge-Browser dieses Plug-in nicht unterstützt Teilen Sie drei Lösungen mit, warum der Edge-Browser dieses Plug-in nicht unterstützt Mar 13, 2024 pm 04:34 PM

Wenn Benutzer den Edge-Browser verwenden, fügen sie möglicherweise einige Plug-Ins hinzu, um weitere Anforderungen zu erfüllen. Beim Hinzufügen eines Plug-Ins wird jedoch angezeigt, dass dieses Plug-In nicht unterstützt wird. Heute stellt Ihnen der Herausgeber drei Lösungen vor. Methode 1: Versuchen Sie es mit einem anderen Browser. Methode 2: Der Flash Player im Browser ist möglicherweise veraltet oder fehlt, sodass das Plug-in nicht unterstützt wird. Sie können die neueste Version von der offiziellen Website herunterladen. Methode 3: Drücken Sie gleichzeitig die Tasten „Strg+Umschalt+Entf“. Klicken Sie auf „Daten löschen“ und öffnen Sie den Browser erneut.

Unterstützt PyCharm Community Edition genügend Plugins? Unterstützt PyCharm Community Edition genügend Plugins? Feb 20, 2024 pm 04:42 PM

Unterstützt PyCharm Community Edition genügend Plugins? Benötigen Sie spezifische Codebeispiele Da die Python-Sprache im Bereich der Softwareentwicklung immer häufiger verwendet wird, wird PyCharm als professionelle integrierte Python-Entwicklungsumgebung (IDE) von Entwicklern bevorzugt. PyCharm ist in zwei Versionen unterteilt: die professionelle Version und die Community-Version. Die Community-Version wird kostenlos bereitgestellt, die Plug-in-Unterstützung ist jedoch im Vergleich zur professionellen Version eingeschränkt. Die Frage ist also: Unterstützt die PyCharm Community Edition genügend Plug-Ins? In diesem Artikel werden spezifische Codebeispiele verwendet

So fügen Sie die Funktionalität des WeChat-Miniprogramms zum WordPress-Plug-in hinzu So fügen Sie die Funktionalität des WeChat-Miniprogramms zum WordPress-Plug-in hinzu Sep 06, 2023 am 09:03 AM

So fügen Sie WeChat Mini-Programmfunktionen zu WordPress-Plugins hinzu. Mit der Beliebtheit und Beliebtheit von WeChat Mini-Programmen beginnen immer mehr Websites und Anwendungen darüber nachzudenken, sie in WeChat Mini-Programme zu integrieren. Für Websites, die WordPress als Content-Management-System verwenden, kann das Hinzufügen der WeChat-Applet-Funktion den Benutzern ein komfortableres Zugriffserlebnis und mehr funktionale Auswahlmöglichkeiten bieten. In diesem Artikel erfahren Sie, wie Sie die Funktionalität des WeChat-Miniprogramms zum WordPress-Plug-in hinzufügen. Schritt 1: Registrieren Sie ein WeChat-Miniprogrammkonto. Zuerst müssen Sie die WeChat-App öffnen

So verwenden Sie das WordPress-Plugin, um eine sofortige Positionierungsfunktion zu erreichen So verwenden Sie das WordPress-Plugin, um eine sofortige Positionierungsfunktion zu erreichen Sep 05, 2023 pm 04:51 PM

So nutzen Sie WordPress-Plug-Ins, um eine sofortige Standortfunktion zu erreichen. Mit der Beliebtheit mobiler Geräte beginnen immer mehr Websites, geolokalisierungsbasierte Dienste anzubieten. Auf WordPress-Websites können wir Plug-ins verwenden, um Funktionen zur sofortigen Positionierung zu implementieren und Besuchern Dienste im Zusammenhang mit ihrem geografischen Standort anzubieten. 1. Wählen Sie das richtige Plug-in. In der WordPress-Plug-in-Bibliothek stehen viele Plug-ins zur Auswahl. Je nach Bedarf und Anforderungen ist die Auswahl des richtigen Plug-Ins der Schlüssel zur sofortigen Positionierungsfunktionalität. Hier sind einige

So verwenden Sie das WordPress-Plugin zur Implementierung der Videowiedergabefunktion So verwenden Sie das WordPress-Plugin zur Implementierung der Videowiedergabefunktion Sep 05, 2023 pm 12:55 PM

So verwenden Sie das WordPress-Plugin zur Implementierung der Videowiedergabefunktion 1. Einführung Die Verwendung von Videos auf Websites und Blogs wird immer häufiger. Um ein qualitativ hochwertiges Benutzererlebnis zu bieten, können wir WordPress-Plugins verwenden, um Videowiedergabefunktionen zu implementieren. In diesem Artikel wird die Verwendung von WordPress-Plugins zur Implementierung von Videowiedergabefunktionen vorgestellt und Codebeispiele bereitgestellt. 2. Plug-Ins auswählen WordPress bietet viele Plug-Ins für die Videowiedergabe zur Auswahl. Bei der Auswahl eines Plug-Ins müssen wir folgende Aspekte berücksichtigen: Kompatibilität: Stellen Sie sicher, dass das Plug-In vorhanden ist

See all articles