[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/maximebf/debugbar/src/DebugBar/ -> OpenHandler.php (source)

   1  <?php
   2  /*
   3   * This file is part of the DebugBar package.
   4   *
   5   * (c) 2013 Maxime Bouroumeau-Fuseau
   6   *
   7   * For the full copyright and license information, please view the LICENSE
   8   * file that was distributed with this source code.
   9   */
  10  
  11  namespace DebugBar;
  12  
  13  /**
  14   * Handler to list and open saved dataset
  15   */
  16  class OpenHandler
  17  {
  18      protected $debugBar;
  19  
  20      /**
  21       * @param DebugBar $debugBar
  22       * @throws DebugBarException
  23       */
  24      public function __construct(DebugBar $debugBar)
  25      {
  26          if (!$debugBar->isDataPersisted()) {
  27              throw new DebugBarException("DebugBar must have a storage backend to use OpenHandler");
  28          }
  29          $this->debugBar = $debugBar;
  30      }
  31  
  32      /**
  33       * Handles the current request
  34       *
  35       * @param array $request Request data
  36       * @param bool $echo
  37       * @param bool $sendHeader
  38       * @return string
  39       * @throws DebugBarException
  40       */
  41      public function handle($request = null, $echo = true, $sendHeader = true)
  42      {
  43          if ($request === null) {
  44              $request = $_REQUEST;
  45          }
  46  
  47          $op = 'find';
  48          if (isset($request['op'])) {
  49              $op = $request['op'];
  50              if (!in_array($op, array('find', 'get', 'clear'))) {
  51                  throw new DebugBarException("Invalid operation '{$request['op']}'");
  52              }
  53          }
  54  
  55          if ($sendHeader) {
  56              $this->debugBar->getHttpDriver()->setHeaders(array(
  57                      'Content-Type' => 'application/json'
  58                  ));
  59          }
  60  
  61          $response = json_encode(call_user_func(array($this, $op), $request));
  62          if ($echo) {
  63              echo $response;
  64          }
  65          return $response;
  66      }
  67  
  68      /**
  69       * Find operation
  70       * @param $request
  71       * @return array
  72       */
  73      protected function find($request)
  74      {
  75          $max = 20;
  76          if (isset($request['max'])) {
  77              $max = $request['max'];
  78          }
  79  
  80          $offset = 0;
  81          if (isset($request['offset'])) {
  82              $offset = $request['offset'];
  83          }
  84  
  85          $filters = array();
  86          foreach (array('utime', 'datetime', 'ip', 'uri', 'method') as $key) {
  87              if (isset($request[$key])) {
  88                  $filters[$key] = $request[$key];
  89              }
  90          }
  91  
  92          return $this->debugBar->getStorage()->find($filters, $max, $offset);
  93      }
  94  
  95      /**
  96       * Get operation
  97       * @param $request
  98       * @return array
  99       * @throws DebugBarException
 100       */
 101      protected function get($request)
 102      {
 103          if (!isset($request['id'])) {
 104              throw new DebugBarException("Missing 'id' parameter in 'get' operation");
 105          }
 106          return $this->debugBar->getStorage()->get($request['id']);
 107      }
 108  
 109      /**
 110       * Clear operation
 111       */
 112      protected function clear($request)
 113      {
 114          $this->debugBar->getStorage()->clear();
 115          return array('success' => true);
 116      }
 117  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer