"Fossies" - the Fresh Open Source Software Archive

Member "icingaweb2-2.11.4/library/vendor/Zend/Controller/Action/Helper/AutoComplete/Abstract.php" (26 Jan 2023, 4055 Bytes) of package /linux/www/icingaweb2-2.11.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 <?php
    2 /**
    3  * Zend Framework
    4  *
    5  * LICENSE
    6  *
    7  * This source file is subject to the new BSD license that is bundled
    8  * with this package in the file LICENSE.txt.
    9  * It is also available through the world-wide-web at this URL:
   10  * http://framework.zend.com/license/new-bsd
   11  * If you did not receive a copy of the license and are unable to
   12  * obtain it through the world-wide-web, please send an email
   13  * to license@zend.com so we can send you a copy immediately.
   14  *
   15  * @category   Zend
   16  * @package    Zend_Controller
   17  * @subpackage Zend_Controller_Action_Helper
   18  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
   19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
   20  * @version    $Id$
   21  */
   22 
   23 /**
   24  * @see Zend_Controller_Action_Helper_Abstract
   25  */
   26 
   27 /**
   28  * Create and send autocompletion lists
   29  *
   30  * @uses       Zend_Controller_Action_Helper_Abstract
   31  * @category   Zend
   32  * @package    Zend_Controller
   33  * @subpackage Zend_Controller_Action_Helper
   34  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
   35  * @license    http://framework.zend.com/license/new-bsd     New BSD License
   36  */
   37 abstract class Zend_Controller_Action_Helper_AutoComplete_Abstract extends Zend_Controller_Action_Helper_Abstract
   38 {
   39     /**
   40      * Suppress exit when sendJson() called
   41      *
   42      * @var boolean
   43      */
   44     public $suppressExit = false;
   45 
   46     /**
   47      * Validate autocompletion data
   48      *
   49      * @param  mixed $data
   50      * @return boolean
   51      */
   52     abstract public function validateData($data);
   53 
   54     /**
   55      * Prepare autocompletion data
   56      *
   57      * @param  mixed   $data
   58      * @param  boolean $keepLayouts
   59      * @return mixed
   60      */
   61     abstract public function prepareAutoCompletion($data, $keepLayouts = false);
   62 
   63     /**
   64      * Disable layouts and view renderer
   65      *
   66      * @return Zend_Controller_Action_Helper_AutoComplete_Abstract Provides a fluent interface
   67      */
   68     public function disableLayouts()
   69     {
   70         /**
   71          * @see Zend_Layout
   72          */
   73         if (null !== ($layout = Zend_Layout::getMvcInstance())) {
   74             $layout->disableLayout();
   75         }
   76 
   77         Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->setNoRender(true);
   78 
   79         return $this;
   80     }
   81 
   82     /**
   83      * Encode data to JSON
   84      *
   85      * @param  mixed $data
   86      * @param  bool  $keepLayouts
   87      * @throws Zend_Controller_Action_Exception
   88      * @return string
   89      */
   90     public function encodeJson($data, $keepLayouts = false)
   91     {
   92         if ($this->validateData($data)) {
   93             return Zend_Controller_Action_HelperBroker::getStaticHelper('Json')->encodeJson($data, $keepLayouts);
   94         }
   95 
   96         /**
   97          * @see Zend_Controller_Action_Exception
   98          */
   99         throw new Zend_Controller_Action_Exception('Invalid data passed for autocompletion');
  100     }
  101 
  102     /**
  103      * Send autocompletion data
  104      *
  105      * Calls prepareAutoCompletion, populates response body with this
  106      * information, and sends response.
  107      *
  108      * @param  mixed $data
  109      * @param  bool  $keepLayouts
  110      * @return string|void
  111      */
  112     public function sendAutoCompletion($data, $keepLayouts = false)
  113     {
  114         $data = $this->prepareAutoCompletion($data, $keepLayouts);
  115 
  116         $response = $this->getResponse();
  117         $response->setBody($data);
  118 
  119         if (!$this->suppressExit) {
  120             $response->sendResponse();
  121             exit;
  122         }
  123 
  124         return $data;
  125     }
  126 
  127     /**
  128      * Strategy pattern: allow calling helper as broker method
  129      *
  130      * Prepares autocompletion data and, if $sendNow is true, immediately sends
  131      * response.
  132      *
  133      * @param  mixed $data
  134      * @param  bool  $sendNow
  135      * @param  bool  $keepLayouts
  136      * @return string|void
  137      */
  138     public function direct($data, $sendNow = true, $keepLayouts = false)
  139     {
  140         if ($sendNow) {
  141             return $this->sendAutoCompletion($data, $keepLayouts);
  142         }
  143 
  144         return $this->prepareAutoCompletion($data, $keepLayouts);
  145     }
  146 }