Parse the input data

@access public
@return bool true on success, false on failure
331265
public function parse()
	{
		while ($this->state && $this->state !== 'emit' && $this->has_data())
		{
			$state = $this->state;
			$this->$state();
		}
		$this->data = '';
		if ($this->state === 'emit')
		{
			return true;
		}
		else
		{
			$this->version = '';
			$this->encoding = '';
			$this->standalone = '';
			return false;
		}
	}
660833
public function parse()
    {
        if ($this->buffer === '') {
            return false;
        }
        $this->frame = null;
        $this->offset = 0;
        $this->bufferSize = strlen($this->buffer);
        while ($this->offset < $this->bufferSize) {
            if ($this->mode === self::MODE_HEADER) {
                $this->skipEmptyLines();
                if ($this->detectFrameHead()) {
                    $this->mode = self::MODE_BODY;
                } else {
                    break;
                }
            }
            if ($this->detectFrameEnd()) {
                $this->mode = self::MODE_HEADER;
            }
            break;
        }

        if ($this->offset > 0) {
            // remove parsed buffer
            $this->buffer = substr($this->buffer, $this->offset);
        }
        return $this->frame !== null;
    }
291759
protected function _readInput()
    {
        if (empty($this->_input)) {
            $fh = fopen('php://input', 'rb');
            $content = stream_get_contents($fh);
            fclose($fh);
            $this->_input = $content;
        }

        return $this->_input;
    }
299943
public function parse()
    {
        // check if a help flag is set
        try {
            $key = $this->checkInputs('-h', '--help');
            if ($key !== false) {
                throw new \Exception('Help flag is set');
            }
        } catch (\Exception $e) {
            $this->outputHelp();
            return false;
        }

        // loop through options and see if they are in the inputs
        foreach ($this->options as $option => $info) {
            // if option is in inputs
            $key = $this->checkInputs($info['short'], $info['long']);
            if ($key === false) {
                $this->pinputs[$info['short']] = false;
                $this->pinputs[$info['long']] = false;
            } else {
                // check if next input should be in input
                if (array_key_exists('input', $info) && $info['input'] == true) {
                    $this->pinputs[$info['short']] = $this->inputs[$key + 1];
                    $this->pinputs[$info['long']] = $this->inputs[$key + 1];
                    unset($this->inputs[$key]); // remove flag from inputs array
                    unset($this->inputs[$key + 1]);
                } else {
                    $this->pinputs[$info['short']] = true;
                    $this->pinputs[$info['long']] = true;
                    unset($this->inputs[$key]);
                }
            }
        }

        // Loop through each of the remaining inputs and assign them to their
        // params
        $count = 0; // count because cannot rely on key value of inputs
        foreach ($this->inputs as $key => $input) {
            // If parameter for input exists
            if (array_key_exists($count, $this->params)) {
                $this->pinputs[$this->params[$count]['name']] = $input;
                unset($this->inputs[$key]); // remove input from inputs
            }
            $count++;
        }

        // loop through remaining flags and insert them at their indexes
        if (!empty($this->inputs)) {
            $this->inputs = array_values($this->inputs);
        }
        $this->pinputs = array_merge($this->inputs, $this->pinputs);

        // check required inputs
        try {
            $this->checkRequired();
        } catch (\Exception $e) {
            echo $e->getMessage() . PHP_EOL . PHP_EOL;
            $this->outputHelp(true);
            return false;
        }

        return true;
    }
