query() public méthode

Provides a read accessor for $this->query. Allows you to use a syntax similar to CakeSession for reading URL query data.
public query ( string $name ) : mixed
$name string Query string variable name
Résultat mixed The value being read
Exemple #1
0
 /**
  * Set output of book content.
  *
  * @access private
  * @return void
  */
 private function setVisibleContent()
 {
     $book = $this->epub;
     $component = $this->cakeRequest->query('comp');
     $callback = function ($m) use($book, $component) {
         $method = $m[1];
         $path = $m[2];
         $end = '';
         if (preg_match('/^src\\s*:/', $method)) {
             $end = ')';
         }
         if (preg_match('/^#/', $path)) {
             return $method . '\'' . $path . '\'' . $end;
         }
         $hash = '';
         if (preg_match('/^(.+)#(.+)$/', $path, $matches)) {
             $path = $matches[1];
             $hash = '#' . $matches[2];
         }
         $comp = $book->getComponentName($component, $path);
         if (!$comp) {
             return $method . '\'#\'' . $end;
         }
         $out = $method . '\'?comp=' . $comp . $hash . '\'' . $end;
         return $end ? $out : str_replace('&', '&', $out);
     };
     $content = preg_replace_callback(array('/(src\\s*:\\s*url\\()(.*?)\\)/', '/(\\@import\\s+)["\'](.*?)["\'];/', '/(href=)["\']([^:]*?)["\']/', '/(src=)["\']([^:]*?)["\']/'), $callback, $book->component($component));
     header('Pragma: public');
     header('Cache-Control: maxage=' . 1209600);
     header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 1209600) . ' GMT');
     header('Content-Type: ' . $book->componentContentType($component));
     print $content;
     exit;
 }
 public function authenticate(CakeRequest $request, CakeResponse $response)
 {
     $params = json_decode($request->query('params'), true);
     if (!isset($params['username'])) {
         $params = json_decode($request->data('params'), true);
     }
     $options = array('conditions' => array('User.username' . $this->userController->User->username => $params['username']));
     $result = $this->userController->User->find('first', $options);
     if ($result) {
         $password = sha1($result['User']['username'] . $result['User']['password']);
         if ("Promobot" . $password == $params['auth']) {
             return $result['User'];
         }
     }
     return false;
 }
 /**
  * Test the query() method with arrays passed via $_GET
  *
  * @return void
  */
 public function testQueryWithArray()
 {
     $_GET = array();
     $_GET['test'] = array('foo', 'bar');
     $request = new CakeRequest();
     $result = $request->query('test');
     $this->assertEquals(array('foo', 'bar'), $result);
     $result = $request->query('test.1');
     $this->assertEquals('bar', $result);
     $result = $request->query('test.2');
     $this->assertNull($result);
 }
