Beispiel #1
0
 public static function instance()
 {
     if (!self::$_instance) {
         self::$_instance = new ArrayParser();
     }
     return self::$_instance;
 }
Beispiel #2
0
 public function display()
 {
     echo "<pre>";
     print_r("======================Group Array Demo===================");
     echo "</pre>";
     $parser = ArrayParser::instance();
     $dataArray = $this->_getData();
     $firstData = $parser->groupArrayByIdFirstStyle($dataArray);
     $secondData = $parser->groupArrayByIdSecondStyle($dataArray);
     echo "<pre>";
     print_r($dataArray);
     echo "</pre>";
     echo "<pre>";
     print_r($firstData);
     echo "</pre>";
     echo "<pre>";
     print_r($secondData);
     echo "</pre>";
 }
Beispiel #3
0
 public function display()
 {
     echo "<pre>";
     print_r("======================Array and Object Demo===================");
     echo "</pre>";
     $parser = ArrayParser::instance();
     $associateArray = $this->_getData();
     $firstData = $parser->convertAssociateArrayToObjectFirst($associateArray);
     $secondData = $parser->convertAssociateArrayToObjectSecond($associateArray);
     echo "<pre>";
     print_r($associateArray);
     echo "</pre>";
     echo "<pre>";
     print_r($firstData);
     echo "</pre>";
     echo "<pre>";
     print_r($secondData);
     echo "</pre>";
 }
 /**
  * Read a language string from the file.
  *
  * @return void
  */
 private function readLangString()
 {
     while (!$this->tokenIs(';')) {
         $this->getNextToken();
         if ($this->tokenIs('[')) {
             $this->subParserSquareBracket();
             continue;
         }
         if ($this->tokenIs('=')) {
             // right hand of the assignment.
             $this->getNextToken();
             if ($this->tokenIs(T_ARRAY) || $this->tokenIs('[')) {
                 $arrayParser = new ArrayParser($this, 1);
                 $arrayParser->parse();
                 $this->debug('After array. ' . var_export($this->getToken(), true));
             } else {
                 $subparser = new StringValue($this);
                 $subparser->parse();
                 $this->file->setValue(implode('.', $this->keystack), $subparser->getValue());
             }
             continue;
         }
         if (!$this->tokenIs(']')) {
             $this->bailUnexpectedToken();
         }
     }
     if ($this->tokenIs(';')) {
         // Reset stack.
         $this->resetStack();
     }
 }
 /**
  * Parse the value portion of a key => value array element.
  *
  * @return void
  */
 private function parseValue()
 {
     $this->getNextToken();
     if ($this->tokenIs(T_ARRAY) || $this->tokenIs('[')) {
         // Sub array with key.
         $this->debug('Sub array with key.');
         $subparser = new ArrayParser($this->parser, $this->level + 1);
         $subparser->parse();
     } else {
         // String item with key.
         $this->debug('String item with key.');
         $subparser = new StringValue($this->parser, $this->level + 1);
         $subparser->parse();
         $this->parser->setValue($this->parser->getStack(), $subparser->getValue());
     }
 }