527469
function parseForms()
	{
		preg_match_all('/<form.*>.+<\/form>/isU', $this->html_data, $forms);
		foreach ($forms[0] as $form) {
			$this->button_counter = 0;

			//form details
			preg_match('/<form.*?name=["\']?([\w\s-]*)["\']?[\s>]/is', $form, $form_name);
			if ($form_name) {
				$this->_return[$this->_counter]['form_data']['name'] = preg_replace('/["\'<>]/', '', $form_name[1]);
			}
			preg_match('/<form.*?action=("([^"]*)"|\'([^\']*)\'|[^>\s]*)([^>]*)?>/is', $form, $action);
			if ($action) {
				$this->_return[$this->_counter]['form_data']['action'] = preg_replace('/["\'<>]/', '', $action[1]);
			}
			preg_match('/<form.*?method=["\']?([\w\s]*)["\']?[\s>]/is', $form, $method);
			if ($method) {
				$this->_return[$this->_counter]['form_data']['method'] = preg_replace('/["\'<>]/', '', $method[1]);
			}
			preg_match('/<form.*?enctype=("([^"]*)"|\'([^\']*)\'|[^>\s]*)([^>]*)?>/is', $form, $enctype);
			if ($enctype) {
				$this->_return[$this->_counter]['form_data']['enctype'] = preg_replace('/["\'<>]/', '', $enctype[1]);
			}
			preg_match('/<form.*?id=["\']?([\w\s-]*)["\']?[\s>]/is', $form, $id);
			if ($id) {
				$this->_return[$this->_counter]['form_data']['id'] = preg_replace('/["\'<>]/', '', $id[1]);
			}

			// form elements: input type = hidden
			if (preg_match_all('/<input[^<>]+type=["\']hidden["\'][^<>]*>/isU', $form, $hiddens)) {
				foreach ($hiddens[0] as $hidden) {
					$this->_return[$this->_counter]['form_elements'][$this->_getName($hidden)] = array(
						'type'  =>  'hidden',
						'value'  =>  $this->_getValue($hidden)
					);
				}
			}

			// form elements: input type = text
			if (preg_match_all('/<input[^<>]+type=["\']text["\'][^<>]*>/isU', $form, $texts)) {
				foreach ($texts[0] as $text) {
					$this->_return[$this->_counter]['form_elements'][$this->_getName($text)] = array(
						'type' => 'text',
						'value' => $this->_getValue($text),
						'id' => $this->_getId($text),
						'class' => $this->_getClass($text)
					);
				}
			}

			/**
			 * HJW 18-7-2014 Magento 1.9.01. uses email as type for user credential
			 * form elements: input type = email
			 */
			if (preg_match_all('/<input[^<>]+type=["\']email["\'][^<>]*>/isU', $form, $texts)) {
				foreach ($texts[0] as $text) {
					$this->_return[$this->_counter]['form_elements'][$this->_getName($text)] = array(
						'type'  => 'email',
						'value'  =>  $this->_getValue($text),
						'id'  =>  $this->_getId($text),
						'class'  =>  $this->_getClass($text)
					);
				}
			}

            // form elements: input type = email
            if (preg_match_all('/<input[^<>]+type=["\']email["\'][^<>]*>/isU', $form, $texts)) {
                foreach ($texts[0] as $text) {
                    $this->_return[$this->_counter]['form_elements'][$this->_getName($text)] = array(
                        'type'  => 'email',
                        'value'  =>  $this->_getValue($text),
                        'id'  =>  $this->_getId($text),
                        'class'  =>  $this->_getClass($text)
                    );
                }
            }

			// form elements: input type = password
			if (preg_match_all('/<input[^<>]+type=["\']password["\'][^<>]*>/isU', $form, $passwords)) {
				foreach ($passwords[0] as $password) {
					$this->_return[$this->_counter]['form_elements'][$this->_getName($password)] = array(
						'type'  =>  'password',
						'value'  =>  $this->_getValue($password)
					);
				}
			}

			// form elements: textarea
			if (preg_match_all('/<textarea.*>.*<\/textarea>/isU', $form, $textareas)) {
				foreach ($textareas[0] as $textarea) {
					preg_match('/<textarea.*>(.*)<\/textarea>/isU', $textarea, $textarea_value);
					$this->_return[$this->_counter]['form_elements'][$this->_getName($textarea)] = array(
						'type'  =>  'textarea',
						'value'  =>  $textarea_value[1]
					);
				}
			}

			// form elements: input type = checkbox
			if (preg_match_all('/<input[^<>]+type=["\']checkbox["\'][^<>]*>/isU', $form, $checkboxes)) {
				foreach ($checkboxes[0] as $checkbox) {
					if (preg_match('/checked/is', $checkbox)) {
						$this->_return[$this->_counter]['form_elements'][$this->_getName($checkbox)] = array(
							'type'  =>  'checkbox',
							'value'  =>  'on'
						);
					} else {
						$this->_return[$this->_counter]['form_elements'][$this->_getName($checkbox)] = array(
							'type'  =>  'checkbox',
							'value'  =>  ''
						);
					}
				}
			}

			// form elements: input type = radio
			if (preg_match_all('/<input[^<>]+type=["\']radio["\'][^<>]*>/isU', $form, $radios)) {
				foreach ($radios[0] as $radio) {
					if (preg_match('/checked/i', $radio)) {
						$this->_return[$this->_counter]['form_elements'][$this->_getName($radio)] = array(
							'type'  =>  'radio',
							'value'  =>  $this->_getValue($radio)
						);
					}
				}
			}

			// form elements: input type = submit
			if (preg_match_all('/<input[^<>]+type=["\']submit["\'][^<>]*>/isU', $form, $submits)) {
				foreach ($submits[0] as $submit) {
					$this->_return[$this->_counter]['buttons'][$this->button_counter] = array(
						'type'  => 'submit',
						'name'  => $this->_getName($submit),
						'value'  => $this->_getValue($submit)
					);
					$this->button_counter++;
				}
			}

			// form elements: input type = button
			if (preg_match_all('/<input[^<>]+type=["\']button["\'][^<>]*>/isU', $form, $buttons)) {
				foreach ($buttons[0] as $button) {
					$this->_return[$this->_counter]['buttons'][$this->button_counter] = array(
						'type'  => 'button',
						'name'  => $this->_getName($button),
						'value'  => $this->_getValue($button)
					);
					$this->button_counter++;
				}
			}

			// form elements: input type = reset
			if (preg_match_all('/<input[^<>]+type=["\']reset["\'][^<>]*>/isU', $form, $resets)) {
				foreach ($resets[0] as $reset) {
					$this->_return[$this->_counter]['buttons'][$this->button_counter] = array(
						'type'  => 'reset',
						'name'  => $this->_getName($reset),
						'value'  => $this->_getValue($reset)
					);
					$this->button_counter++;
				}
			}

			// form elements: input type = image
			if (preg_match_all('/<input[^<>]+type=["\']image["\'][^<>]*>/isU', $form, $images)) {
				foreach ($images[0] as $image) {
					$this->_return[$this->_counter]['buttons'][$this->button_counter] = array(
						'type'  => 'image',
						'name'  => $this->_getName($image),
						'value'  => $this->_getValue($image)
					);
					$this->button_counter++;
				}
			}

			// input type=select entries
			// Here I have to go on step around to grep at first all select names and then
			// the content. Seems not to work in an other way
			if (preg_match_all('/<select.*>.+<\/select>/isU', $form, $selects)) {
				foreach ($selects[0] as $select) {
					if (preg_match_all('/<option.*>.+<\/option>/isU', $select, $all_options)) {
						$option_value = '';
						foreach ($all_options[0] as $option) {
							if (preg_match('/selected/i', $option)) {
								if (preg_match('/value=["\'](.*)["\']\s/isU', $option, $option_value)) {
									$option_value = $option_value[1];
									$found_selected = 1;
								} else {
									preg_match('/<option.*>(.*)<\/option>/isU', $option, $option_value);
									$option_value = $option_value[1];
									$found_selected = 1;
								}
							}
						}
						if (!isset($found_selected)) {
							if (preg_match('/value=["\'](.*)["\']/isU', $all_options[0][0], $option_value)) {
								$option_value = $option_value[1];
							} else {
								preg_match('/<option>(.*)<\/option>/isU', $all_options[0][0], $option_value);
								$option_value = $option_value[1];
							}
						} else {
							unset($found_selected);
						}
						$this->_return[$this->_counter]['form_elements'][$this->_getName($select)] = array(
							'type'  => 'select',
							'value'  => trim($option_value)
						);
					}
				}
			}

			# form elements: input type = --not defined--
			if ( preg_match_all('/<input[^<>]+name=["\'](.*)["\'][^<>]*>/isU', $form, $inputs)) {
				foreach ($inputs[0] as $input) {
					if ( !preg_match('/type=("([^"]*)"|\'([^\']*)\'|[^>\s]*)([^>]*)?>/is', $input) ) {
						if ( !isset($this->_return[$this->_counter]['form_elements'][$this->_getName($input)]) ) {
							$this->_return[$this->_counter]['form_elements'][$this->_getName($input)] =
								array(
									'type'  => 'text',
									'value'  =>  $this->_getValue($input),
									'id'  =>  $this->_getId($input),
									'class'  =>  $this->_getClass($input)
								);

						}
					}
				}
			}

			// Update the form counter if we have more then 1 form in the HTML table
			$this->_counter++;
		}

		return $this->_return;
	}
