Parses content from request into an array of values.

@param  string $content
@param  string $type the type the content is expected to be.
@return array
@throws Exception
965450
protected function parseRequestContent($content, $type)
    {
        $content = json_decode($content, true);
        if (empty($content['data'])) {
            throw new Exception(
                'Payload either contains misformed JSON or missing "data" parameter.',
                static::ERROR_SCOPE | static::ERROR_INVALID_ATTRS,
                BaseResponse::HTTP_BAD_REQUEST
            );
        }

        $data = $content['data'];
        if (!isset($data['type'])) {
            throw new Exception(
                '"type" parameter not set in request.',
                static::ERROR_SCOPE | static::ERROR_INVALID_ATTRS,
                BaseResponse::HTTP_BAD_REQUEST
            );
        }
        if ($data['type'] !== $type) {
            throw new Exception(
                '"type" parameter is not valid. Expecting ' . $type,
                static::ERROR_SCOPE | static::ERROR_INVALID_ATTRS,
                BaseResponse::HTTP_CONFLICT
            );
        }
        unset($data['type']);

        return $data;
    }
936417
private static function parseArgs($content)
    {
        // Replace initial stars
        $content = preg_replace('/^\s*\*/m', '', $content);

        $data  = array();
        $len   = strlen($content);
        $i     = 0;
        $var   = '';
        $val   = '';
        $level = 1;

        $prevDelimiter = '';
        $nextDelimiter = '';
        $nextToken     = '';
        $composing     = false;
        $type          = 'plain';
        $delimiter     = null;
        $quoted        = false;
        $tokens        = array('"', '"', '{', '}', ',', '=');

        while ($i <= $len) {
            $prev_c = substr($content, $i -1, 1);
            $c = substr($content, $i++, 1);

            if ($c === '"' && $prev_c !== "\\") {
                $delimiter = $c;
                //open delimiter
                if (!$composing && empty($prevDelimiter) && empty($nextDelimiter)) {
                    $prevDelimiter = $nextDelimiter = $delimiter;
                    $val           = '';
                    $composing     = true;
                    $quoted        = true;
                } else {
                    // close delimiter
                    if ($c !== $nextDelimiter) {
                        throw new Exception(sprintf(
                            "Parse Error: enclosing error -> expected: [%s], given: [%s]",
                            $nextDelimiter, $c
                        ));
                    }

                    // validating syntax
                    if ($i < $len) {
                        if (',' !== substr($content, $i, 1) && '\\' !== $prev_c) {
                            throw new Exception(sprintf(
                                "Parse Error: missing comma separator near: ...%s<--",
                                substr($content, ($i-10), $i)
                            ));
                        }
                    }

                    $prevDelimiter = $nextDelimiter = '';
                    $composing     = false;
                    $delimiter     = null;
                }
            } elseif (!$composing && in_array($c, $tokens)) {
                switch ($c) {
                    case '=':
                        $prevDelimiter = $nextDelimiter = '';
                        $level     = 2;
                        $composing = false;
                        $type      = 'assoc';
                        $quoted = false;
                        break;
                    case ',':
                        $level = 3;

                        // If composing flag is true yet,
                        // it means that the string was not enclosed, so it is parsing error.
                        if ($composing === true && !empty($prevDelimiter) && !empty($nextDelimiter)) {
                            throw new Exception(sprintf(
                                "Parse Error: enclosing error -> expected: [%s], given: [%s]",
                                $nextDelimiter, $c
                            ));
                        }

                        $prevDelimiter = $nextDelimiter = '';
                        break;
                    case '{':
                        $subc = '';
                        $subComposing = true;

                        while ($i <= $len) {
                            $c = substr($content, $i++, 1);

                            if (isset($delimiter) && $c === $delimiter) {
                                throw new Exception(sprintf(
                                    "Parse Error: Composite variable is not enclosed correctly."
                                ));
                            }

                            if ($c === '}') {
                                $subComposing = false;
                                break;
                            }
                            $subc .= $c;
                        }

                        // if the string is composing yet means that the structure of var. never was enclosed with '}'
                        if ($subComposing) {
                            throw new Exception(sprintf(
                                "Parse Error: Composite variable is not enclosed correctly. near: ...%s'",
                                $subc
                            ));
                        }

                        $val = self::parseArgs($subc);
                        break;
                }
            } else {
                if ($level == 1) {
                    $var .= $c;
                } elseif ($level == 2) {
                    $val .= $c;
                }
            }

            if ($level === 3 || $i === $len) {
                if ($type == 'plain' && $i === $len) {
                    $data = self::castValue($var);
                } else {
                    $data[trim($var)] = self::castValue($val, !$quoted);
                }

                $level = 1;
                $var   = $val = '';
                $composing = false;
                $quoted = false;
            }
        }

        return $data;
    }
