Validates a request line

@param string $line
@throws BadRequestException
199814
protected function validateRequestLine($line)
    {
        $matches = [0 => null, 1 => null];

        if (!preg_match(self::REQUEST_LINE_REGEX, $line, $matches) || !$matches[1]) {
            throw new BadRequestException('Invalid request line', 400);
        }

        return $matches[1];
    }
1313503
private function parseCodeLine(string $line): Line
    {
        if (strlen($line) == 0) {
            return new Line(Line::EXISTED, '');
        }

        $firstChar = $line[0];
        $cleanLine = rtrim(substr($line, 1));

        return new Line(Line::$opsMap[$firstChar], $cleanLine);
    }
1047385
public function parseLine($line) {

        $data = explode(";", $line);
        $i    = -1;

        $model = new Card();
        $model->setTicketNumber($this->decodeString($data[++$i]));
        $model->setUserNumber(IntegerHelper::parseString($data[++$i]));
        $model->setArticleNumber(IntegerHelper::parseString($data[++$i]));
        $model->setValidFrom($this->decodeDate($data[++$i]));
        $model->setExpires($this->decodeDate($data[++$i]));
        $model->setBlocked(BooleanHelper::parseString($data[++$i]));
        $model->setBlockedDate($this->decodeDate($data[++$i]));
        $model->setProductionState(IntegerHelper::parseString($data[++$i]));
        $model->setReasonProduction(IntegerHelper::parseString($data[++$i]));
        $model->setProductionCounter(IntegerHelper::parseString($data[++$i]));
        $model->setNeutral(BooleanHelper::parseString($data[++$i]));
        $model->setRetainTicketEntry(BooleanHelper::parseString($data[++$i]));
        $model->setEntryBarrierClosed(BooleanHelper::parseString($data[++$i]));
        $model->setExitBarrierClosed(BooleanHelper::parseString($data[++$i]));
        $model->setRetainTicketExit(BooleanHelper::parseString($data[++$i]));
        $model->setDisplayText(BooleanHelper::parseString($data[++$i]));
        $model->setDisplayText1($this->decodeString($data[++$i]));
        $model->setDisplayText2($this->decodeString($data[++$i]));
        $model->setPersonnalNo(IntegerHelper::parseString($data[++$i]));
        $model->setResidualValue(IntegerHelper::parseString($data[++$i]));
        $model->setSerialNumberKeyCardSwatch($this->decodeString($data[++$i]));
        $model->setCurrencyResidualValue($this->decodeString($data[++$i]));
        $model->setTicketType(IntegerHelper::parseString($data[++$i]));
        $model->setTicketSubType($this->decodeString($data[++$i]));
        $model->setSerialNo($this->decodeString($data[++$i]));
        $model->setSuspendPeriodFrom($this->decodeDate($data[++$i]));
        $model->setSuspendPeriodUntil($this->decodeDate($data[++$i]));
        $model->setUseValidCarParks(BooleanHelper::parseString($data[++$i]));
        $model->setProductionFacilityNumber(IntegerHelper::parseString($data[++$i]));

        return $model;
    }
112919
protected function verifyUploadedFile($file)
    {
        if (is_array($file['error'])) {
            throw new BadRequestException("Only a single application package file is allowed for import.");
        }

        if (UPLOAD_ERR_OK !== ($error = $file['error'])) {
            throw new InternalServerErrorException(
                "Failed to receive upload of '" . $file['name'] . "': " . $error
            );
        }

        $extension = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION));
        if (static::FILE_EXTENSION != $extension) {
            throw new BadRequestException("Only package files ending with '" .
                static::FILE_EXTENSION .
                "' are allowed for import.");
        }

        $this->setZipFile($file['tmp_name']);
    }
202826
public function parseBody( $line )
    {
        $line = rtrim( $line, "\r\n" );
        if ( $this->text === null )
        {
            $this->text = $line;
        }
        else
        {
            $this->text .= "\n" . $line;
        }
    }
872042
public function logValidationError($validationType, $messageException = null, $method = null, $line = null)
    {
        if (self::getConfig('log', 'validation')) {
            $this->logMessage("VALIDATE][KO][{$validationType}", "{$messageException} --- " . $this->__toString() . "\n", $method, $line);
        }
        //file_put_contents('php://stderr', "[" . date('Y-m-d H:i:s') . "][VALIDATION][KO][{{$method}#{$line}][{$validationType}] : {$messageException} --- " . $this->__toString() . "\n");
    }