1244349
public function parse()
	{
		$i=0;
		$lines	= $this->read();
		foreach( $lines as $line )
			$this->data[]	= $this->parseLine( $line );
	}
1038831
protected function _parseArgs()
    {
        $inString = false;
        $cpt = 0;
        $last = $char = $value = $name = '';
        $args = [];
        $body = '';
        while ($token = $this->_stream->current(true)) {
            $body .= $token[1];
            switch ($token[0]) {
                case '(':
                    if ($cpt) {
                        $value .= $token[1];
                    }
                    $cpt++;
                break;
                case '=':
                    $name = $value;
                    $value = '';
                break;
                case ')':
                    $cpt--;
                    if ($cpt) {
                        $value .= $token[1];
                        break;
                    }
                case ',':
                    $value = trim($value);
                    if ($value !== '') {
                        $name ? $args[trim($name)] = $value : $args[] = $value;
                    }
                    $name = $value = '';
                break;
                default:
                    $value .= $token[1];
                break;
            }
            if ($token[1] === ')' && $cpt === 0) {
                break;
            }
            $this->_stream->next();
        }
        return compact('args', 'body');
    }
1049751
public function parse()
    {
        $input = new ArgvInput($this->arguments);
        $parsed = [];

        foreach ($this->search as $option) {
            if ($input->hasParameterOption($option)) {
                $name = ltrim($option, '-');
                $parsed[$name] = $input->getParameterOption($option);
            }
        }

        return $parsed;
    }