Exemple #4
0
 /**
  * return request params
  *
  * @return array
  */
 protected function _getRequestParameters(CakeRequest $request)
 {
     //if (strpos($request->getRequestUri(), '&') === false) {
     //$this->_logger->debug('Requested url: ' . print_r($request->query, true));
     //$this->_logger->debug('Empty query: ' . print_r(empty($request->query), true));
     //$this->_logger->debug('Count query: ' . print_r(count($request->query), true));
     //if (strpos($request->url, '&') === false) {
     if (count($request->query) <= 1) {
         $this->_logger->debug('Non query request');
         $commands = array(0 => 'Sync', 1 => 'SendMail', 2 => 'SmartForward', 3 => 'SmartReply', 4 => 'GetAttachment', 9 => 'FolderSync', 10 => 'FolderCreate', 11 => 'FolderDelete', 12 => 'FolderUpdate', 13 => 'MoveItems', 14 => 'GetItemEstimate', 15 => 'MeetingResponse', 16 => 'Search', 17 => 'Settings', 18 => 'Ping', 19 => 'ItemOperations', 20 => 'Provision', 21 => 'ResolveRecipients', 22 => 'ValidateCert');
         //$requestParameters = substr($request->getRequestUri(), strpos($request->getRequestUri(), '?'));
         $requestParameters = substr($request->url, strpos($request->url, '?'));
         $stream = fopen("php://temp", 'r+');
         fwrite($stream, base64_decode($requestParameters));
         rewind($stream);
         // unpack the first 4 bytes
         $unpacked = unpack('CprotocolVersion/Ccommand/vlocale', fread($stream, 4));
         // 140 => 14.0
         $protocolVersion = substr($unpacked['protocolVersion'], 0, -1) . '.' . substr($unpacked['protocolVersion'], -1);
         $command = $commands[$unpacked['command']];
         $locale = $unpacked['locale'];
         // unpack deviceId
         $length = ord(fread($stream, 1));
         if ($length > 0) {
             $toUnpack = fread($stream, $length);
             $unpacked = unpack("H" . $length * 2 . "string", $toUnpack);
             $deviceId = $unpacked['string'];
         }
         // unpack policyKey
         $length = ord(fread($stream, 1));
         if ($length > 0) {
             $unpacked = unpack('Vstring', fread($stream, $length));
             $policyKey = $unpacked['string'];
         }
         // unpack device type
         $length = ord(fread($stream, 1));
         if ($length > 0) {
             $unpacked = unpack('A' . $length . 'string', fread($stream, $length));
             $deviceType = $unpacked['string'];
         }
         while (!feof($stream)) {
             $tag = ord(fread($stream, 1));
             $length = ord(fread($stream, 1));
             switch ($tag) {
                 case self::PARAMETER_ATTACHMENTNAME:
                     $unpacked = unpack('A' . $length . 'string', fread($stream, $length));
                     $attachmentName = $unpacked['string'];
                     break;
                 case self::PARAMETER_COLLECTIONID:
                     $unpacked = unpack('A' . $length . 'string', fread($stream, $length));
                     $collectionId = $unpacked['string'];
                     break;
                 case self::PARAMETER_ITEMID:
                     $unpacked = unpack('A' . $length . 'string', fread($stream, $length));
                     $itemId = $unpacked['string'];
                     break;
                 case self::PARAMETER_OPTIONS:
                     $options = ord(fread($stream, 1));
                     $saveInSent = !!($options & 0x1);
                     $acceptMultiPart = !!($options & 0x2);
                     break;
                 default:
                     if ($this->_logger instanceof Syncroton_Log) {
                         $this->_logger->critical(__METHOD__ . '::' . __LINE__ . " found unhandled command parameters");
                     }
             }
         }
         $result = array('protocolVersion' => $protocolVersion, 'command' => $command, 'deviceId' => $deviceId, 'deviceType' => isset($deviceType) ? $deviceType : null, 'policyKey' => isset($policyKey) ? $policyKey : null, 'saveInSent' => isset($saveInSent) ? $saveInSent : false, 'collectionId' => isset($collectionId) ? $collectionId : null, 'itemId' => isset($itemId) ? $itemId : null, 'attachmentName' => isset($attachmentName) ? $attachmentName : null, 'acceptMultipart' => isset($acceptMultiPart) ? $acceptMultiPart : false);
     } else {
         $result = array('protocolVersion' => $request->header('MS_ASPROTOCOLVERSION'), 'command' => $request->query('Cmd'), 'deviceId' => $request->query('DeviceId'), 'deviceType' => $request->query('DeviceType'), 'policyKey' => $request->header('X_MS_POLICYKEY'), 'saveInSent' => $request->query('SaveInSent') == 'T', 'collectionId' => $request->query('CollectionId'), 'itemId' => $request->query('ItemId'), 'attachmentName' => $request->query('AttachmentName'), 'acceptMultipart' => $request->header('MS_ASACCEPTMULTIPART') == 'T');
     }
     $result['userAgent'] = env('HTTP_USER_AGENT', $result['deviceType']);
     $result['contentType'] = env('CONTENT_TYPE');
     //$this->_logger->debug('Query result: ' . print_r($result, true));
     return $result;
 }