示例#1
0
 /**
  * Test strip slashes from array when magic quotes enabled
  */
 public function testStripSlashesFromArrayWithMagicQuotes()
 {
     $data = array("This should have \"quotes\" in it", "And this \"too\" has quotes");
     $stripped = Slim_Http_Util::stripSlashesIfMagicQuotes($data, true);
     $this->assertEquals($data = array('This should have "quotes" in it', 'And this "too" has quotes'), $stripped);
 }
示例#2
0
 /**
  * Fetch POST data
  *
  * This method returns a key-value array of data sent in the HTTP request body, or
  * the value of a hash key if requested; if the array key does not exist, NULL is returned.
  *
  * @param   string $key
  * @return  array|mixed|null
  * @throws  RuntimeException If environment input is not available
  */
 public function post($key = null)
 {
     if (!isset($this->env['slim.input'])) {
         throw new RuntimeException('Missing slim.input in environment variables');
     }
     if (!isset($this->env['slim.request.form_hash'])) {
         $this->env['slim.request.form_hash'] = array();
         if ($this->isFormData() && is_string($this->env['slim.input'])) {
             $output = array();
             if (function_exists('mb_parse_str') && !isset($this->env['slim.tests.ignore_multibyte'])) {
                 mb_parse_str($this->env['slim.input'], $output);
             } else {
                 parse_str($this->env['slim.input'], $output);
             }
             $this->env['slim.request.form_hash'] = Slim_Http_Util::stripSlashesIfMagicQuotes($output);
         } else {
             $this->env['slim.request.form_hash'] = Slim_Http_Util::stripSlashesIfMagicQuotes($_POST);
         }
     }
     if ($key) {
         if (isset($this->env['slim.request.form_hash'][$key])) {
             return $this->env['slim.request.form_hash'][$key];
         } else {
             return null;
         }
     } else {
         return $this->env['slim.request.form_hash'];
     }
 }