1311735
public function parse(array $tag, $content) {

        // If more than 1 http:// is found in the string, possible XSS attack
        if ((mb_substr_count($content, 'http://') + mb_substr_count($content, 'https://')) > 1) {
            return null;
        }

        $tag['attributes']['src'] = $content;

        if (!empty($tag['attributes']['default'])) {
            list($width, $height) = explode('x', $tag['attributes']['default']);

            $tag['attributes']['width'] = $width;
            $tag['attributes']['height'] = $height;
        }

        if (empty($tag['attributes']['alt'])) {
            $tag['attributes']['alt'] = '';
        }

        return parent::parse($tag, $content);
    }
623657
public function getContent($content, $type, $father = null)
    {
        $array = ['type' => $type->getName(), 'size' => 'content-12'];

        if ($father) {
            $array['father'] = $father->getId();
            $subContent = $this->subContent->findOneBy(['child' => $content, 'father' => $father]);
            $array['size'] = $subContent->getSize();
        } else {
            $contentType = $this->contentType->findOneBy(['content' => $content, 'type' => $type]);
            $array['size'] = $contentType->getSize();
            $array['collapse'] = $contentType->isCollapse();
        }

        $array['content'] = $content;

        return $array;
    }
205315
public function setMessage($type, $content)
    {
        $message = new \stdClass;
        $message->mt = $type;
        $message->content = $content;
        $messages = $this->session()->get('messages', array());
        $messages[] = $message;
        $this->session()->set('messages', $messages);
    }
774657
public function parse($content)
    {
        if (strpos($content, '@ORM') === false) {
            return null;
        }

        if (preg_match(self::PATTERN, $content, $matches)) {
            return (new \SplFixedArray(2))->fromArray([$matches[1], $matches[2]]);
        }

        return null;
    }
693290
public function addContent($content)
    {
        if ($content instanceof Page) {
            $this->addPage($content);
        }
        else {
            if ($content) {
                $this->addChild($content);
            }
            else {
                throw new Exception("Unknown content type.");
            }
        }
    }
1227489
public function getResponse($content = '')
    {
        //transform content by content type
        if ($this->isJsonRequest()) {
            if ($content instanceof Response\JsonResponse) {
                $content = json_decode($content->getBody());
            } elseif (!is_array($content)) {
                $content = [$content];
            }
        } else {
            if (is_array($content)) {
                $content = implode('', $content);
            } elseif ($content instanceof ResponseInterface) {
                $content = $content->getBody()->__toString();
            }
        }

        if (!$this->getContainer()->has(ResponseInterface::class)) {
            if ($this->isCli()) {
                $class = Response\TextResponse::class;
            } elseif ($this->isJsonRequest()) {
                $class = Response\JsonResponse::class;
            } else {
                $class = Response\HtmlResponse::class;
            }
            $this->getContainer()->add(ResponseInterface::class, $class);
        }

        /** @var ResponseInterface $response */
        $response = $this->validateContract($this->getContainer()->get(ResponseInterface::class, [$content]),
            ResponseInterface::class);

        //inject request content type
        $request = $this->getRequest();

        $contentTypeKey = 'content-type';
        foreach ($request->getHeader($contentTypeKey) as $contentType) {
            $response = $response->withHeader($contentTypeKey, $contentType);
        }

        return $response;
    }
677224
public function setContent($content)
    {
        if (null !== $content && !is_string($content) && !is_numeric($content) && !is_callable(array($content, '__toString'))) {
            throw new \UnexpectedValueException(sprintf('The Response content must be a string or object implementing __toString(), "%s" given.', gettype($content)));
        }

        $this->content = (string) $content;

        return $this;
    }
1260616
public function parse($content)
    {
        $set = null;
        if (strpos($content, '@ORM') === false) {
            return $set;
        }

        if (preg_match(self::PATTERN, $content, $matches)) {
            $set[] = [$matches[1], $matches[2]];
        }



        return $set;
    }
