Exemplo n.º 1
0
 protected function _encodeAssociativeArray($Variable, $ObjectDepth = 1, $ArrayDepth = 1, $MaxDepth = 1)
 {
     if (($ret = $this->_checkDepth('Array', $ArrayDepth, $MaxDepth)) !== false) {
         return $ret;
     }
     $index = 0;
     $maxLength = $this->getOption('maxArrayLength');
     $lengthNoLimit = $this->getOption('lengthNoLimit');
     $isGlobals = false;
     foreach ($Variable as $key => $val) {
         // Encoding the $GLOBALS PHP array causes an infinite loop
         // if the recursion is not reset here as it contains
         // a reference to itself. This is the only way I have come up
         // with to stop infinite recursion in this case.
         if ($key == 'GLOBALS' && is_array($val) && array_key_exists('GLOBALS', $val)) {
             $isGlobals = true;
         }
         if ($isGlobals) {
             switch ($key) {
                 case 'GLOBALS':
                     $val = array(self::SKIP => true, 'encoder.trimmed' => true, 'encoder.notice' => 'Recursion (GLOBALS)');
                     break;
                 case '_ENV':
                 case 'HTTP_ENV_VARS':
                 case '_POST':
                 case 'HTTP_POST_VARS':
                 case '_GET':
                 case 'HTTP_GET_VARS':
                 case '_COOKIE':
                 case 'HTTP_COOKIE_VARS':
                 case '_SERVER':
                 case 'HTTP_SERVER_VARS':
                 case '_FILES':
                 case 'HTTP_POST_FILES':
                 case '_REQUEST':
                     $val = array(self::SKIP => true, 'encoder.trimmed' => true, 'encoder.notice' => 'Automatically Excluded (GLOBALS)');
                     break;
             }
         }
         if ($this->getOption('treatArrayMapAsDictionary')) {
             if (!Insight_Util::is_utf8($key)) {
                 $key = utf8_encode($key);
             }
             $return[$key] = $this->_encodeVariable($val, 1, $ArrayDepth + 1);
         } else {
             $return[] = array($this->_encodeVariable($key), $this->_encodeVariable($val, 1, $ArrayDepth + 1, $MaxDepth + 1));
         }
         $index++;
         if ($maxLength >= 0 && $index >= $maxLength && $lengthNoLimit !== true) {
             if ($this->getOption('treatArrayMapAsDictionary')) {
                 $return['...'] = array('encoder.trimmed' => true, 'encoder.notice' => 'Max Array Length (' . $maxLength . ') ' . (count($Variable) - $maxLength) . ' more');
             } else {
                 $return[] = array(array('encoder.trimmed' => true, 'encoder.notice' => 'Max Array Length (' . $maxLength . ') ' . (count($Variable) - $maxLength) . ' more'), array('encoder.trimmed' => true, 'encoder.notice' => 'Max Array Length (' . $maxLength . ') ' . (count($Variable) - $maxLength) . ' more'));
             }
             break;
         }
     }
     return array('value' => $return);
 }