340047
protected function _throwException($exception = null)
    {
        if ($exception !== null) {
            if (!Configure::read('debug') && $exception instanceof SecurityException) {
                $exception->setReason($exception->getMessage());
                $exception->setMessage(self::DEFAULT_EXCEPTION_MESSAGE);
            }
            throw $exception;
        }
        throw new BadRequestException(self::DEFAULT_EXCEPTION_MESSAGE);
    }
1251828
public function validate(string $value)
    {
        if (!$value || mb_strlen($value, 'UTF-8') >= $this->minimumLength) {
            return;
        }

        $this->error['minlength.%'] = [$this->minimumLength];
    }
1226177
private function parseResponseHeaderLine($line) {
        list($key, $value) = explode(':', $line, 2);
        $key = trim(strtolower(str_replace('-', '_', $key)));
        $value = trim($value);
        if (empty($this->headers[$key])) {
            $this->headers[$key] = $value;
        } elseif (is_array($this->headers[$key])) {
            $this->headers[$key][] = $value;
        } else {
            $this->headers[$key] = array($this->headers[$key], $value);
        }
    }
894683
public static function validate($value)
    {
        assert(is_string($value));

        if ($value !== self::LAST && $value !== self::ERROR) {
            throw new ClientException('Invalid update policy');
        }
    }
28035
public function writeFreeFormLine($line)
	{
        if ($this->_logStatus == self::STATUS_LOG_OPEN
            && $this->_severityThreshold != self::OFF) {
            if (fwrite($this->_fileHandle, $line) === false) {
                $this->_messageQueue[] = $this->_messages['writefail'];
            }
        }
    }
419639
public function parse($line)
    {
        $this->error = false;
        $this->currentTextLineContainer = $this->textLineContainers[$this->config->defaultTextLineContainer];
        $firsttag = clone ($this->currentTextLineContainer->tag);

        $this->str = preg_split($this->currentTextLineContainer->pattern, $line, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
        $this->end = count($this->str);

        if ($this->end > 1) {
            $pos = -1;
            $this->_parse($firsttag, $pos);

            return $firsttag->getContent();
        } else {
            $firsttag->addContentString($line);

            return $firsttag->getContent();
        }
    }
1201876
protected function processLine($line)
    {
        if ($line === '') {
            $this->handleBlankLine();
            return;
        }

        $this->justNewEntry = false;

        $data = $this->parseLine($line);

        if ($data['key'][0] === '#') {
            $this->handleComment($data);
            return;
        }

        $this->handleOtherCases($data, $line);
    }
339050
private function validateEndpoint($endpoint)
    {
        $isValid = filter_var($endpoint, FILTER_VALIDATE_URL);

        if ($isValid) {
            $scheme = strtolower(parse_url($endpoint, PHP_URL_SCHEME));
            if (in_array($scheme, ['http', 'https'], true)) {
                return;
            }
        }

        throw new Exception(self::ERR_INVALID_ENDPOINT);
    }
1100203
private function getParamChunksFromLine($line)
    {
        $paramChunks = explode(' ', $line);
        $paramChunks = array_filter($paramChunks, function($val) {
            return $val !== '';
        });
        unset($paramChunks[0]);
        
        return $paramChunks;
    }
1227575
public function printLine($line)
    {
        if (!$this->handle) {
            throw new \RuntimeException('can not write to file: invalid file handle');
        }
        fwrite($this->handle, $line . "\n");
        ++$this->lineNumber;
    }
608067
public function checkConnectionError($line) {
		$line = rtrim($line, ')');
		if (substr($line, -23) === ErrorCodes::LogonFailure) {
			throw new AuthenticationException('Invalid login');
		}
		if (substr($line, -26) === ErrorCodes::BadHostName) {
			throw new InvalidHostException('Invalid hostname');
		}
		if (substr($line, -22) === ErrorCodes::Unsuccessful) {
			throw new InvalidHostException('Connection unsuccessful');
		}
		if (substr($line, -28) === ErrorCodes::ConnectionRefused) {
			throw new InvalidHostException('Connection refused');
		}
		if (substr($line, -26) === ErrorCodes::NoLogonServers) {
			throw new NoLoginServerException('No login server');
		}
		if (substr($line, -23) === ErrorCodes::AccessDenied) {
			throw new AccessDeniedException('Access denied');
		}
	}