792968
protected function parse()
    {
        $data = $this->_source->getData();

        $prefilters = $this->getPreFilterInstances();
        foreach($prefilters as $prefilter) {
            $data = $prefilter->filter($data);
        }

        $realpath = $this->_source->getRealPath();
        $parser = new PHPTAL_Dom_SaxXmlParser($this->_encoding);

        $builder = new PHPTAL_Dom_PHPTALDocumentBuilder();
        $tree = $parser->parseString($builder, $data, $realpath)->getResult();

        foreach($prefilters as $prefilter) {
            if ($prefilter instanceof PHPTAL_PreFilter) {
                if ($prefilter->filterDOM($tree) !== NULL) {
                    throw new PHPTAL_ConfigurationException("Don't return value from filterDOM()");
                }
            }
        }

        $state = new PHPTAL_Php_State($this);

        $codewriter = new PHPTAL_Php_CodeWriter($state);
        $codewriter->doTemplateFile($this->getFunctionName(), $tree);

        return $codewriter->getResult();
    }
273405
function parse() {
        $name_without_parens = preg_replace('/[{}]/', '', $this->full_name);

        $parts = explode('::', $name_without_parens);
        $name_without_case_keys = trim($parts[0]);
        array_shift($parts);
        $this->case_keys = array_map('trim', $parts);

        $parts = explode(':', $name_without_case_keys);
        $this->short_name = trim($parts[0]);
        array_shift($parts);
        $this->context_keys = array_map('trim', $parts);
    }
1375018
private function parse(){
		$inputs = explode('&',$this->input);
		foreach($inputs as $input){
			$exp = explode('=',$input);
			if(count($exp)==2)
				$this->content[urldecode($exp[0])] = urldecode($exp[1]);
		}
	}