300555
public function parse($content)
    {
        if (!$content || strpos($content, '@view') === false) {
            return [];
        }
        $ret = [];

        if (preg_match(self::VIEW_RENDER, $content, $match)) {
            $ret[0] = array_pop($match);
        } else {
            $ret[0] = null;
        }

        if (preg_match(self::VIEW_TEMPLATE_FILE, $content, $match)) {
            $ret[1] = array_pop($match);
        } else {
            $ret[1] = null;
        }

        if (preg_match_all(self::VIEW_PARAMETERS, $content, $match, PREG_SET_ORDER)) {
            $set = [];
            // "all" is excluded
            foreach ($match as $position => $group) {
                $set[$group[1]] = $group[2];
            }

            if ($set){
                $ret[] = $set;
            }

        }

        return $ret;
    }
1259385
private function parseResponse($content) {
        
        list ( $headerStr, $body ) = explode("\r\n\r\n", $content, 2);
        
        $header = array ();
        
        $headerPart = explode("\r\n", $headerStr);
        
        list ( $httpProtocol, $statusCode, $statStr ) = explode(' ', array_shift($headerPart), 3);
        
        foreach ( $headerPart as $item ) {
            list ( $key, $value ) = explode(':', $item);
            $header [$key] = $value;
        }
        
        $result = array (
            'protocol' => $httpProtocol,
            'status' => intval($statusCode),
            'statusMsg' => $statStr,
            'header' => $header,
            'content' => $body, 
        );
        
        return $result;
    }
519006
private function getContentData($content)
    {
        $res = [];
        $res['startStringPos'] = strpos($content, $this->startString) + strlen($this->startString);
        $res['endStringPos'] = strpos($content, $this->endString);
        $res['bundleList'] = substr($content, $res['startStringPos'], ($res['endStringPos'] - $res['startStringPos']));
        return $res;
    }
926972
public function parse($content)
    {
        if (!$content) {
            return [];
        }

        if (strpos($content, '@validator') === false) {
            return[];
        }


        $validatorSet = [];
        if (preg_match_all(self::ANNOTATION_PATTERN, $content, $matches)) {

            $typeBoolean = new InterpreterTypeBoolean();
            // simplify the matches and return only the parameter list
            $set = [];
            foreach ($matches[1] as $validator) {
                // if there is no validator name why even bother
                if (preg_match(self::VALIDATOR_NAME_PATTERN, $validator, $match)) {
                    $set[self::INDEX_INTERFACE] = $match[1];
                } else {
                    continue;
                }

                if (preg_match(self::VALIDATOR_OPERATOR_PATTERN, $validator, $match)) {
                    $set[self::INDEX_OPERATOR] = $match[1];
                } else {
                    $set[self::INDEX_OPERATOR] = self::DEFAULT_OPERATOR;
                }

                if (preg_match(self::VALIDATOR_MANDATORY_PATTERN, $validator, $match)) {
                    $set[self::INDEX_MANDATORY] = $typeBoolean->execute($match[1]);
                } else {
                    $set[self::INDEX_MANDATORY] = self::DEFAULT_MANDATORY;
                }

                if (preg_match(self::VALIDATOR_EXPECTATION_PATTERN, $validator, $match)) {
                    $set[self::INDEX_EXPECTED] = $typeBoolean->execute($match[1]);
                } else {
                    $set[self::INDEX_EXPECTED] = self::DEFAULT_EXPECTATION;
                }

                // add the set
                if ($set) {
                    array_push($validatorSet, $set);
                }
            }
        }

        return $validatorSet;
    }
1125354
public function content($content = null)
    {
        if ($content !== null) {
            if (!is_scalar($content) && !is_callable([$content, '__toString'])) {
                throw new ResponseException('Response content must be a scalar or object with __toString() method "' . $this->getType($content) . '" given.');
            }

            $this->content = (string) $content;
        }

        return $this->content;
    }
940596
public static function create($type, $content)
	{
		if (empty($type)) {
			throw new AlertTypeException('Unable to create message with invalid type.');
		}

		if (empty($content)) {
			throw new AlertContentException('Unable to create message with invalid content.');
		}

		return new self($type, $content);
	}
516989
public function parse($content) {
    $this->resetFd();
    foreach ($this->formdataParts($content) as $part) {
      if (!$this->isLastPart($part)) {
        $this->processFormdataPart($part);
      }
    }
    $this->compileData();
    return $this->fd;
  }