1280329
public function parse()
    {
        $nextCursor = (int) $this->body[0];
        return array_merge([
            'finished' => (0 === $nextCursor),
            'nextCursor' => $nextCursor,
        ], $this->parseBody((array) $this->body[1]));
    }
957189
private function parseValue($input)
    {
        if (is_array($input)) {

        } elseif (substr($input, 0, 1) === '"' && substr($input, -1) === '"') {
            $input = substr($input, 1, -1);
        } elseif (strpos($input, "|") !== false) {
            $input = explode("|", $input);
            foreach ($input as $key => $value) {
                $input[$key] = $this->parseValue($value);
            }
        } elseif ($input === "false") {
            $input = false;
        } elseif ($input === "true") {
            $input = true;
        } elseif (is_numeric($input)) {
            if (strpos($input, ".") !== false) {
                $input = (float)$input;
            } else {
                $input = (int)$input;
            }
        } elseif ($input === "on") {
            $input = true;
        }

        return $input;
    }
534033
public function parse()
    {
        // Fetch the basic values from possible user defined values.
        if ($this->entity->hasConfig("labels")) {
            if ($this->entity->hasConfig("labels.singular_name")) {
                $this->singular = $this->entity->getConfig("labels.singular_name");
            } elseif ($this->entity->hasConfig("labels.name")) {
                $this->plural = $this->entity->getConfig("labels.name");
            }
        }

        if (!empty($this->singular) && empty($this->plural)) {
            $this->plural = Inflector::pluralize($this->singular);
        }

        if (!empty($this->plural) && empty($this->singular)) {
            $this->singular = Inflector::singularize($this->plural);
        }

        // If nothing is sent in, guess the name from the object name.
        if (empty($this->plural) && empty($this->singular)) {
            $this->singular   = ucfirst(Inflector::singularize($this->entity->getShortName()));
            $this->plural     = ucfirst(Inflector::pluralize($this->entity->getShortName()));
        }
    }
1272995
private function parsePut()
    {
        $contentType = (isset($_SERVER['CONTENT_TYPE'])) ? $_SERVER['CONTENT_TYPE'] : 'application/x-www-form-urlencoded';

        $tmp = explode(';', $contentType);
        $boundary = '';
        $encoding = '';

        $contentType = array_shift($tmp);

        foreach ($tmp as $t) {
            if (strpos($t, 'boundary') !== false) {
                $t = explode('=', $t, 2);
                if (isset($t[1])) {
                    $boundary = '--' . $t[1];
                }
            } elseif (strpos($t, 'charset') !== false) {
                $t = explode('=', $t, 2);
                if (isset($t[1])) {
                    $encoding = $t[1];
                }
            }
            if ($boundary !== '' && $encoding !== '') {
                break;
            }
        }

        switch ($contentType) {
            case 'multipart/form-data':
                #grab multipart boundary from content type header
                if (!empty($boundary)) {
                    break;
                }
                $contentType = 'application/x-www-form-urlencoded';
            // Fallthrough intentional - no boundary supplied with multipart content-type, so treat as url encoded
            case 'application/x-www-form-urlencoded':
                parse_str(file_get_contents($this->unitTestRequestFile ?: 'php://input'), $_POST);
                return;
            default:
                return;
        }

        $_FILES = [];
        $_POST = [];
        $chunkLength = 8096;
        $raw_headers = '';

        $stream = fopen($this->unitTestRequestFile ?: 'php://input', 'rb');

        $sanity = fgets($stream, strlen($boundary) + 5);

        // Skip initial blank line
        if ($sanity == "\r\n") {
            $sanity = fgets($stream, strlen($boundary) + 5);
        }

        if (rtrim($sanity) !== $boundary) {
            #malformed file, boundary should be first item
            return;
        }

        while (($chunk = fgets($stream)) !== false) {
            if ($chunk === $boundary) {
                continue;
            }

            if (rtrim($chunk) == '') { #blank line means we have all the headers and are going to read content
                $raw_headers = explode("\r\n", $raw_headers);
                $headers = [];
                $matches = [];

                foreach ($raw_headers as $header) {
                    if (strpos($header, ':') === false) {
                        continue;
                    }
                    list($name, $value) = explode(':', $header, 2);
                    $headers[strtolower($name)] = ltrim($value, ' ');
                }

                $raw_headers = '';

                if (!isset($headers['content-disposition'])) {
                    continue;
                }

                $filename = null;
                preg_match(
                    '/^(.+); *name="([^"]+)"(; *filename="([^"]+)")?/',
                    $headers['content-disposition'],
                    $matches
                );
                list(, $type, $name) = $matches;

                #process data
                if (isset($matches[4])) { #pull in file
                    $error = UPLOAD_ERR_OK;

                    $filename = $matches[4];
                    $filename_parts = pathinfo($filename);
                    $contentType = 'unknown';

                    if (isset($headers['content-type'])) {
                        $tmp = explode(';', $headers['content-type']);
                        $contentType = $tmp[0];
                    }

                    $tmpnam = tempnam(ini_get('upload_tmp_dir'), 'php');
                    $fileHandle = fopen($tmpnam, 'wb');


                    if ($fileHandle === false) {
                        $error = UPLOAD_ERR_CANT_WRITE;
                    } else {
                        $lastLine = null;
                        while (($chunk = fgets($stream, $chunkLength)) !== false && strpos($chunk, $boundary) !== 0) {
                            if ($lastLine !== null) {
                                if (fwrite($fileHandle, $lastLine) === false) {
                                    $error = UPLOAD_ERR_CANT_WRITE;
                                    break;
                                }
                            }
                            $lastLine = $chunk;
                        }

                        if ($lastLine !== null && $error !== UPLOAD_ERR_CANT_WRITE) {
                            if (fwrite($fileHandle, rtrim($lastLine, "\r\n")) === false) {
                                $error = UPLOAD_ERR_CANT_WRITE;
                            }
                        }
                    }

                    $_FILES[$name] = [
                        'name' => $filename,
                        'type' => $contentType,
                        'tmp_name' => $tmpnam,
                        'error' => $error,
                        'size' => filesize($tmpnam)
                    ];

                    continue;
                } else { #pull in variable
                    $fullValue = '';
                    $lastLine = null;
                    while (($chunk = fgets($stream)) !== false && strpos($chunk, $boundary) !== 0) {
                        if ($lastLine !== null) {
                            $fullValue .= $lastLine;
                        }

                        $lastLine = $chunk;
                    }

                    if ($lastLine !== null) {
                        $fullValue .= rtrim($lastLine, "\r\n");
                    }

                    if (isset($headers['content-type'])) {
                        $tmp = explode(';', $headers['content-type']);
                        $encoding = '';

                        foreach ($tmp as $t) {
                            if (strpos($t, 'charset') !== false) {
                                $t = explode($t, '=', 2);
                                if (isset($t[1])) {
                                    $encoding = $t[1];
                                }
                                break;
                            }
                        }

                        if ($encoding !== '' && strtoupper($encoding) !== 'UTF-8' && strtoupper($encoding) !== 'UTF8') {
                            $tmp = mb_convert_encoding($fullValue, 'UTF-8', $encoding);
                            if ($tmp !== false) {
                                $fullValue = $tmp;
                            }
                        }

                    }

                    $fullValue = $name . '=' . $fullValue;
                    $origName = $name;
                    $tmp = [];
                    parse_str($fullValue, $tmp);
                    $_POST = $this->recursiveSetter($origName, $_POST, $tmp);
                }
                continue;
            }

            $raw_headers .= $chunk;
        }

        $GLOBALS['_PUT'] = $_POST;
        fclose($stream);
    }
376883
public function parse()
    {
        $path = $this->_contents;

        if (!isset($this->_parsed_data[$path])) {
            $context = $this->getCommandContext();
            $context->data = $path;
            $this->getCommandChain()->run(LibBaseTemplateFilter::MODE_READ, $context);
            $this->_parsed_data[$path] = $context->data;
        }

        return $this->_parsed_data[$path];
    }
1111000
public function ParseFromArray()
	{
		$this->value = $this->reader->next();
		$this->value = ($this->value != 0) ? 1 : 0;
	}