mirror of https://github.com/Tildetel/site.git
Added signup form and revamped phonebook.
This commit is contained in:
parent
9cac1650a1
commit
14a94fdc56
|
@ -0,0 +1 @@
|
|||
.env
|
|
@ -1,8 +0,0 @@
|
|||
|
||||
|
||||
# php -- BEGIN cPanel-generated handler, do not edit
|
||||
# Set the “ea-php74” package as the default “PHP” programming language.
|
||||
<IfModule mime_module>
|
||||
AddHandler application/x-httpd-ea-php74 .php .php7 .phtml
|
||||
</IfModule>
|
||||
# php -- END cPanel-generated handler, do not edit
|
|
@ -0,0 +1,387 @@
|
|||
<?php
|
||||
|
||||
require_once __DIR__ . '/vendor/autoload.php'; // Load Composer packages
|
||||
|
||||
// Load environment variables from the .env file
|
||||
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
|
||||
$dotenv->load();
|
||||
|
||||
// Check if the user's IP matches the allowed IP
|
||||
$allowed_ip = $_ENV['ALLOWED_IP'];
|
||||
$user_ip = $_SERVER['REMOTE_ADDR'];
|
||||
|
||||
if ($user_ip !== $allowed_ip) {
|
||||
// If IP address doesn't match, show an error message and exit
|
||||
header('HTTP/1.0 403 Forbidden');
|
||||
echo "Access denied.";
|
||||
exit;
|
||||
}
|
||||
|
||||
include 'db.php';
|
||||
|
||||
// Handle deletion of an entry
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['delete'])) {
|
||||
$id = intval($_POST['delete']);
|
||||
|
||||
// Prepare and bind
|
||||
$stmt = $conn->prepare("DELETE FROM phonebook WHERE id = ?");
|
||||
$stmt->bind_param("i", $id);
|
||||
|
||||
// Execute the statement
|
||||
if ($stmt->execute()) {
|
||||
$success_message = "Entry deleted successfully!";
|
||||
} else {
|
||||
$error_message = "Error: " . $stmt->error;
|
||||
}
|
||||
|
||||
// Close the statement
|
||||
$stmt->close();
|
||||
}
|
||||
|
||||
// Handle adding a new phonebook entry
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['tilde_name']) && isset($_POST['extension']) && isset($_POST['username'])) {
|
||||
$tilde_name = htmlspecialchars($_POST['tilde_name']);
|
||||
$extension = htmlspecialchars($_POST['extension']);
|
||||
$username = htmlspecialchars($_POST['username']);
|
||||
|
||||
// Prepare and bind
|
||||
$stmt = $conn->prepare("INSERT INTO phonebook (tilde_name, extension, username) VALUES (?, ?, ?)");
|
||||
$stmt->bind_param("sss", $tilde_name, $extension, $username);
|
||||
|
||||
// Execute the statement
|
||||
if ($stmt->execute()) {
|
||||
$success_message = "New entry added successfully!";
|
||||
} else {
|
||||
$error_message = "Error: " . $stmt->error;
|
||||
}
|
||||
|
||||
// Close the statement
|
||||
$stmt->close();
|
||||
}
|
||||
|
||||
// Handle sending the confirmation email
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['send_email'])) {
|
||||
$extension = htmlspecialchars($_POST['extension']);
|
||||
$pbxPassword = htmlspecialchars($_POST['pbx_password']);
|
||||
$ucpPassword = htmlspecialchars($_POST['ucp_password']);
|
||||
$email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
|
||||
|
||||
// Prepare the email content
|
||||
$subject = "Your tilde.tel Account Details";
|
||||
$message = "Here are your account details:\n\n" .
|
||||
"For VOIP Application:\n\n" .
|
||||
"Extension: $extension\n" .
|
||||
"Password: $pbxPassword\n" .
|
||||
"Server name: connect.tilde.tel\n" .
|
||||
"Port: 5060 (UDP)\n" .
|
||||
"Voicemail Password: Your extension number is your temporary password. Please dial the voicemail to change this.\n\n" .
|
||||
"For User Control Panel:\n\n" .
|
||||
"Username: $extension\n" .
|
||||
"Password: $ucpPassword\n" .
|
||||
"Access control panel at:\n\n" .
|
||||
"https://connect.tilde.tel/ucp\n\n" .
|
||||
"Thanks,\n\n~deepend";
|
||||
|
||||
$headers = "From: no-reply@tilde.tel\r\n";
|
||||
$headers .= "Cc: signup@tilde.tel\r\n";
|
||||
|
||||
// Send the email
|
||||
if (mail($email, $subject, $message, $headers)) {
|
||||
$success_message = "Email sent successfully to $email!";
|
||||
} else {
|
||||
$error_message = "Error sending email to $email.";
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch all entries with a username
|
||||
$sql = "SELECT id, tilde_name, extension, username FROM phonebook WHERE username IS NOT NULL AND username != '' ORDER BY tilde_name, extension";
|
||||
$users_result = $conn->query($sql);
|
||||
|
||||
// Fetch all pending entries (without a username)
|
||||
$sql = "SELECT id, tilde_name, extension FROM phonebook WHERE username IS NULL OR username = '' ORDER BY tilde_name, extension";
|
||||
$pending_result = $conn->query($sql);
|
||||
|
||||
// Determine which section to show based on the query parameter
|
||||
$section = isset($_GET['section']) ? $_GET['section'] : 'users';
|
||||
?>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<link rel="icon" href="https://tilde.tel/logo-300.png">
|
||||
<style>
|
||||
.container {
|
||||
margin: 20px auto;
|
||||
width: 80%;
|
||||
font-family: 'DejaVu Sans', sans-serif;
|
||||
color: #333333;
|
||||
}
|
||||
.container h2 {
|
||||
color: #ffa633;
|
||||
text-align: center;
|
||||
}
|
||||
.nav-menu {
|
||||
text-align: center;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.nav-menu a {
|
||||
margin: 0 15px;
|
||||
text-decoration: none;
|
||||
font-size: 18px;
|
||||
color: #ffa633;
|
||||
}
|
||||
.nav-menu a.active {
|
||||
font-weight: bold;
|
||||
text-decoration: underline;
|
||||
}
|
||||
.list-container {
|
||||
margin-bottom: 40px;
|
||||
background-color: #ffffff;
|
||||
border: 2px solid #ffa633;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
.collapsible {
|
||||
background-color: #ffa633;
|
||||
color: white;
|
||||
cursor: pointer;
|
||||
padding: 10px;
|
||||
width: 100%;
|
||||
border: none;
|
||||
text-align: left;
|
||||
outline: none;
|
||||
font-size: 18px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.collapsible:after {
|
||||
content: '\002B'; /* Plus symbol */
|
||||
font-size: 13px;
|
||||
color: white;
|
||||
float: right;
|
||||
margin-left: 5px;
|
||||
}
|
||||
.collapsible.active:after {
|
||||
content: "\2212"; /* Minus symbol */
|
||||
}
|
||||
.content {
|
||||
padding: 0 20px;
|
||||
display: none;
|
||||
overflow: hidden;
|
||||
background-color: #f9f9f9;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 5px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin-top: 10px;
|
||||
}
|
||||
table, th, td {
|
||||
border: 1px solid #cccccc;
|
||||
padding: 10px;
|
||||
text-align: left;
|
||||
}
|
||||
th {
|
||||
background-color: #ffa633;
|
||||
color: white;
|
||||
}
|
||||
.form-container {
|
||||
margin: 20px auto;
|
||||
width: 50%;
|
||||
background-color: #ffffff;
|
||||
border: 2px solid #ffa633;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
.form-container label {
|
||||
font-weight: bold;
|
||||
font-size: 16px;
|
||||
color: #333333;
|
||||
display: block;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
.form-container input[type="text"],
|
||||
.form-container input[type="password"],
|
||||
.form-container input[type="email"] {
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
margin-bottom: 15px;
|
||||
border: 1px solid #cccccc;
|
||||
border-radius: 5px;
|
||||
font-size: 14px;
|
||||
}
|
||||
.form-container input[type="submit"] {
|
||||
background-color: #ffa633;
|
||||
color: #ffffff;
|
||||
padding: 10px 20px;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
font-size: 16px;
|
||||
}
|
||||
.form-container input[type="submit"]:hover {
|
||||
background-color: #e69530;
|
||||
}
|
||||
.message {
|
||||
font-size: 16px;
|
||||
color: green;
|
||||
font-weight: bold;
|
||||
margin-top: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
.error {
|
||||
font-size: 16px;
|
||||
color: red;
|
||||
font-weight: bold;
|
||||
margin-top: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
<title>Admin - Phonebook Management</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h2>Phonebook Management</h2>
|
||||
|
||||
<?php
|
||||
if (isset($success_message)) {
|
||||
echo "<p class='message'>$success_message</p>";
|
||||
}
|
||||
if (isset($error_message)) {
|
||||
echo "<p class='error'>$error_message</p>";
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="nav-menu">
|
||||
<a href="?section=users" class="<?= $section == 'users' ? 'active' : '' ?>">Existing Users</a>
|
||||
<a href="?section=pending" class="<?= $section == 'pending' ? 'active' : '' ?>">Pending Entries</a>
|
||||
<a href="?section=add" class="<?= $section == 'add' ? 'active' : '' ?>">Add New Entry</a>
|
||||
<a href="?section=send_email" class="<?= $section == 'send_email' ? 'active' : '' ?>">Send Confirmation Email</a>
|
||||
</div>
|
||||
|
||||
<?php if ($section == 'users'): ?>
|
||||
<div class="list-container">
|
||||
<h3>Existing Users</h3>
|
||||
<?php
|
||||
if ($users_result->num_rows > 0) {
|
||||
$currentTilde = '';
|
||||
while($row = $users_result->fetch_assoc()) {
|
||||
if ($currentTilde != $row['tilde_name']) {
|
||||
if ($currentTilde != '') {
|
||||
echo "</table></div>"; // Close previous content div and table
|
||||
}
|
||||
$currentTilde = $row['tilde_name'];
|
||||
echo "<button class='collapsible'>$currentTilde</button>";
|
||||
echo "<div class='content'>";
|
||||
echo "<table>
|
||||
<tr>
|
||||
<th>Extension</th>
|
||||
<th>Username</th>
|
||||
<th>Action</th>
|
||||
</tr>";
|
||||
}
|
||||
echo "<tr>";
|
||||
echo "<td>{$row['extension']}</td>";
|
||||
echo "<td>{$row['username']}</td>";
|
||||
echo "<td>
|
||||
<form action='' method='POST'>
|
||||
<button type='submit' name='delete' value='{$row['id']}'>Delete</button>
|
||||
</form>
|
||||
</td>";
|
||||
echo "</tr>";
|
||||
}
|
||||
echo "</table></div>"; // Close the last table and content div
|
||||
} else {
|
||||
echo "<p>No users found.</p>";
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<?php elseif ($section == 'pending'): ?>
|
||||
<div class="list-container">
|
||||
<h3>Pending Entries (No Username)</h3>
|
||||
<table>
|
||||
<tr>
|
||||
<th>Tilde Name</th>
|
||||
<th>Extension</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
<?php
|
||||
if ($pending_result->num_rows > 0) {
|
||||
while($row = $pending_result->fetch_assoc()) {
|
||||
echo "<tr>";
|
||||
echo "<td>{$row['tilde_name']}</td>";
|
||||
echo "<td>{$row['extension']}</td>";
|
||||
echo "<td>
|
||||
<form action='' method='POST'>
|
||||
<button type='submit' name='delete' value='{$row['id']}'>Delete</button>
|
||||
</form>
|
||||
</td>";
|
||||
echo "</tr>";
|
||||
}
|
||||
} else {
|
||||
echo "<tr><td colspan='3'>No pending entries.</td></tr>";
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
</div>
|
||||
<?php elseif ($section == 'add'): ?>
|
||||
<div class="form-container">
|
||||
<h3>Add a New Phonebook Entry</h3>
|
||||
<form action="" method="POST">
|
||||
<label for="tilde_name">Tilde Name:</label>
|
||||
<input type="text" id="tilde_name" name="tilde_name" required>
|
||||
|
||||
<label for="extension">Extension:</label>
|
||||
<input type="text" id="extension" name="extension" required>
|
||||
|
||||
<label for="username">Username:</label>
|
||||
<input type="text" id="username" name="username" required>
|
||||
|
||||
<input type="submit" value="Add Entry">
|
||||
</form>
|
||||
</div>
|
||||
<?php elseif ($section == 'send_email'): ?>
|
||||
<div class="form-container">
|
||||
<h3>Send Signup Confirmation Email</h3>
|
||||
<form action="" method="POST">
|
||||
<label for="extension">Extension:</label>
|
||||
<input type="text" id="extension" name="extension" required>
|
||||
|
||||
<label for="pbx_password">PBX Password:</label>
|
||||
<input type="password" id="pbx_password" name="pbx_password" required>
|
||||
|
||||
<label for="ucp_password">UCP Password:</label>
|
||||
<input type="password" id="ucp_password" name="ucp_password" required>
|
||||
|
||||
<label for="email">Email Address:</label>
|
||||
<input type="email" id="email" name="email" required>
|
||||
|
||||
<input type="submit" name="send_email" value="Send Confirmation Email">
|
||||
</form>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Collapsible functionality
|
||||
var coll = document.getElementsByClassName("collapsible");
|
||||
for (var i = 0; i < coll.length; i++) {
|
||||
coll[i].addEventListener("click", function() {
|
||||
this.classList.toggle("active");
|
||||
var content = this.nextElementSibling;
|
||||
if (content.style.display === "block") {
|
||||
content.style.display = "none";
|
||||
} else {
|
||||
content.style.display = "block";
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<?php
|
||||
$conn->close();
|
||||
?>
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"require": {
|
||||
"vlucas/phpdotenv": "^5.6"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,479 @@
|
|||
{
|
||||
"_readme": [
|
||||
"This file locks the dependencies of your project to a known state",
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "108be68e4e2b97fed51d36a10eed0849",
|
||||
"packages": [
|
||||
{
|
||||
"name": "graham-campbell/result-type",
|
||||
"version": "v1.1.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/GrahamCampbell/Result-Type.git",
|
||||
"reference": "3ba905c11371512af9d9bdd27d99b782216b6945"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/GrahamCampbell/Result-Type/zipball/3ba905c11371512af9d9bdd27d99b782216b6945",
|
||||
"reference": "3ba905c11371512af9d9bdd27d99b782216b6945",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.2.5 || ^8.0",
|
||||
"phpoption/phpoption": "^1.9.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^8.5.39 || ^9.6.20 || ^10.5.28"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"GrahamCampbell\\ResultType\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Graham Campbell",
|
||||
"email": "hello@gjcampbell.co.uk",
|
||||
"homepage": "https://github.com/GrahamCampbell"
|
||||
}
|
||||
],
|
||||
"description": "An Implementation Of The Result Type",
|
||||
"keywords": [
|
||||
"Graham Campbell",
|
||||
"GrahamCampbell",
|
||||
"Result Type",
|
||||
"Result-Type",
|
||||
"result"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/GrahamCampbell/Result-Type/issues",
|
||||
"source": "https://github.com/GrahamCampbell/Result-Type/tree/v1.1.3"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://github.com/GrahamCampbell",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/graham-campbell/result-type",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2024-07-20T21:45:45+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpoption/phpoption",
|
||||
"version": "1.9.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/schmittjoh/php-option.git",
|
||||
"reference": "e3fac8b24f56113f7cb96af14958c0dd16330f54"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/schmittjoh/php-option/zipball/e3fac8b24f56113f7cb96af14958c0dd16330f54",
|
||||
"reference": "e3fac8b24f56113f7cb96af14958c0dd16330f54",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.2.5 || ^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"bamarni/composer-bin-plugin": "^1.8.2",
|
||||
"phpunit/phpunit": "^8.5.39 || ^9.6.20 || ^10.5.28"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"bamarni-bin": {
|
||||
"bin-links": true,
|
||||
"forward-command": false
|
||||
},
|
||||
"branch-alias": {
|
||||
"dev-master": "1.9-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"PhpOption\\": "src/PhpOption/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"Apache-2.0"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Johannes M. Schmitt",
|
||||
"email": "schmittjoh@gmail.com",
|
||||
"homepage": "https://github.com/schmittjoh"
|
||||
},
|
||||
{
|
||||
"name": "Graham Campbell",
|
||||
"email": "hello@gjcampbell.co.uk",
|
||||
"homepage": "https://github.com/GrahamCampbell"
|
||||
}
|
||||
],
|
||||
"description": "Option Type for PHP",
|
||||
"keywords": [
|
||||
"language",
|
||||
"option",
|
||||
"php",
|
||||
"type"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/schmittjoh/php-option/issues",
|
||||
"source": "https://github.com/schmittjoh/php-option/tree/1.9.3"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://github.com/GrahamCampbell",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/phpoption/phpoption",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2024-07-20T21:41:07+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/polyfill-ctype",
|
||||
"version": "v1.30.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/polyfill-ctype.git",
|
||||
"reference": "0424dff1c58f028c451efff2045f5d92410bd540"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/0424dff1c58f028c451efff2045f5d92410bd540",
|
||||
"reference": "0424dff1c58f028c451efff2045f5d92410bd540",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.1"
|
||||
},
|
||||
"provide": {
|
||||
"ext-ctype": "*"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-ctype": "For best performance"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"thanks": {
|
||||
"name": "symfony/polyfill",
|
||||
"url": "https://github.com/symfony/polyfill"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
"bootstrap.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"Symfony\\Polyfill\\Ctype\\": ""
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Gert de Pagter",
|
||||
"email": "BackEndTea@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Symfony polyfill for ctype functions",
|
||||
"homepage": "https://symfony.com",
|
||||
"keywords": [
|
||||
"compatibility",
|
||||
"ctype",
|
||||
"polyfill",
|
||||
"portable"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/polyfill-ctype/tree/v1.30.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://symfony.com/sponsor",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/fabpot",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2024-05-31T15:07:36+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/polyfill-mbstring",
|
||||
"version": "v1.30.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/polyfill-mbstring.git",
|
||||
"reference": "fd22ab50000ef01661e2a31d850ebaa297f8e03c"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/fd22ab50000ef01661e2a31d850ebaa297f8e03c",
|
||||
"reference": "fd22ab50000ef01661e2a31d850ebaa297f8e03c",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.1"
|
||||
},
|
||||
"provide": {
|
||||
"ext-mbstring": "*"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-mbstring": "For best performance"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"thanks": {
|
||||
"name": "symfony/polyfill",
|
||||
"url": "https://github.com/symfony/polyfill"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
"bootstrap.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"Symfony\\Polyfill\\Mbstring\\": ""
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nicolas Grekas",
|
||||
"email": "p@tchwork.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Symfony polyfill for the Mbstring extension",
|
||||
"homepage": "https://symfony.com",
|
||||
"keywords": [
|
||||
"compatibility",
|
||||
"mbstring",
|
||||
"polyfill",
|
||||
"portable",
|
||||
"shim"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/polyfill-mbstring/tree/v1.30.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://symfony.com/sponsor",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/fabpot",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2024-06-19T12:30:46+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/polyfill-php80",
|
||||
"version": "v1.30.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/polyfill-php80.git",
|
||||
"reference": "77fa7995ac1b21ab60769b7323d600a991a90433"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/77fa7995ac1b21ab60769b7323d600a991a90433",
|
||||
"reference": "77fa7995ac1b21ab60769b7323d600a991a90433",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.1"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"thanks": {
|
||||
"name": "symfony/polyfill",
|
||||
"url": "https://github.com/symfony/polyfill"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
"bootstrap.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"Symfony\\Polyfill\\Php80\\": ""
|
||||
},
|
||||
"classmap": [
|
||||
"Resources/stubs"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Ion Bazan",
|
||||
"email": "ion.bazan@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Nicolas Grekas",
|
||||
"email": "p@tchwork.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions",
|
||||
"homepage": "https://symfony.com",
|
||||
"keywords": [
|
||||
"compatibility",
|
||||
"polyfill",
|
||||
"portable",
|
||||
"shim"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/polyfill-php80/tree/v1.30.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://symfony.com/sponsor",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/fabpot",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2024-05-31T15:07:36+00:00"
|
||||
},
|
||||
{
|
||||
"name": "vlucas/phpdotenv",
|
||||
"version": "v5.6.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/vlucas/phpdotenv.git",
|
||||
"reference": "a59a13791077fe3d44f90e7133eb68e7d22eaff2"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/a59a13791077fe3d44f90e7133eb68e7d22eaff2",
|
||||
"reference": "a59a13791077fe3d44f90e7133eb68e7d22eaff2",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-pcre": "*",
|
||||
"graham-campbell/result-type": "^1.1.3",
|
||||
"php": "^7.2.5 || ^8.0",
|
||||
"phpoption/phpoption": "^1.9.3",
|
||||
"symfony/polyfill-ctype": "^1.24",
|
||||
"symfony/polyfill-mbstring": "^1.24",
|
||||
"symfony/polyfill-php80": "^1.24"
|
||||
},
|
||||
"require-dev": {
|
||||
"bamarni/composer-bin-plugin": "^1.8.2",
|
||||
"ext-filter": "*",
|
||||
"phpunit/phpunit": "^8.5.34 || ^9.6.13 || ^10.4.2"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-filter": "Required to use the boolean validator."
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"bamarni-bin": {
|
||||
"bin-links": true,
|
||||
"forward-command": false
|
||||
},
|
||||
"branch-alias": {
|
||||
"dev-master": "5.6-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Dotenv\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"BSD-3-Clause"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Graham Campbell",
|
||||
"email": "hello@gjcampbell.co.uk",
|
||||
"homepage": "https://github.com/GrahamCampbell"
|
||||
},
|
||||
{
|
||||
"name": "Vance Lucas",
|
||||
"email": "vance@vancelucas.com",
|
||||
"homepage": "https://github.com/vlucas"
|
||||
}
|
||||
],
|
||||
"description": "Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.",
|
||||
"keywords": [
|
||||
"dotenv",
|
||||
"env",
|
||||
"environment"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/vlucas/phpdotenv/issues",
|
||||
"source": "https://github.com/vlucas/phpdotenv/tree/v5.6.1"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://github.com/GrahamCampbell",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/vlucas/phpdotenv",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2024-07-20T21:52:34+00:00"
|
||||
}
|
||||
],
|
||||
"packages-dev": [],
|
||||
"aliases": [],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": [],
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": [],
|
||||
"platform-dev": [],
|
||||
"plugin-api-version": "2.6.0"
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
require_once __DIR__ . '/vendor/autoload.php'; // Load Composer packages
|
||||
|
||||
// Load environment variables from the .env file
|
||||
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
|
||||
$dotenv->load();
|
||||
|
||||
$servername = $_ENV['DB_SERVERNAME'];
|
||||
$username = $_ENV['DB_USERNAME'];
|
||||
$password = $_ENV['DB_PASSWORD'];
|
||||
$dbname = $_ENV['DB_NAME'];
|
||||
|
||||
// Create connection
|
||||
$conn = new mysqli($servername, $username, $password);
|
||||
|
||||
// Check connection
|
||||
if ($conn->connect_error) {
|
||||
die("Connection failed: " . $conn->connect_error);
|
||||
}
|
||||
|
||||
// Create database if it doesn't exist
|
||||
$sql = "CREATE DATABASE IF NOT EXISTS $dbname";
|
||||
if ($conn->query($sql) === FALSE) {
|
||||
die("Error creating database: " . $conn->error);
|
||||
}
|
||||
|
||||
// Select the database
|
||||
$conn->select_db($dbname);
|
||||
|
||||
// Create the phonebook table if it doesn't exist
|
||||
$sql = "CREATE TABLE IF NOT EXISTS phonebook (
|
||||
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
||||
tilde_name VARCHAR(255) NOT NULL,
|
||||
extension VARCHAR(20) NOT NULL,
|
||||
username VARCHAR(255) NOT NULL
|
||||
)";
|
||||
|
||||
if ($conn->query($sql) === FALSE) {
|
||||
die("Error creating table: " . $conn->error);
|
||||
}
|
||||
?>
|
410
faq.html
410
faq.html
|
@ -1,206 +1,206 @@
|
|||
<html>
|
||||
<head>
|
||||
<link rel="icon" href="https://tilde.tel/logo-300.png">
|
||||
<style>
|
||||
@font-face {
|
||||
font-family: 'DejaVu Sans';
|
||||
src: url('https://tilde.tel/fonts/dejavu-sans-webfont.eot');
|
||||
src: url('https://tilde.tel/fonts/dejavu-sans-webfont.eot#iefix') format('embedded-opentype'),
|
||||
url('https://tilde.tel/fonts/dejavu-sans-webfont.woff2') format('woff2'),
|
||||
url('https://tilde.tel/fonts/dejavu-sans-webfont.woff') format('woff'),
|
||||
url('https://tilde.tel/fonts/dejavu-sans-webfont.ttf') format('truetype'),
|
||||
url('https://tilde.tel/fonts/dejavu-sans-webfont.svg#dejavu_sansregular') format('svg');
|
||||
}
|
||||
html {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: #f0f0f0;
|
||||
}
|
||||
.splash {
|
||||
position: absolute;
|
||||
width: 400px;
|
||||
height: 400px;
|
||||
top: 38%;
|
||||
left: 50%;
|
||||
margin: -150px 0 0 -200px;
|
||||
font-family: 'DejaVu Sans', sans-serif;
|
||||
text-align: center;
|
||||
}
|
||||
.slogan {
|
||||
font-weight: bold;
|
||||
font-size: 30px;
|
||||
color: #ffa633;
|
||||
font-family: 'DejaVu Sans', sans-serif;
|
||||
text-align: center;
|
||||
}
|
||||
.banner {
|
||||
position: absolute;
|
||||
bottom: 10px;
|
||||
width: 468px;
|
||||
left: 50%;
|
||||
right: 50%;
|
||||
margin: 0px 0px 0px -234px;
|
||||
border: 4px solid #cacaca;
|
||||
background-color: #cacaca;
|
||||
font-family: 'DejaVu Sans', sans-serif;
|
||||
font-size: 9px;
|
||||
color: #f0f0f0;
|
||||
}
|
||||
.info {
|
||||
font-weight: bold;
|
||||
font-size: 17px;
|
||||
color: #FFA633;
|
||||
}
|
||||
.column {
|
||||
float: left;
|
||||
}
|
||||
.left {
|
||||
width: 111px;
|
||||
text-align: center;
|
||||
}
|
||||
.right {
|
||||
width: 639px;
|
||||
text-align: left;
|
||||
}
|
||||
.row:after {
|
||||
content: "";
|
||||
display: table;
|
||||
clear: both;
|
||||
}
|
||||
</style>
|
||||
<title>~tel | FAQ</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="row">
|
||||
<div class="column left">
|
||||
<a href="https://tilde.tel/"><img src="https://tilde.tel/logo-300.png" height="66px" width="66px" alt="tilde.tel logo"></a><br/>
|
||||
<br/>
|
||||
<br/>
|
||||
<a href="https://tilde.tel/faq.html"><img src="https://tilde.tel/faq-on.png" height="44px" width="44px" alt="FAQ"></a><br/>
|
||||
<br/>
|
||||
<br/>
|
||||
<a href="https://tilde.tel/phonebook.html"><img src="https://tilde.tel/phonebook-off.png" height="44px" width="44px" alt="Phonebook"></a><br/>
|
||||
<br/>
|
||||
<a href="https://connect.tilde.tel/ucp" target="_blank"><img src="https://tilde.tel/settings-off.png" height="44px" width="44px" alt="User Control Panel"></a>
|
||||
<br/>
|
||||
<br/>
|
||||
<a href="https://tilde.tel/signup"><img src="https://tilde.tel/signup-off.png" height="44px" width="44px" alt="Sign up"></a>
|
||||
<br/>
|
||||
</div>
|
||||
<div class="column right">
|
||||
<div class="slogan">
|
||||
FAQ
|
||||
</div>
|
||||
<pre>
|
||||
*** ~tel Frequently Asked Questions ***
|
||||
|
||||
Background
|
||||
|
||||
Q. What is this?
|
||||
|
||||
A. tilde.tel is a small hobby software PBX for the tildeverse. So far
|
||||
users can make calls, leave voicemails and participate in a multi-
|
||||
user conference with more features to come. The numbers are
|
||||
loosely broken down by tilde, with each tilde having its own
|
||||
prefix "area code".
|
||||
|
||||
Q. Who runs it?
|
||||
|
||||
A. Service was originally created by cat, currently service is hosted by deepend and managed by deepend, cat and dokuja.
|
||||
|
||||
Q. Do you represent x tilde
|
||||
|
||||
A. No, while I use the names of the other tildes and PUBNIX systems
|
||||
as a way to group the various ~tel users I don't claim to be a
|
||||
representative of them in any way.
|
||||
|
||||
|
||||
Getting a phone number
|
||||
|
||||
Q. How do I sign up?
|
||||
|
||||
A. https://tilde.tel/signup
|
||||
|
||||
Q. What constitutes a tilde, as far as tilde.tel is concerned?
|
||||
|
||||
A. Basically any of the community PUBNIX systems, but not
|
||||
specifically limited to the ones that have "tilde" in their name
|
||||
and not specifically ones that offer shell access. Pretty much
|
||||
anyone will be considered, with the exception of...
|
||||
|
||||
Q. I'm an SDF user, can I have a tilde.tel number?
|
||||
|
||||
A. Nope! SDF already has a really excellent VoIP service that you
|
||||
should utilise instead and a lot of tilde.tel will mirror
|
||||
functionality the SDF's service already has. Being an SDF member
|
||||
of course doesn't exclude you from tilde.tel though, if you're
|
||||
also a member of a tilde, there just won't be an SDF "area code".
|
||||
|
||||
Q. Can I have x phone number?
|
||||
|
||||
A. Nah, that kind of thing can lead to butting heads and other nonsense.
|
||||
|
||||
Q. If I'm a member of multiple tildes, can I have multiple numbers?
|
||||
|
||||
A. Sure, if you need it why not.
|
||||
|
||||
|
||||
Using ~tel
|
||||
|
||||
Q. What are the settings I need to connect?
|
||||
|
||||
A. The settings below should get you up and running:
|
||||
|
||||
Username: [your extension]
|
||||
Password: [your password]
|
||||
Server: connect.tilde.tel
|
||||
Port: 5060
|
||||
Transport: UDP
|
||||
|
||||
Q. Can I update my details? CLI? Reset my password?
|
||||
|
||||
A. Nope! At least not yet. It's gonna be all manual initially while I
|
||||
sort out some kind of system to do that for you.
|
||||
|
||||
Q. Can I call external VoIP numbers or PSTN network numbers?
|
||||
|
||||
A. Not at the moment. URI dialing is in the works but dialing out to
|
||||
the PSTN network is fraught with danger.
|
||||
|
||||
Q. Can I dial in to ~tel externally?
|
||||
|
||||
A. Again not yet but that functionality is high on my list.
|
||||
|
||||
Q. Can I connect x to ~tel?
|
||||
|
||||
A. Knock yourself out. Connect a phone, connect your own Asterisk
|
||||
server, connect rusty old analog gear or a BBS, it's all good as
|
||||
long as it doesn't cause too much mischief or ruin anyone's good
|
||||
time. A robodialer is fun for a minute but gets old pretty quick.
|
||||
|
||||
Which brings us to...
|
||||
|
||||
|
||||
Using ~tel responsibly
|
||||
|
||||
Q. Does ~tel have a code of conduct/terms of use/whatever?
|
||||
|
||||
A. Sure: Do as thou wilt, harm none. This includes but is not limited
|
||||
too physical, emotional, psychological, financial and esoterical
|
||||
harm.
|
||||
|
||||
Be courteous and treat other users with respect and we'll all have
|
||||
a good time.
|
||||
|
||||
Q. Is there anything I should/should not be doing?
|
||||
|
||||
A. I think the tilde and PUBNIX communities have enough commmon sense
|
||||
to behave but just for clarity's sake; keep in mind the users on
|
||||
this system are real people, sometimes unsolicited calls are
|
||||
welcome and sometimes not, try to be sure you're not being a
|
||||
nuisance or pest before dialing out.
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
<html>
|
||||
<head>
|
||||
<link rel="icon" href="https://tilde.tel/logo-300.png">
|
||||
<style>
|
||||
@font-face {
|
||||
font-family: 'DejaVu Sans';
|
||||
src: url('https://tilde.tel/fonts/dejavu-sans-webfont.eot');
|
||||
src: url('https://tilde.tel/fonts/dejavu-sans-webfont.eot#iefix') format('embedded-opentype'),
|
||||
url('https://tilde.tel/fonts/dejavu-sans-webfont.woff2') format('woff2'),
|
||||
url('https://tilde.tel/fonts/dejavu-sans-webfont.woff') format('woff'),
|
||||
url('https://tilde.tel/fonts/dejavu-sans-webfont.ttf') format('truetype'),
|
||||
url('https://tilde.tel/fonts/dejavu-sans-webfont.svg#dejavu_sansregular') format('svg');
|
||||
}
|
||||
html {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: #f0f0f0;
|
||||
}
|
||||
.splash {
|
||||
position: absolute;
|
||||
width: 400px;
|
||||
height: 400px;
|
||||
top: 38%;
|
||||
left: 50%;
|
||||
margin: -150px 0 0 -200px;
|
||||
font-family: 'DejaVu Sans', sans-serif;
|
||||
text-align: center;
|
||||
}
|
||||
.slogan {
|
||||
font-weight: bold;
|
||||
font-size: 30px;
|
||||
color: #ffa633;
|
||||
font-family: 'DejaVu Sans', sans-serif;
|
||||
text-align: center;
|
||||
}
|
||||
.banner {
|
||||
position: absolute;
|
||||
bottom: 10px;
|
||||
width: 468px;
|
||||
left: 50%;
|
||||
right: 50%;
|
||||
margin: 0px 0px 0px -234px;
|
||||
border: 4px solid #cacaca;
|
||||
background-color: #cacaca;
|
||||
font-family: 'DejaVu Sans', sans-serif;
|
||||
font-size: 9px;
|
||||
color: #f0f0f0;
|
||||
}
|
||||
.info {
|
||||
font-weight: bold;
|
||||
font-size: 17px;
|
||||
color: #FFA633;
|
||||
}
|
||||
.column {
|
||||
float: left;
|
||||
}
|
||||
.left {
|
||||
width: 111px;
|
||||
text-align: center;
|
||||
}
|
||||
.right {
|
||||
width: 639px;
|
||||
text-align: left;
|
||||
}
|
||||
.row:after {
|
||||
content: "";
|
||||
display: table;
|
||||
clear: both;
|
||||
}
|
||||
</style>
|
||||
<title>~tel | FAQ</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="row">
|
||||
<div class="column left">
|
||||
<a href="https://tilde.tel/"><img src="https://tilde.tel/logo-300.png" height="66px" width="66px" alt="tilde.tel logo"></a><br/>
|
||||
<br/>
|
||||
<br/>
|
||||
<a href="https://tilde.tel/faq.html"><img src="https://tilde.tel/faq-on.png" height="44px" width="44px" alt="FAQ"></a><br/>
|
||||
<br/>
|
||||
<br/>
|
||||
<a href="https://tilde.tel/phonebook.php"><img src="https://tilde.tel/phonebook-off.png" height="44px" width="44px" alt="Phonebook"></a><br/>
|
||||
<br/>
|
||||
<a href="https://connect.tilde.tel/ucp" target="_blank"><img src="https://tilde.tel/settings-off.png" height="44px" width="44px" alt="User Control Panel"></a>
|
||||
<br/>
|
||||
<br/>
|
||||
<a href="https://tilde.tel/signup"><img src="https://tilde.tel/signup-off.png" height="44px" width="44px" alt="Sign up"></a>
|
||||
<br/>
|
||||
</div>
|
||||
<div class="column right">
|
||||
<div class="slogan">
|
||||
FAQ
|
||||
</div>
|
||||
<pre>
|
||||
*** ~tel Frequently Asked Questions ***
|
||||
|
||||
Background
|
||||
|
||||
Q. What is this?
|
||||
|
||||
A. tilde.tel is a small hobby software PBX for the tildeverse. So far
|
||||
users can make calls, leave voicemails and participate in a multi-
|
||||
user conference with more features to come. The numbers are
|
||||
loosely broken down by tilde, with each tilde having its own
|
||||
prefix "area code".
|
||||
|
||||
Q. Who runs it?
|
||||
|
||||
A. Service was originally created by cat, currently service is hosted by deepend and managed by deepend, cat and dokuja.
|
||||
|
||||
Q. Do you represent x tilde
|
||||
|
||||
A. No, while I use the names of the other tildes and PUBNIX systems
|
||||
as a way to group the various ~tel users I don't claim to be a
|
||||
representative of them in any way.
|
||||
|
||||
|
||||
Getting a phone number
|
||||
|
||||
Q. How do I sign up?
|
||||
|
||||
A. https://tilde.tel/signup
|
||||
|
||||
Q. What constitutes a tilde, as far as tilde.tel is concerned?
|
||||
|
||||
A. Basically any of the community PUBNIX systems, but not
|
||||
specifically limited to the ones that have "tilde" in their name
|
||||
and not specifically ones that offer shell access. Pretty much
|
||||
anyone will be considered, with the exception of...
|
||||
|
||||
Q. I'm an SDF user, can I have a tilde.tel number?
|
||||
|
||||
A. Nope! SDF already has a really excellent VoIP service that you
|
||||
should utilise instead and a lot of tilde.tel will mirror
|
||||
functionality the SDF's service already has. Being an SDF member
|
||||
of course doesn't exclude you from tilde.tel though, if you're
|
||||
also a member of a tilde, there just won't be an SDF "area code".
|
||||
|
||||
Q. Can I have x phone number?
|
||||
|
||||
A. Nah, that kind of thing can lead to butting heads and other nonsense.
|
||||
|
||||
Q. If I'm a member of multiple tildes, can I have multiple numbers?
|
||||
|
||||
A. Sure, if you need it why not.
|
||||
|
||||
|
||||
Using ~tel
|
||||
|
||||
Q. What are the settings I need to connect?
|
||||
|
||||
A. The settings below should get you up and running:
|
||||
|
||||
Username: [your extension]
|
||||
Password: [your password]
|
||||
Server: connect.tilde.tel
|
||||
Port: 5060
|
||||
Transport: UDP
|
||||
|
||||
Q. Can I update my details? CLI? Reset my password?
|
||||
|
||||
A. Nope! At least not yet. It's gonna be all manual initially while I
|
||||
sort out some kind of system to do that for you.
|
||||
|
||||
Q. Can I call external VoIP numbers or PSTN network numbers?
|
||||
|
||||
A. Not at the moment. URI dialing is in the works but dialing out to
|
||||
the PSTN network is fraught with danger.
|
||||
|
||||
Q. Can I dial in to ~tel externally?
|
||||
|
||||
A. Again not yet but that functionality is high on my list.
|
||||
|
||||
Q. Can I connect x to ~tel?
|
||||
|
||||
A. Knock yourself out. Connect a phone, connect your own Asterisk
|
||||
server, connect rusty old analog gear or a BBS, it's all good as
|
||||
long as it doesn't cause too much mischief or ruin anyone's good
|
||||
time. A robodialer is fun for a minute but gets old pretty quick.
|
||||
|
||||
Which brings us to...
|
||||
|
||||
|
||||
Using ~tel responsibly
|
||||
|
||||
Q. Does ~tel have a code of conduct/terms of use/whatever?
|
||||
|
||||
A. Sure: Do as thou wilt, harm none. This includes but is not limited
|
||||
too physical, emotional, psychological, financial and esoterical
|
||||
harm.
|
||||
|
||||
Be courteous and treat other users with respect and we'll all have
|
||||
a good time.
|
||||
|
||||
Q. Is there anything I should/should not be doing?
|
||||
|
||||
A. I think the tilde and PUBNIX communities have enough commmon sense
|
||||
to behave but just for clarity's sake; keep in mind the users on
|
||||
this system are real people, sometimes unsolicited calls are
|
||||
welcome and sometimes not, try to be sure you're not being a
|
||||
nuisance or pest before dialing out.
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
181
index.html
181
index.html
|
@ -1,91 +1,90 @@
|
|||
|
||||
<html>
|
||||
<head>
|
||||
<link rel="icon" href="https://tilde.tel/logo-300.png">
|
||||
<style>
|
||||
@font-face {
|
||||
font-family: 'DejaVu Sans';
|
||||
src: url('https://tilde.tel/fonts/dejavu-sans-webfont.eot');
|
||||
src: url('https://tilde.tel/fonts/dejavu-sans-webfont.eot#iefix') format('embedded-opentype'),
|
||||
url('https://tilde.tel/fonts/dejavu-sans-webfont.woff2') format('woff2'),
|
||||
url('https://tilde.tel/fonts/dejavu-sans-webfont.woff') format('woff'),
|
||||
url('https://tilde.tel/fonts/dejavu-sans-webfont.ttf') format('truetype'),
|
||||
url('https://tilde.tel/fonts/dejavu-sans-webfont.svg#dejavu_sansregular') format('svg');
|
||||
}
|
||||
html {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: #f0f0f0;
|
||||
}
|
||||
.splash {
|
||||
position: absolute;
|
||||
width: 400px;
|
||||
height: 400px;
|
||||
top: 38%;
|
||||
left: 50%;
|
||||
margin: -150px 0 0 -200px;
|
||||
font-family: 'DejaVu Sans', sans-serif;
|
||||
text-align: center;
|
||||
}
|
||||
.slogan {
|
||||
font-weight: bold;
|
||||
font-size: 30px;
|
||||
color: #ffa633;
|
||||
font-family: 'DejaVu Sans', sans-serif;
|
||||
text-align: center;
|
||||
}
|
||||
.banner {
|
||||
position: absolute;
|
||||
bottom: 10px;
|
||||
width: 468px;
|
||||
left: 50%;
|
||||
right: 50%;
|
||||
margin: 0px 0px 0px -234px;
|
||||
border: 4px solid #cacaca;
|
||||
background-color: #cacaca;
|
||||
font-family: 'DejaVu Sans', sans-serif;
|
||||
font-size: 9px;
|
||||
color: #f0f0f0;
|
||||
}
|
||||
.info {
|
||||
font-weight: bold;
|
||||
font-size: 17px;
|
||||
color: #FFA633;
|
||||
}
|
||||
.column {
|
||||
float: left;
|
||||
}
|
||||
.left {
|
||||
width: 111px;
|
||||
text-align: center;
|
||||
}
|
||||
.right {
|
||||
width: 639px;
|
||||
text-align: left;
|
||||
}
|
||||
.row:after {
|
||||
content: "";
|
||||
display: table;
|
||||
clear: both;
|
||||
}
|
||||
</style>
|
||||
<title>~tel</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="splash">
|
||||
<img src="https://tilde.tel/logo-300.png" alt="tilde.tel logo"><br>
|
||||
<br>
|
||||
<font class="slogan">“Your $HOME Phone”</font><br>
|
||||
<font class="info">#tildetel on irc.newnet.net</font><br>
|
||||
<br>
|
||||
<img src="https://stats.newnet.net/badges/badge.php?channel=%23tildetel"><br>
|
||||
<br>
|
||||
<a href="https://tilde.tel/faq.html"><img src="https://tilde.tel/faq-off.png" height="44px" width="44px" alt="FAQ"></a> <a href="https://tilde.tel/phonebook.html"><img src="https://tilde.tel/phonebook-off.png" height="44px" width="44px" alt="FAQ"></a> <a href="https://connect.tilde.tel/ucp" target="_blank"><img src="https://tilde.tel/settings-off.png" height="44px" width="44px" alt="User Control Panel"></a> <a href="https://tilde.tel/signup"><img src="https://tilde.tel/signup-off.png" height="44px" width="44px" alt="Sign up"></a> <br>
|
||||
</div>
|
||||
<div class="banner">
|
||||
Tildeverse Banner Exchange<br/>
|
||||
<br>
|
||||
<iframe src="https://banner.tildeverse.org/work.php?ID=tildetel" width="468" height="60" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no"></iframe>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
<html>
|
||||
<head>
|
||||
<link rel="icon" href="https://tilde.tel/logo-300.png">
|
||||
<style>
|
||||
@font-face {
|
||||
font-family: 'DejaVu Sans';
|
||||
src: url('https://tilde.tel/fonts/dejavu-sans-webfont.eot');
|
||||
src: url('https://tilde.tel/fonts/dejavu-sans-webfont.eot#iefix') format('embedded-opentype'),
|
||||
url('https://tilde.tel/fonts/dejavu-sans-webfont.woff2') format('woff2'),
|
||||
url('https://tilde.tel/fonts/dejavu-sans-webfont.woff') format('woff'),
|
||||
url('https://tilde.tel/fonts/dejavu-sans-webfont.ttf') format('truetype'),
|
||||
url('https://tilde.tel/fonts/dejavu-sans-webfont.svg#dejavu_sansregular') format('svg');
|
||||
}
|
||||
html {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: #f0f0f0;
|
||||
}
|
||||
.splash {
|
||||
position: absolute;
|
||||
width: 400px;
|
||||
height: 400px;
|
||||
top: 38%;
|
||||
left: 50%;
|
||||
margin: -150px 0 0 -200px;
|
||||
font-family: 'DejaVu Sans', sans-serif;
|
||||
text-align: center;
|
||||
}
|
||||
.slogan {
|
||||
font-weight: bold;
|
||||
font-size: 30px;
|
||||
color: #ffa633;
|
||||
font-family: 'DejaVu Sans', sans-serif;
|
||||
text-align: center;
|
||||
}
|
||||
.banner {
|
||||
position: absolute;
|
||||
bottom: 10px;
|
||||
width: 468px;
|
||||
left: 50%;
|
||||
right: 50%;
|
||||
margin: 0px 0px 0px -234px;
|
||||
border: 4px solid #cacaca;
|
||||
background-color: #cacaca;
|
||||
font-family: 'DejaVu Sans', sans-serif;
|
||||
font-size: 9px;
|
||||
color: #f0f0f0;
|
||||
}
|
||||
.info {
|
||||
font-weight: bold;
|
||||
font-size: 17px;
|
||||
color: #FFA633;
|
||||
}
|
||||
.column {
|
||||
float: left;
|
||||
}
|
||||
.left {
|
||||
width: 111px;
|
||||
text-align: center;
|
||||
}
|
||||
.right {
|
||||
width: 639px;
|
||||
text-align: left;
|
||||
}
|
||||
.row:after {
|
||||
content: "";
|
||||
display: table;
|
||||
clear: both;
|
||||
}
|
||||
</style>
|
||||
<title>~tel</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="splash">
|
||||
<img src="https://tilde.tel/logo-300.png" alt="tilde.tel logo"><br>
|
||||
<br>
|
||||
<font class="slogan">“Your $HOME Phone”</font><br>
|
||||
<font class="info">#tildetel on irc.newnet.net</font><br>
|
||||
<br>
|
||||
<img src="https://stats.newnet.net/badges/badge.php?channel=%23tildetel"><br>
|
||||
<br>
|
||||
<a href="https://tilde.tel/faq.html"><img src="https://tilde.tel/faq-off.png" height="44px" width="44px" alt="FAQ"></a> <a href="https://tilde.tel/phonebook.php"><img src="https://tilde.tel/phonebook-off.png" height="44px" width="44px" alt="FAQ"></a> <a href="https://connect.tilde.tel/ucp" target="_blank"><img src="https://tilde.tel/settings-off.png" height="44px" width="44px" alt="User Control Panel"></a> <a href="https://tilde.tel/signup"><img src="https://tilde.tel/signup-off.png" height="44px" width="44px" alt="Sign up"></a> <br>
|
||||
</div>
|
||||
<div class="banner">
|
||||
Tildeverse Banner Exchange<br/>
|
||||
<br>
|
||||
<iframe src="https://banner.tildeverse.org/work.php?ID=tildetel" width="468" height="60" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no"></iframe>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,177 +1,150 @@
|
|||
<html>
|
||||
<head>
|
||||
<link rel="icon" href="https://tilde.tel/logo-300.png">
|
||||
<style>
|
||||
@font-face {
|
||||
font-family: 'DejaVu Sans';
|
||||
src: url('/https://tilde.tel/fonts/dejavu-sans-webfont.eot');
|
||||
src: url('/https://tilde.tel/fonts/dejavu-sans-webfont.eot#iefix') format('embedded-opentype'),
|
||||
url('https://tilde.tel/fonts/dejavu-sans-webfont.woff2') format('woff2'),
|
||||
url('/https://tilde.tel/fonts/dejavu-sans-webfont.woff') format('woff'),
|
||||
url('/https://tilde.tel/fonts/dejavu-sans-webfont.ttf') format('truetype'),
|
||||
url('/https://tilde.tel/fonts/dejavu-sans-webfont.svg#dejavu_sansregular') format('svg');
|
||||
}
|
||||
html {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: #f0f0f0;
|
||||
}
|
||||
.splash {
|
||||
position: absolute;
|
||||
width: 400px;
|
||||
height: 400px;
|
||||
top: 38%;
|
||||
left: 50%;
|
||||
margin: -150px 0 0 -200px;
|
||||
font-family: 'DejaVu Sans', sans-serif;
|
||||
text-align: center;
|
||||
}
|
||||
.slogan {
|
||||
font-weight: bold;
|
||||
font-size: 30px;
|
||||
color: #ffa633;
|
||||
font-family: 'DejaVu Sans', sans-serif;
|
||||
text-align: center;
|
||||
}
|
||||
.banner {
|
||||
position: absolute;
|
||||
bottom: 10px;
|
||||
width: 468px;
|
||||
left: 50%;
|
||||
right: 50%;
|
||||
margin: 0px 0px 0px -234px;
|
||||
border: 4px solid #cacaca;
|
||||
background-color: #cacaca;
|
||||
font-family: 'DejaVu Sans', sans-serif;
|
||||
font-size: 9px;
|
||||
color: #f0f0f0;
|
||||
}
|
||||
.info {
|
||||
font-weight: bold;
|
||||
font-size: 17px;
|
||||
color: #FFA633;
|
||||
}
|
||||
.column {
|
||||
float: left;
|
||||
}
|
||||
.left {
|
||||
width: 111px;
|
||||
text-align: center;
|
||||
}
|
||||
.right {
|
||||
width: 639px;
|
||||
text-align: left;
|
||||
}
|
||||
.row:after {
|
||||
content: "";
|
||||
display: table;
|
||||
clear: both;
|
||||
}
|
||||
</style>
|
||||
<title>~tel | the Orange Pages</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="row">
|
||||
<div class="column left">
|
||||
<a href="https://tilde.tel/"><img src="https://tilde.tel/logo-300.png" height="66px" width="66px" alt="tilde.tel logo"></a><br/>
|
||||
<br/>
|
||||
<br/>
|
||||
<a href="https://tilde.tel/faq.html"><img src="https://tilde.tel/faq-off.png" height="44px" width="44px" alt="FAQ"></a><br/>
|
||||
<br/>
|
||||
<br/>
|
||||
<a href="https://tilde.tel/phonebook.html"><img src="https://tilde.tel/phonebook-on.png" height="44px" width="44px" alt="Phonebook"></a><br/>
|
||||
<br/>
|
||||
<a href="https://connect.tilde.tel/ucp" target="_blank"><img src="https://tilde.tel/settings-off.png" height="44px" width="44px" alt="User Control Panel"></a>
|
||||
<br/>
|
||||
<br/>
|
||||
<a href="https://tilde.tel/signup"><img src="https://tilde.tel/signup-off.png" height="44px" width="44px" alt="Sign up"></a>
|
||||
<br/>
|
||||
</div>
|
||||
<div class="column right">
|
||||
<div class="slogan">
|
||||
the Orange Pages
|
||||
</div>
|
||||
<pre>
|
||||
Service Numbers
|
||||
|
||||
[Extension] [Service]
|
||||
1101 Echo Test
|
||||
1102 Music on Hold, courtesy of tilderadio.org
|
||||
1104 Voicemail
|
||||
1105 Conference bridge
|
||||
|
||||
|
||||
The 1900s (Currently unavailable)
|
||||
|
||||
[Extension] [Contributor] [Description]
|
||||
|
||||
1900s Hopefully returning soon!
|
||||
|
||||
~Tel Community
|
||||
|
||||
[Tilde] [Extension] [User]
|
||||
tilde.team 2013101 dokuja
|
||||
2013105 brendo
|
||||
2013122 la
|
||||
2013123 murteza
|
||||
2013124 ianremsen
|
||||
2013125 ideclon
|
||||
2013126 youngchief
|
||||
|
||||
cosmic.voyage 2023101 tomasino
|
||||
|
||||
tilde.institute 2033106 mounderfod
|
||||
2033107 fn
|
||||
|
||||
circumlunar.space 2053101 solderpunk
|
||||
2053104 shufei
|
||||
|
||||
tilde.town 2063101 cat
|
||||
2063108 cel
|
||||
2063112 lunacb
|
||||
2063113 derberger
|
||||
2063114 thegiant
|
||||
2063115 iikorni
|
||||
2063116 dlopez
|
||||
2063117 jns
|
||||
|
||||
tilde.club 2123103 deepend
|
||||
2123109 barnold
|
||||
2123110 frostcake
|
||||
2123111 freach
|
||||
2123112 hnr
|
||||
2123113 mutex
|
||||
2123114 diatonic
|
||||
2123115 zbba
|
||||
2123116 juest
|
||||
2123117 xkrishguptaa
|
||||
2123118 speedygo55
|
||||
2123119 marcelositr
|
||||
|
||||
|
||||
ctrl-c.club 2133103 pareid0lia
|
||||
2133104 loghead
|
||||
2133105 hexagram23
|
||||
2133106 vrunt
|
||||
2133107 unbeatable101
|
||||
2133108 winco
|
||||
|
||||
tilde.green 2193101 jmjl
|
||||
|
||||
envs.net 2203101 youshitsune
|
||||
2203102 wilco
|
||||
2203103 georgemoody
|
||||
2203104 li0ard
|
||||
|
||||
tilde.guru 2213101 sarmonsiill
|
||||
|
||||
exozy.me 2403101 nothr
|
||||
|
||||
texto-plano.xyz 2413101 peron
|
||||
|
||||
thunix.net 2043103 cycledelix
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
include 'db.php';
|
||||
|
||||
// Fetch all entries from the phonebook table where username is not empty
|
||||
$sql = "SELECT tilde_name, extension, username FROM phonebook WHERE username IS NOT NULL AND username != '' ORDER BY tilde_name, extension";
|
||||
$result = $conn->query($sql);
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<link rel="icon" href="https://tilde.tel/logo-300.png">
|
||||
<style>
|
||||
@font-face {
|
||||
font-family: 'DejaVu Sans';
|
||||
src: url('/https://tilde.tel/fonts/dejavu-sans-webfont.eot');
|
||||
src: url('/https://tilde.tel/fonts/dejavu-sans-webfont.eot#iefix') format('embedded-opentype'),
|
||||
url('/https://tilde.tel/fonts/dejavu-sans-webfont.woff2') format('woff2'),
|
||||
url('/https://tilde.tel/fonts/dejavu-sans-webfont.woff') format('woff'),
|
||||
url('/https://tilde.tel/fonts/dejavu-sans-webfont.ttf') format('truetype'),
|
||||
url('/https://tilde.tel/fonts/dejavu-sans-webfont.svg#dejavu_sansregular') format('svg');
|
||||
}
|
||||
html {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: #f0f0f0;
|
||||
}
|
||||
.splash {
|
||||
position: absolute;
|
||||
width: 400px;
|
||||
height: 400px;
|
||||
top: 38%;
|
||||
left: 50%;
|
||||
margin: -150px 0 0 -200px;
|
||||
font-family: 'DejaVu Sans', sans-serif;
|
||||
text-align: center;
|
||||
}
|
||||
.slogan {
|
||||
font-weight: bold;
|
||||
font-size: 30px;
|
||||
color: #ffa633;
|
||||
font-family: 'DejaVu Sans', sans-serif;
|
||||
text-align: center;
|
||||
}
|
||||
.banner {
|
||||
position: absolute;
|
||||
bottom: 10px;
|
||||
width: 468px;
|
||||
left: 50%;
|
||||
right: 50%;
|
||||
margin: 0px 0px 0px -234px;
|
||||
border: 4px solid #cacaca;
|
||||
background-color: #cacaca;
|
||||
font-family: 'DejaVu Sans', sans-serif;
|
||||
font-size: 9px;
|
||||
color: #f0f0f0;
|
||||
}
|
||||
.info {
|
||||
font-weight: bold;
|
||||
font-size: 17px;
|
||||
color: #FFA633;
|
||||
}
|
||||
.column {
|
||||
float: left;
|
||||
}
|
||||
.left {
|
||||
width: 111px;
|
||||
text-align: center;
|
||||
}
|
||||
.right {
|
||||
width: 639px;
|
||||
text-align: left;
|
||||
}
|
||||
.row:after {
|
||||
content: "";
|
||||
display: table;
|
||||
clear: both;
|
||||
}
|
||||
</style>
|
||||
<title>~tel | the Orange Pages</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="row">
|
||||
<div class="column left">
|
||||
<a href="https://tilde.tel/"><img src="https://tilde.tel/logo-300.png" height="66px" width="66px" alt="tilde.tel logo"></a><br/>
|
||||
<br/>
|
||||
<br/>
|
||||
<a href="https://tilde.tel/faq.html"><img src="https://tilde.tel/faq-off.png" height="44px" width="44px" alt="FAQ"></a><br/>
|
||||
<br/>
|
||||
<br/>
|
||||
<a href="https://tilde.tel/phonebook.php"><img src="https://tilde.tel/phonebook-on.png" height="44px" width="44px" alt="Phonebook"></a><br/>
|
||||
<br/>
|
||||
<a href="https://connect.tilde.tel/ucp" target="_blank"><img src="https://tilde.tel/settings-off.png" height="44px" width="44px" alt="User Control Panel"></a>
|
||||
<br/>
|
||||
<br/>
|
||||
<a href="https://tilde.tel/signup"><img src="https://tilde.tel/signup-off.png" height="44px" width="44px" alt="Sign up"></a>
|
||||
<br/>
|
||||
</div>
|
||||
<div class="column right">
|
||||
<div class="slogan">
|
||||
the Orange Pages
|
||||
</div>
|
||||
<pre>
|
||||
Service Numbers
|
||||
|
||||
[Extension] [Service]
|
||||
1101 Echo Test
|
||||
1102 Music on Hold, courtesy of tilderadio.org
|
||||
1104 Voicemail
|
||||
1105 Conference bridge
|
||||
|
||||
|
||||
The 1900s (Currently unavailable)
|
||||
|
||||
Coming soon!
|
||||
|
||||
|
||||
[Extension] [Contributor] [Description]
|
||||
|
||||
1900s Hopefully returning soon!
|
||||
|
||||
~Tel Community
|
||||
|
||||
[Tilde] [Extension] [User]
|
||||
<br>
|
||||
<?php
|
||||
if ($result->num_rows > 0) {
|
||||
$currentTilde = '';
|
||||
while($row = $result->fetch_assoc()) {
|
||||
if ($currentTilde != $row['tilde_name']) {
|
||||
if ($currentTilde != '') {
|
||||
echo "<br>\n"; // Insert a line break between different Tildes
|
||||
}
|
||||
$currentTilde = $row['tilde_name'];
|
||||
echo $currentTilde . "\n";
|
||||
}
|
||||
echo str_pad('', 20) . str_pad($row['extension'], 20) . $row['username'] . "\n";
|
||||
}
|
||||
} else {
|
||||
echo "No entries found.";
|
||||
}
|
||||
?>
|
||||
<br>
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
$conn->close();
|
||||
?>
|
|
@ -1,120 +0,0 @@
|
|||
<html>
|
||||
<head>
|
||||
<link rel="icon" href="https://tilde.tel/logo-300.png">
|
||||
<style>
|
||||
@font-face {
|
||||
font-family: 'DejaVu Sans';
|
||||
src: url('https://tilde.tel/fonts/dejavu-sans-webfont.eot');
|
||||
src: url('https://tilde.tel/fonts/dejavu-sans-webfont.eot#iefix') format('embedded-opentype'),
|
||||
url('https://tilde.tel/fonts/dejavu-sans-webfont.woff2') format('woff2'),
|
||||
url('https://tilde.tel/fonts/dejavu-sans-webfont.woff') format('woff'),
|
||||
url('https://tilde.tel/fonts/dejavu-sans-webfont.ttf') format('truetype'),
|
||||
url('https://tilde.tel/fonts/dejavu-sans-webfont.svg#dejavu_sansregular') format('svg');
|
||||
}
|
||||
html {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: #f0f0f0;
|
||||
}
|
||||
.splash {
|
||||
position: absolute;
|
||||
width: 400px;
|
||||
height: 400px;
|
||||
top: 38%;
|
||||
left: 50%;
|
||||
margin: -150px 0 0 -200px;
|
||||
font-family: 'DejaVu Sans', sans-serif;
|
||||
text-align: center;
|
||||
}
|
||||
.slogan {
|
||||
font-weight: bold;
|
||||
font-size: 30px;
|
||||
color: #ffa633;
|
||||
font-family: 'DejaVu Sans', sans-serif;
|
||||
text-align: center;
|
||||
}
|
||||
.banner {
|
||||
position: absolute;
|
||||
bottom: 10px;
|
||||
width: 468px;
|
||||
left: 50%;
|
||||
right: 50%;
|
||||
margin: 0px 0px 0px -234px;
|
||||
border: 4px solid #cacaca;
|
||||
background-color: #cacaca;
|
||||
font-family: 'DejaVu Sans', sans-serif;
|
||||
font-size: 9px;
|
||||
color: #f0f0f0;
|
||||
}
|
||||
.info {
|
||||
font-weight: bold;
|
||||
font-size: 17px;
|
||||
color: #FFA633;
|
||||
}
|
||||
.column {
|
||||
float: left;
|
||||
}
|
||||
.left {
|
||||
width: 111px;
|
||||
text-align: center;
|
||||
}
|
||||
.right {
|
||||
width: 639px;
|
||||
text-align: left;
|
||||
}
|
||||
.row:after {
|
||||
content: "";
|
||||
display: table;
|
||||
clear: both;
|
||||
}
|
||||
</style>
|
||||
<title>~tel | Sign Up</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="row">
|
||||
<div class="column left">
|
||||
<a href="https://tilde.tel/"><img src="https://tilde.tel/logo-300.png" height="66px" width="66px" alt="tilde.tel logo"></a><br/>
|
||||
<br/>
|
||||
<br/>
|
||||
<a href="https://tilde.tel/faq.html"><img src="https://tilde.tel/faq-off.png" height="44px" width="44px" alt="FAQ"></a><br/>
|
||||
<br/>
|
||||
<br/>
|
||||
<a href="https://tilde.tel/phonebook.html"><img src="https://tilde.tel/phonebook-off.png" height="44px" width="44px" alt="Phonebook"></a><br/>
|
||||
<br/>
|
||||
<a href="https://connect.tilde.tel/ucp" target="_blank"><img src="https://tilde.tel/settings-off.png" height="44px" width="44px" alt="User Control Panel"></a>
|
||||
<br/>
|
||||
<br/>
|
||||
<a href="https://tilde.tel/signup"><img src="https://tilde.tel/signup-on.png" height="44px" width="44px" alt="Sign up"></a><br/>
|
||||
</div>
|
||||
<div class="column right">
|
||||
<div class="slogan">
|
||||
Sign up
|
||||
</div>
|
||||
<pre>
|
||||
Welcome to tilde.tel, excited to have you as a member!
|
||||
|
||||
|
||||
**See FAQ if your unsure if you qualify to have an account**
|
||||
|
||||
|
||||
**If you were a previous tilde.tel user you can let us know if you would like your old extension.**
|
||||
|
||||
|
||||
How-to request account:
|
||||
|
||||
|
||||
Send email to signup@tilde.tel
|
||||
|
||||
|
||||
EMAIL TOPIC:
|
||||
|
||||
tilde.tel account request
|
||||
|
||||
EMAIL CONTENT:
|
||||
|
||||
Your email address, tilde username and what tilde your a member.
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,258 @@
|
|||
<?php
|
||||
include '../db.php';
|
||||
|
||||
$nextExtension = ''; // Variable to hold the next available extension
|
||||
$selectedTilde = ''; // Variable to hold the selected Tilde
|
||||
$formSubmitted = false; // Variable to track if the form was submitted successfully
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['tilde'])) {
|
||||
$selectedTilde = htmlspecialchars($_POST['tilde']);
|
||||
|
||||
// Fetch the highest extension for the selected Tilde
|
||||
$sql = "SELECT MAX(extension) as max_extension FROM phonebook WHERE tilde_name='$selectedTilde'";
|
||||
$result = $conn->query($sql);
|
||||
if ($result->num_rows > 0) {
|
||||
$row = $result->fetch_assoc();
|
||||
// Increment the extension by 1
|
||||
$nextExtension = strval(intval($row['max_extension']) + 1);
|
||||
} else {
|
||||
// Default extension if no records found
|
||||
$nextExtension = '0000001';
|
||||
}
|
||||
}
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['extension'])) {
|
||||
$email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
|
||||
$username = htmlspecialchars($_POST['username']);
|
||||
$tilde = htmlspecialchars($_POST['tilde']);
|
||||
$extension = htmlspecialchars($_POST['extension']);
|
||||
|
||||
// Email content
|
||||
$subject = "tilde.tel account request";
|
||||
$message = "Email: $email\nUsername: $username\nTilde: $tilde\nExtension: $extension";
|
||||
$headers = "From: signup@tilde.tel\r\nReply-To: $email";
|
||||
|
||||
// Send the email
|
||||
if (mail("signup@tilde.tel", $subject, $message, $headers)) {
|
||||
$formSubmitted = true;
|
||||
|
||||
// Insert the new entry into the phonebook
|
||||
$stmt = $conn->prepare("INSERT INTO phonebook (tilde_name, extension, username) VALUES (?, ?, ?)");
|
||||
$stmt->bind_param("sss", $tilde, $extension, $username);
|
||||
$stmt->execute();
|
||||
$stmt->close();
|
||||
} else {
|
||||
echo "<p>There was an error sending your request. Please try again later.</p>";
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT DISTINCT tilde_name FROM phonebook ORDER BY tilde_name";
|
||||
$result = $conn->query($sql);
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<link rel="icon" href="https://tilde.tel/logo-300.png">
|
||||
<style>
|
||||
@font-face {
|
||||
font-family: 'DejaVu Sans';
|
||||
src: url('/https://tilde.tel/fonts/dejavu-sans-webfont.eot');
|
||||
src: url('/https://tilde.tel/fonts/dejavu-sans-webfont.eot#iefix') format('embedded-opentype'),
|
||||
url('/https://tilde.tel/fonts/dejavu-sans-webfont.woff2') format('woff2'),
|
||||
url('/https://tilde.tel/fonts/dejavu-sans-webfont.woff') format('woff'),
|
||||
url('/https://tilde.tel/fonts/dejavu-sans-webfont.ttf') format('truetype'),
|
||||
url('/https://tilde.tel/fonts/dejavu-sans-webfont.svg#dejavu_sansregular') format('svg');
|
||||
}
|
||||
html {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: #f0f0f0;
|
||||
}
|
||||
.splash {
|
||||
position: absolute;
|
||||
width: 400px;
|
||||
height: 400px;
|
||||
top: 38%;
|
||||
left: 50%;
|
||||
margin: -150px 0 0 -200px;
|
||||
font-family: 'DejaVu Sans', sans-serif;
|
||||
text-align: center;
|
||||
}
|
||||
.slogan {
|
||||
font-weight: bold;
|
||||
font-size: 30px;
|
||||
color: #ffa633;
|
||||
font-family: 'DejaVu Sans', sans-serif;
|
||||
text-align: center;
|
||||
}
|
||||
.banner {
|
||||
position: absolute;
|
||||
bottom: 10px;
|
||||
width: 468px;
|
||||
left: 50%;
|
||||
right: 50%;
|
||||
margin: 0px 0px 0px -234px;
|
||||
border: 4px solid #cacaca;
|
||||
background-color: #cacaca;
|
||||
font-family: 'DejaVu Sans', sans-serif;
|
||||
font-size: 9px;
|
||||
color: #f0f0f0;
|
||||
}
|
||||
.info {
|
||||
font-weight: bold;
|
||||
font-size: 17px;
|
||||
color: #FFA633;
|
||||
}
|
||||
.column {
|
||||
float: left;
|
||||
}
|
||||
.left {
|
||||
width: 111px;
|
||||
text-align: center;
|
||||
}
|
||||
.right {
|
||||
width: 639px;
|
||||
text-align: left;
|
||||
position: relative;
|
||||
}
|
||||
.form-container {
|
||||
margin: 20px auto;
|
||||
width: 70%;
|
||||
background-color: #ffffff;
|
||||
border: 2px solid #ffa633;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||
font-family: 'DejaVu Sans', sans-serif;
|
||||
color: #333333;
|
||||
}
|
||||
.form-container label {
|
||||
font-weight: bold;
|
||||
font-size: 16px;
|
||||
color: #333333;
|
||||
display: block;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
.form-container input[type="text"],
|
||||
.form-container input[type="email"],
|
||||
.form-container select {
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
margin-bottom: 15px;
|
||||
border: 1px solid #cccccc;
|
||||
border-radius: 5px;
|
||||
font-size: 14px;
|
||||
font-family: 'DejaVu Sans', sans-serif;
|
||||
}
|
||||
.form-container input[type="submit"] {
|
||||
background-color: #ffa633;
|
||||
color: #ffffff;
|
||||
padding: 10px 20px;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
font-size: 16px;
|
||||
font-family: 'DejaVu Sans', sans-serif;
|
||||
}
|
||||
.form-container input[type="submit"]:hover {
|
||||
background-color: #e69530;
|
||||
}
|
||||
.success-message {
|
||||
margin: 20px auto;
|
||||
width: 70%;
|
||||
background-color: #dff0d8;
|
||||
border: 2px solid #d6e9c6;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||
font-family: 'DejaVu Sans', sans-serif;
|
||||
color: #3c763d;
|
||||
font-size: 18px;
|
||||
text-align: center;
|
||||
}
|
||||
.note {
|
||||
font-size: 14px;
|
||||
color: #777;
|
||||
margin-top: 10px;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
<title>~tel | Sign Up</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="row">
|
||||
<div class="column left">
|
||||
<a href="https://tilde.tel/"><img src="https://tilde.tel/logo-300.png" height="66px" width="66px" alt="tilde.tel logo"></a><br/>
|
||||
<br/>
|
||||
<br/>
|
||||
<a href="https://tilde.tel/faq.html"><img src="https://tilde.tel/faq-off.png" height="44px" width="44px" alt="FAQ"></a><br/>
|
||||
<br/>
|
||||
<br/>
|
||||
<a href="https://tilde.tel/phonebook.php"><img src="https://tilde.tel/phonebook-off.png" height="44px" width="44px" alt="Phonebook"></a><br/>
|
||||
<br/>
|
||||
<a href="https://connect.tilde.tel/ucp" target="_blank"><img src="https://tilde.tel/settings-off.png" height="44px" width="44px" alt="User Control Panel"></a>
|
||||
<br/>
|
||||
<br/>
|
||||
<a href="https://tilde.tel/signup"><img src="https://tilde.tel/signup-on.png" height="44px" width="44px" alt="Sign up"></a><br/>
|
||||
</div>
|
||||
<div class="column right">
|
||||
<div class="slogan">
|
||||
Sign up
|
||||
</div>
|
||||
<pre>
|
||||
Welcome to tilde.tel, excited to have you as a member!
|
||||
|
||||
**See FAQ if you're unsure if you qualify to have an account**
|
||||
|
||||
**If you were a previous tilde.tel user you can let us know if you would like your old extension.**
|
||||
|
||||
</pre>
|
||||
|
||||
<?php if ($formSubmitted): ?>
|
||||
<!-- Show success message -->
|
||||
<div class="success-message">
|
||||
<p>Thank you for signing up! We will get back to you shortly.</p>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<!-- Signup form -->
|
||||
<div class="form-container">
|
||||
<form action="" method="POST">
|
||||
<label for="tilde">Tilde you're a member of:</label>
|
||||
<select id="tilde" name="tilde" onchange="this.form.submit()" required>
|
||||
<option value="" disabled selected>Select your Tilde</option>
|
||||
<?php
|
||||
if ($result->num_rows > 0) {
|
||||
while($row = $result->fetch_assoc()) {
|
||||
$selected = ($row['tilde_name'] == $selectedTilde) ? 'selected' : '';
|
||||
echo "<option value='{$row['tilde_name']}' $selected>{$row['tilde_name']}</option>";
|
||||
}
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
|
||||
<?php if (!empty($nextExtension)) : ?>
|
||||
<p>Next available extension: <strong><?= $nextExtension ?></strong></p>
|
||||
<input type="hidden" name="extension" value="<?= $nextExtension ?>">
|
||||
<?php endif; ?>
|
||||
|
||||
<label for="email">Email:</label>
|
||||
<input type="email" id="email" name="email" required>
|
||||
|
||||
<label for="username">Tilde Username:</label>
|
||||
<input type="text" id="username" name="username" required>
|
||||
|
||||
<?php if (!isset($_POST['tilde'])): ?>
|
||||
<input type="submit" value="Continue">
|
||||
<?php else: ?>
|
||||
<input type="submit" value="Sign Up">
|
||||
<?php endif; ?>
|
||||
</form>
|
||||
<p class="note">If your Tilde is not listed, please email the admin at <a href="mailto:deepend@tilde.tel">deepend@tilde.tel</a>.</p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<?php $conn->close(); ?>
|
Binary file not shown.
After Width: | Height: | Size: 31 KiB |
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
// autoload.php @generated by Composer
|
||||
|
||||
if (PHP_VERSION_ID < 50600) {
|
||||
if (!headers_sent()) {
|
||||
header('HTTP/1.1 500 Internal Server Error');
|
||||
}
|
||||
$err = 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL;
|
||||
if (!ini_get('display_errors')) {
|
||||
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
|
||||
fwrite(STDERR, $err);
|
||||
} elseif (!headers_sent()) {
|
||||
echo $err;
|
||||
}
|
||||
}
|
||||
trigger_error(
|
||||
$err,
|
||||
E_USER_ERROR
|
||||
);
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInite875ae8441d070d7dda5f4b47a2117aa::getLoader();
|
|
@ -0,0 +1,579 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Composer.
|
||||
*
|
||||
* (c) Nils Adermann <naderman@naderman.de>
|
||||
* Jordi Boggiano <j.boggiano@seld.be>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
/**
|
||||
* ClassLoader implements a PSR-0, PSR-4 and classmap class loader.
|
||||
*
|
||||
* $loader = new \Composer\Autoload\ClassLoader();
|
||||
*
|
||||
* // register classes with namespaces
|
||||
* $loader->add('Symfony\Component', __DIR__.'/component');
|
||||
* $loader->add('Symfony', __DIR__.'/framework');
|
||||
*
|
||||
* // activate the autoloader
|
||||
* $loader->register();
|
||||
*
|
||||
* // to enable searching the include path (eg. for PEAR packages)
|
||||
* $loader->setUseIncludePath(true);
|
||||
*
|
||||
* In this example, if you try to use a class in the Symfony\Component
|
||||
* namespace or one of its children (Symfony\Component\Console for instance),
|
||||
* the autoloader will first look for the class under the component/
|
||||
* directory, and it will then fallback to the framework/ directory if not
|
||||
* found before giving up.
|
||||
*
|
||||
* This class is loosely based on the Symfony UniversalClassLoader.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @see https://www.php-fig.org/psr/psr-0/
|
||||
* @see https://www.php-fig.org/psr/psr-4/
|
||||
*/
|
||||
class ClassLoader
|
||||
{
|
||||
/** @var \Closure(string):void */
|
||||
private static $includeFile;
|
||||
|
||||
/** @var string|null */
|
||||
private $vendorDir;
|
||||
|
||||
// PSR-4
|
||||
/**
|
||||
* @var array<string, array<string, int>>
|
||||
*/
|
||||
private $prefixLengthsPsr4 = array();
|
||||
/**
|
||||
* @var array<string, list<string>>
|
||||
*/
|
||||
private $prefixDirsPsr4 = array();
|
||||
/**
|
||||
* @var list<string>
|
||||
*/
|
||||
private $fallbackDirsPsr4 = array();
|
||||
|
||||
// PSR-0
|
||||
/**
|
||||
* List of PSR-0 prefixes
|
||||
*
|
||||
* Structured as array('F (first letter)' => array('Foo\Bar (full prefix)' => array('path', 'path2')))
|
||||
*
|
||||
* @var array<string, array<string, list<string>>>
|
||||
*/
|
||||
private $prefixesPsr0 = array();
|
||||
/**
|
||||
* @var list<string>
|
||||
*/
|
||||
private $fallbackDirsPsr0 = array();
|
||||
|
||||
/** @var bool */
|
||||
private $useIncludePath = false;
|
||||
|
||||
/**
|
||||
* @var array<string, string>
|
||||
*/
|
||||
private $classMap = array();
|
||||
|
||||
/** @var bool */
|
||||
private $classMapAuthoritative = false;
|
||||
|
||||
/**
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
private $missingClasses = array();
|
||||
|
||||
/** @var string|null */
|
||||
private $apcuPrefix;
|
||||
|
||||
/**
|
||||
* @var array<string, self>
|
||||
*/
|
||||
private static $registeredLoaders = array();
|
||||
|
||||
/**
|
||||
* @param string|null $vendorDir
|
||||
*/
|
||||
public function __construct($vendorDir = null)
|
||||
{
|
||||
$this->vendorDir = $vendorDir;
|
||||
self::initializeIncludeClosure();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, list<string>>
|
||||
*/
|
||||
public function getPrefixes()
|
||||
{
|
||||
if (!empty($this->prefixesPsr0)) {
|
||||
return call_user_func_array('array_merge', array_values($this->prefixesPsr0));
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, list<string>>
|
||||
*/
|
||||
public function getPrefixesPsr4()
|
||||
{
|
||||
return $this->prefixDirsPsr4;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
public function getFallbackDirs()
|
||||
{
|
||||
return $this->fallbackDirsPsr0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
public function getFallbackDirsPsr4()
|
||||
{
|
||||
return $this->fallbackDirsPsr4;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string> Array of classname => path
|
||||
*/
|
||||
public function getClassMap()
|
||||
{
|
||||
return $this->classMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, string> $classMap Class to filename map
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addClassMap(array $classMap)
|
||||
{
|
||||
if ($this->classMap) {
|
||||
$this->classMap = array_merge($this->classMap, $classMap);
|
||||
} else {
|
||||
$this->classMap = $classMap;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of PSR-0 directories for a given prefix, either
|
||||
* appending or prepending to the ones previously set for this prefix.
|
||||
*
|
||||
* @param string $prefix The prefix
|
||||
* @param list<string>|string $paths The PSR-0 root directories
|
||||
* @param bool $prepend Whether to prepend the directories
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function add($prefix, $paths, $prepend = false)
|
||||
{
|
||||
$paths = (array) $paths;
|
||||
if (!$prefix) {
|
||||
if ($prepend) {
|
||||
$this->fallbackDirsPsr0 = array_merge(
|
||||
$paths,
|
||||
$this->fallbackDirsPsr0
|
||||
);
|
||||
} else {
|
||||
$this->fallbackDirsPsr0 = array_merge(
|
||||
$this->fallbackDirsPsr0,
|
||||
$paths
|
||||
);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$first = $prefix[0];
|
||||
if (!isset($this->prefixesPsr0[$first][$prefix])) {
|
||||
$this->prefixesPsr0[$first][$prefix] = $paths;
|
||||
|
||||
return;
|
||||
}
|
||||
if ($prepend) {
|
||||
$this->prefixesPsr0[$first][$prefix] = array_merge(
|
||||
$paths,
|
||||
$this->prefixesPsr0[$first][$prefix]
|
||||
);
|
||||
} else {
|
||||
$this->prefixesPsr0[$first][$prefix] = array_merge(
|
||||
$this->prefixesPsr0[$first][$prefix],
|
||||
$paths
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of PSR-4 directories for a given namespace, either
|
||||
* appending or prepending to the ones previously set for this namespace.
|
||||
*
|
||||
* @param string $prefix The prefix/namespace, with trailing '\\'
|
||||
* @param list<string>|string $paths The PSR-4 base directories
|
||||
* @param bool $prepend Whether to prepend the directories
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addPsr4($prefix, $paths, $prepend = false)
|
||||
{
|
||||
$paths = (array) $paths;
|
||||
if (!$prefix) {
|
||||
// Register directories for the root namespace.
|
||||
if ($prepend) {
|
||||
$this->fallbackDirsPsr4 = array_merge(
|
||||
$paths,
|
||||
$this->fallbackDirsPsr4
|
||||
);
|
||||
} else {
|
||||
$this->fallbackDirsPsr4 = array_merge(
|
||||
$this->fallbackDirsPsr4,
|
||||
$paths
|
||||
);
|
||||
}
|
||||
} elseif (!isset($this->prefixDirsPsr4[$prefix])) {
|
||||
// Register directories for a new namespace.
|
||||
$length = strlen($prefix);
|
||||
if ('\\' !== $prefix[$length - 1]) {
|
||||
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
|
||||
}
|
||||
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
|
||||
$this->prefixDirsPsr4[$prefix] = $paths;
|
||||
} elseif ($prepend) {
|
||||
// Prepend directories for an already registered namespace.
|
||||
$this->prefixDirsPsr4[$prefix] = array_merge(
|
||||
$paths,
|
||||
$this->prefixDirsPsr4[$prefix]
|
||||
);
|
||||
} else {
|
||||
// Append directories for an already registered namespace.
|
||||
$this->prefixDirsPsr4[$prefix] = array_merge(
|
||||
$this->prefixDirsPsr4[$prefix],
|
||||
$paths
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of PSR-0 directories for a given prefix,
|
||||
* replacing any others previously set for this prefix.
|
||||
*
|
||||
* @param string $prefix The prefix
|
||||
* @param list<string>|string $paths The PSR-0 base directories
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function set($prefix, $paths)
|
||||
{
|
||||
if (!$prefix) {
|
||||
$this->fallbackDirsPsr0 = (array) $paths;
|
||||
} else {
|
||||
$this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of PSR-4 directories for a given namespace,
|
||||
* replacing any others previously set for this namespace.
|
||||
*
|
||||
* @param string $prefix The prefix/namespace, with trailing '\\'
|
||||
* @param list<string>|string $paths The PSR-4 base directories
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setPsr4($prefix, $paths)
|
||||
{
|
||||
if (!$prefix) {
|
||||
$this->fallbackDirsPsr4 = (array) $paths;
|
||||
} else {
|
||||
$length = strlen($prefix);
|
||||
if ('\\' !== $prefix[$length - 1]) {
|
||||
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
|
||||
}
|
||||
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
|
||||
$this->prefixDirsPsr4[$prefix] = (array) $paths;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns on searching the include path for class files.
|
||||
*
|
||||
* @param bool $useIncludePath
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUseIncludePath($useIncludePath)
|
||||
{
|
||||
$this->useIncludePath = $useIncludePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be used to check if the autoloader uses the include path to check
|
||||
* for classes.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getUseIncludePath()
|
||||
{
|
||||
return $this->useIncludePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns off searching the prefix and fallback directories for classes
|
||||
* that have not been registered with the class map.
|
||||
*
|
||||
* @param bool $classMapAuthoritative
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setClassMapAuthoritative($classMapAuthoritative)
|
||||
{
|
||||
$this->classMapAuthoritative = $classMapAuthoritative;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should class lookup fail if not found in the current class map?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isClassMapAuthoritative()
|
||||
{
|
||||
return $this->classMapAuthoritative;
|
||||
}
|
||||
|
||||
/**
|
||||
* APCu prefix to use to cache found/not-found classes, if the extension is enabled.
|
||||
*
|
||||
* @param string|null $apcuPrefix
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setApcuPrefix($apcuPrefix)
|
||||
{
|
||||
$this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The APCu prefix in use, or null if APCu caching is not enabled.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getApcuPrefix()
|
||||
{
|
||||
return $this->apcuPrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers this instance as an autoloader.
|
||||
*
|
||||
* @param bool $prepend Whether to prepend the autoloader or not
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register($prepend = false)
|
||||
{
|
||||
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
|
||||
|
||||
if (null === $this->vendorDir) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($prepend) {
|
||||
self::$registeredLoaders = array($this->vendorDir => $this) + self::$registeredLoaders;
|
||||
} else {
|
||||
unset(self::$registeredLoaders[$this->vendorDir]);
|
||||
self::$registeredLoaders[$this->vendorDir] = $this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters this instance as an autoloader.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unregister()
|
||||
{
|
||||
spl_autoload_unregister(array($this, 'loadClass'));
|
||||
|
||||
if (null !== $this->vendorDir) {
|
||||
unset(self::$registeredLoaders[$this->vendorDir]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the given class or interface.
|
||||
*
|
||||
* @param string $class The name of the class
|
||||
* @return true|null True if loaded, null otherwise
|
||||
*/
|
||||
public function loadClass($class)
|
||||
{
|
||||
if ($file = $this->findFile($class)) {
|
||||
$includeFile = self::$includeFile;
|
||||
$includeFile($file);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the path to the file where the class is defined.
|
||||
*
|
||||
* @param string $class The name of the class
|
||||
*
|
||||
* @return string|false The path if found, false otherwise
|
||||
*/
|
||||
public function findFile($class)
|
||||
{
|
||||
// class map lookup
|
||||
if (isset($this->classMap[$class])) {
|
||||
return $this->classMap[$class];
|
||||
}
|
||||
if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
|
||||
return false;
|
||||
}
|
||||
if (null !== $this->apcuPrefix) {
|
||||
$file = apcu_fetch($this->apcuPrefix.$class, $hit);
|
||||
if ($hit) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
||||
$file = $this->findFileWithExtension($class, '.php');
|
||||
|
||||
// Search for Hack files if we are running on HHVM
|
||||
if (false === $file && defined('HHVM_VERSION')) {
|
||||
$file = $this->findFileWithExtension($class, '.hh');
|
||||
}
|
||||
|
||||
if (null !== $this->apcuPrefix) {
|
||||
apcu_add($this->apcuPrefix.$class, $file);
|
||||
}
|
||||
|
||||
if (false === $file) {
|
||||
// Remember that this class does not exist.
|
||||
$this->missingClasses[$class] = true;
|
||||
}
|
||||
|
||||
return $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the currently registered loaders keyed by their corresponding vendor directories.
|
||||
*
|
||||
* @return array<string, self>
|
||||
*/
|
||||
public static function getRegisteredLoaders()
|
||||
{
|
||||
return self::$registeredLoaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $class
|
||||
* @param string $ext
|
||||
* @return string|false
|
||||
*/
|
||||
private function findFileWithExtension($class, $ext)
|
||||
{
|
||||
// PSR-4 lookup
|
||||
$logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
|
||||
|
||||
$first = $class[0];
|
||||
if (isset($this->prefixLengthsPsr4[$first])) {
|
||||
$subPath = $class;
|
||||
while (false !== $lastPos = strrpos($subPath, '\\')) {
|
||||
$subPath = substr($subPath, 0, $lastPos);
|
||||
$search = $subPath . '\\';
|
||||
if (isset($this->prefixDirsPsr4[$search])) {
|
||||
$pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
|
||||
foreach ($this->prefixDirsPsr4[$search] as $dir) {
|
||||
if (file_exists($file = $dir . $pathEnd)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// PSR-4 fallback dirs
|
||||
foreach ($this->fallbackDirsPsr4 as $dir) {
|
||||
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
||||
// PSR-0 lookup
|
||||
if (false !== $pos = strrpos($class, '\\')) {
|
||||
// namespaced class name
|
||||
$logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
|
||||
. strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
|
||||
} else {
|
||||
// PEAR-like class name
|
||||
$logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
|
||||
}
|
||||
|
||||
if (isset($this->prefixesPsr0[$first])) {
|
||||
foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
|
||||
if (0 === strpos($class, $prefix)) {
|
||||
foreach ($dirs as $dir) {
|
||||
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// PSR-0 fallback dirs
|
||||
foreach ($this->fallbackDirsPsr0 as $dir) {
|
||||
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
||||
// PSR-0 include paths.
|
||||
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
|
||||
return $file;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private static function initializeIncludeClosure()
|
||||
{
|
||||
if (self::$includeFile !== null) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope isolated include.
|
||||
*
|
||||
* Prevents access to $this/self from included files.
|
||||
*
|
||||
* @param string $file
|
||||
* @return void
|
||||
*/
|
||||
self::$includeFile = \Closure::bind(static function($file) {
|
||||
include $file;
|
||||
}, null, null);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,359 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Composer.
|
||||
*
|
||||
* (c) Nils Adermann <naderman@naderman.de>
|
||||
* Jordi Boggiano <j.boggiano@seld.be>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Composer;
|
||||
|
||||
use Composer\Autoload\ClassLoader;
|
||||
use Composer\Semver\VersionParser;
|
||||
|
||||
/**
|
||||
* This class is copied in every Composer installed project and available to all
|
||||
*
|
||||
* See also https://getcomposer.org/doc/07-runtime.md#installed-versions
|
||||
*
|
||||
* To require its presence, you can require `composer-runtime-api ^2.0`
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class InstalledVersions
|
||||
{
|
||||
/**
|
||||
* @var mixed[]|null
|
||||
* @psalm-var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}|array{}|null
|
||||
*/
|
||||
private static $installed;
|
||||
|
||||
/**
|
||||
* @var bool|null
|
||||
*/
|
||||
private static $canGetVendors;
|
||||
|
||||
/**
|
||||
* @var array[]
|
||||
* @psalm-var array<string, array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>
|
||||
*/
|
||||
private static $installedByVendor = array();
|
||||
|
||||
/**
|
||||
* Returns a list of all package names which are present, either by being installed, replaced or provided
|
||||
*
|
||||
* @return string[]
|
||||
* @psalm-return list<string>
|
||||
*/
|
||||
public static function getInstalledPackages()
|
||||
{
|
||||
$packages = array();
|
||||
foreach (self::getInstalled() as $installed) {
|
||||
$packages[] = array_keys($installed['versions']);
|
||||
}
|
||||
|
||||
if (1 === \count($packages)) {
|
||||
return $packages[0];
|
||||
}
|
||||
|
||||
return array_keys(array_flip(\call_user_func_array('array_merge', $packages)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all package names with a specific type e.g. 'library'
|
||||
*
|
||||
* @param string $type
|
||||
* @return string[]
|
||||
* @psalm-return list<string>
|
||||
*/
|
||||
public static function getInstalledPackagesByType($type)
|
||||
{
|
||||
$packagesByType = array();
|
||||
|
||||
foreach (self::getInstalled() as $installed) {
|
||||
foreach ($installed['versions'] as $name => $package) {
|
||||
if (isset($package['type']) && $package['type'] === $type) {
|
||||
$packagesByType[] = $name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $packagesByType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given package is installed
|
||||
*
|
||||
* This also returns true if the package name is provided or replaced by another package
|
||||
*
|
||||
* @param string $packageName
|
||||
* @param bool $includeDevRequirements
|
||||
* @return bool
|
||||
*/
|
||||
public static function isInstalled($packageName, $includeDevRequirements = true)
|
||||
{
|
||||
foreach (self::getInstalled() as $installed) {
|
||||
if (isset($installed['versions'][$packageName])) {
|
||||
return $includeDevRequirements || !isset($installed['versions'][$packageName]['dev_requirement']) || $installed['versions'][$packageName]['dev_requirement'] === false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given package satisfies a version constraint
|
||||
*
|
||||
* e.g. If you want to know whether version 2.3+ of package foo/bar is installed, you would call:
|
||||
*
|
||||
* Composer\InstalledVersions::satisfies(new VersionParser, 'foo/bar', '^2.3')
|
||||
*
|
||||
* @param VersionParser $parser Install composer/semver to have access to this class and functionality
|
||||
* @param string $packageName
|
||||
* @param string|null $constraint A version constraint to check for, if you pass one you have to make sure composer/semver is required by your package
|
||||
* @return bool
|
||||
*/
|
||||
public static function satisfies(VersionParser $parser, $packageName, $constraint)
|
||||
{
|
||||
$constraint = $parser->parseConstraints((string) $constraint);
|
||||
$provided = $parser->parseConstraints(self::getVersionRanges($packageName));
|
||||
|
||||
return $provided->matches($constraint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a version constraint representing all the range(s) which are installed for a given package
|
||||
*
|
||||
* It is easier to use this via isInstalled() with the $constraint argument if you need to check
|
||||
* whether a given version of a package is installed, and not just whether it exists
|
||||
*
|
||||
* @param string $packageName
|
||||
* @return string Version constraint usable with composer/semver
|
||||
*/
|
||||
public static function getVersionRanges($packageName)
|
||||
{
|
||||
foreach (self::getInstalled() as $installed) {
|
||||
if (!isset($installed['versions'][$packageName])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$ranges = array();
|
||||
if (isset($installed['versions'][$packageName]['pretty_version'])) {
|
||||
$ranges[] = $installed['versions'][$packageName]['pretty_version'];
|
||||
}
|
||||
if (array_key_exists('aliases', $installed['versions'][$packageName])) {
|
||||
$ranges = array_merge($ranges, $installed['versions'][$packageName]['aliases']);
|
||||
}
|
||||
if (array_key_exists('replaced', $installed['versions'][$packageName])) {
|
||||
$ranges = array_merge($ranges, $installed['versions'][$packageName]['replaced']);
|
||||
}
|
||||
if (array_key_exists('provided', $installed['versions'][$packageName])) {
|
||||
$ranges = array_merge($ranges, $installed['versions'][$packageName]['provided']);
|
||||
}
|
||||
|
||||
return implode(' || ', $ranges);
|
||||
}
|
||||
|
||||
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $packageName
|
||||
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present
|
||||
*/
|
||||
public static function getVersion($packageName)
|
||||
{
|
||||
foreach (self::getInstalled() as $installed) {
|
||||
if (!isset($installed['versions'][$packageName])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isset($installed['versions'][$packageName]['version'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $installed['versions'][$packageName]['version'];
|
||||
}
|
||||
|
||||
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $packageName
|
||||
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present
|
||||
*/
|
||||
public static function getPrettyVersion($packageName)
|
||||
{
|
||||
foreach (self::getInstalled() as $installed) {
|
||||
if (!isset($installed['versions'][$packageName])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isset($installed['versions'][$packageName]['pretty_version'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $installed['versions'][$packageName]['pretty_version'];
|
||||
}
|
||||
|
||||
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $packageName
|
||||
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as reference
|
||||
*/
|
||||
public static function getReference($packageName)
|
||||
{
|
||||
foreach (self::getInstalled() as $installed) {
|
||||
if (!isset($installed['versions'][$packageName])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isset($installed['versions'][$packageName]['reference'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $installed['versions'][$packageName]['reference'];
|
||||
}
|
||||
|
||||
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $packageName
|
||||
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as install path. Packages of type metapackages also have a null install path.
|
||||
*/
|
||||
public static function getInstallPath($packageName)
|
||||
{
|
||||
foreach (self::getInstalled() as $installed) {
|
||||
if (!isset($installed['versions'][$packageName])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return isset($installed['versions'][$packageName]['install_path']) ? $installed['versions'][$packageName]['install_path'] : null;
|
||||
}
|
||||
|
||||
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @psalm-return array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}
|
||||
*/
|
||||
public static function getRootPackage()
|
||||
{
|
||||
$installed = self::getInstalled();
|
||||
|
||||
return $installed[0]['root'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the raw installed.php data for custom implementations
|
||||
*
|
||||
* @deprecated Use getAllRawData() instead which returns all datasets for all autoloaders present in the process. getRawData only returns the first dataset loaded, which may not be what you expect.
|
||||
* @return array[]
|
||||
* @psalm-return array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}
|
||||
*/
|
||||
public static function getRawData()
|
||||
{
|
||||
@trigger_error('getRawData only returns the first dataset loaded, which may not be what you expect. Use getAllRawData() instead which returns all datasets for all autoloaders present in the process.', E_USER_DEPRECATED);
|
||||
|
||||
if (null === self::$installed) {
|
||||
// only require the installed.php file if this file is loaded from its dumped location,
|
||||
// and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
|
||||
if (substr(__DIR__, -8, 1) !== 'C') {
|
||||
self::$installed = include __DIR__ . '/installed.php';
|
||||
} else {
|
||||
self::$installed = array();
|
||||
}
|
||||
}
|
||||
|
||||
return self::$installed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the raw data of all installed.php which are currently loaded for custom implementations
|
||||
*
|
||||
* @return array[]
|
||||
* @psalm-return list<array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>
|
||||
*/
|
||||
public static function getAllRawData()
|
||||
{
|
||||
return self::getInstalled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Lets you reload the static array from another file
|
||||
*
|
||||
* This is only useful for complex integrations in which a project needs to use
|
||||
* this class but then also needs to execute another project's autoloader in process,
|
||||
* and wants to ensure both projects have access to their version of installed.php.
|
||||
*
|
||||
* A typical case would be PHPUnit, where it would need to make sure it reads all
|
||||
* the data it needs from this class, then call reload() with
|
||||
* `require $CWD/vendor/composer/installed.php` (or similar) as input to make sure
|
||||
* the project in which it runs can then also use this class safely, without
|
||||
* interference between PHPUnit's dependencies and the project's dependencies.
|
||||
*
|
||||
* @param array[] $data A vendor/composer/installed.php data set
|
||||
* @return void
|
||||
*
|
||||
* @psalm-param array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $data
|
||||
*/
|
||||
public static function reload($data)
|
||||
{
|
||||
self::$installed = $data;
|
||||
self::$installedByVendor = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
* @psalm-return list<array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>
|
||||
*/
|
||||
private static function getInstalled()
|
||||
{
|
||||
if (null === self::$canGetVendors) {
|
||||
self::$canGetVendors = method_exists('Composer\Autoload\ClassLoader', 'getRegisteredLoaders');
|
||||
}
|
||||
|
||||
$installed = array();
|
||||
|
||||
if (self::$canGetVendors) {
|
||||
foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) {
|
||||
if (isset(self::$installedByVendor[$vendorDir])) {
|
||||
$installed[] = self::$installedByVendor[$vendorDir];
|
||||
} elseif (is_file($vendorDir.'/composer/installed.php')) {
|
||||
/** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
|
||||
$required = require $vendorDir.'/composer/installed.php';
|
||||
$installed[] = self::$installedByVendor[$vendorDir] = $required;
|
||||
if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) {
|
||||
self::$installed = $installed[count($installed) - 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (null === self::$installed) {
|
||||
// only require the installed.php file if this file is loaded from its dumped location,
|
||||
// and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
|
||||
if (substr(__DIR__, -8, 1) !== 'C') {
|
||||
/** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
|
||||
$required = require __DIR__ . '/installed.php';
|
||||
self::$installed = $required;
|
||||
} else {
|
||||
self::$installed = array();
|
||||
}
|
||||
}
|
||||
|
||||
if (self::$installed !== array()) {
|
||||
$installed[] = self::$installed;
|
||||
}
|
||||
|
||||
return $installed;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
|
||||
Copyright (c) Nils Adermann, Jordi Boggiano
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
// autoload_classmap.php @generated by Composer
|
||||
|
||||
$vendorDir = dirname(__DIR__);
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
'Attribute' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/Attribute.php',
|
||||
'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
|
||||
'PhpToken' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/PhpToken.php',
|
||||
'Stringable' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/Stringable.php',
|
||||
'UnhandledMatchError' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/UnhandledMatchError.php',
|
||||
'ValueError' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/ValueError.php',
|
||||
);
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
// autoload_files.php @generated by Composer
|
||||
|
||||
$vendorDir = dirname(__DIR__);
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
'320cde22f66dd4f5d3fd621d3e88b98f' => $vendorDir . '/symfony/polyfill-ctype/bootstrap.php',
|
||||
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => $vendorDir . '/symfony/polyfill-mbstring/bootstrap.php',
|
||||
'a4a119a56e50fbb293281d9a48007e0e' => $vendorDir . '/symfony/polyfill-php80/bootstrap.php',
|
||||
);
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
// autoload_namespaces.php @generated by Composer
|
||||
|
||||
$vendorDir = dirname(__DIR__);
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
);
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
// autoload_psr4.php @generated by Composer
|
||||
|
||||
$vendorDir = dirname(__DIR__);
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
'Symfony\\Polyfill\\Php80\\' => array($vendorDir . '/symfony/polyfill-php80'),
|
||||
'Symfony\\Polyfill\\Mbstring\\' => array($vendorDir . '/symfony/polyfill-mbstring'),
|
||||
'Symfony\\Polyfill\\Ctype\\' => array($vendorDir . '/symfony/polyfill-ctype'),
|
||||
'PhpOption\\' => array($vendorDir . '/phpoption/phpoption/src/PhpOption'),
|
||||
'GrahamCampbell\\ResultType\\' => array($vendorDir . '/graham-campbell/result-type/src'),
|
||||
'Dotenv\\' => array($vendorDir . '/vlucas/phpdotenv/src'),
|
||||
);
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInite875ae8441d070d7dda5f4b47a2117aa
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
public static function loadClassLoader($class)
|
||||
{
|
||||
if ('Composer\Autoload\ClassLoader' === $class) {
|
||||
require __DIR__ . '/ClassLoader.php';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Composer\Autoload\ClassLoader
|
||||
*/
|
||||
public static function getLoader()
|
||||
{
|
||||
if (null !== self::$loader) {
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
require __DIR__ . '/platform_check.php';
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInite875ae8441d070d7dda5f4b47a2117aa', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInite875ae8441d070d7dda5f4b47a2117aa', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInite875ae8441d070d7dda5f4b47a2117aa::getInitializer($loader));
|
||||
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInite875ae8441d070d7dda5f4b47a2117aa::$files;
|
||||
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
||||
require $file;
|
||||
}
|
||||
}, null, null);
|
||||
foreach ($filesToLoad as $fileIdentifier => $file) {
|
||||
$requireFile($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
|
||||
// autoload_static.php @generated by Composer
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInite875ae8441d070d7dda5f4b47a2117aa
|
||||
{
|
||||
public static $files = array (
|
||||
'320cde22f66dd4f5d3fd621d3e88b98f' => __DIR__ . '/..' . '/symfony/polyfill-ctype/bootstrap.php',
|
||||
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
|
||||
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
|
||||
);
|
||||
|
||||
public static $prefixLengthsPsr4 = array (
|
||||
'S' =>
|
||||
array (
|
||||
'Symfony\\Polyfill\\Php80\\' => 23,
|
||||
'Symfony\\Polyfill\\Mbstring\\' => 26,
|
||||
'Symfony\\Polyfill\\Ctype\\' => 23,
|
||||
),
|
||||
'P' =>
|
||||
array (
|
||||
'PhpOption\\' => 10,
|
||||
),
|
||||
'G' =>
|
||||
array (
|
||||
'GrahamCampbell\\ResultType\\' => 26,
|
||||
),
|
||||
'D' =>
|
||||
array (
|
||||
'Dotenv\\' => 7,
|
||||
),
|
||||
);
|
||||
|
||||
public static $prefixDirsPsr4 = array (
|
||||
'Symfony\\Polyfill\\Php80\\' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/symfony/polyfill-php80',
|
||||
),
|
||||
'Symfony\\Polyfill\\Mbstring\\' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/symfony/polyfill-mbstring',
|
||||
),
|
||||
'Symfony\\Polyfill\\Ctype\\' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/symfony/polyfill-ctype',
|
||||
),
|
||||
'PhpOption\\' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/phpoption/phpoption/src/PhpOption',
|
||||
),
|
||||
'GrahamCampbell\\ResultType\\' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/graham-campbell/result-type/src',
|
||||
),
|
||||
'Dotenv\\' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/vlucas/phpdotenv/src',
|
||||
),
|
||||
);
|
||||
|
||||
public static $classMap = array (
|
||||
'Attribute' => __DIR__ . '/..' . '/symfony/polyfill-php80/Resources/stubs/Attribute.php',
|
||||
'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
|
||||
'PhpToken' => __DIR__ . '/..' . '/symfony/polyfill-php80/Resources/stubs/PhpToken.php',
|
||||
'Stringable' => __DIR__ . '/..' . '/symfony/polyfill-php80/Resources/stubs/Stringable.php',
|
||||
'UnhandledMatchError' => __DIR__ . '/..' . '/symfony/polyfill-php80/Resources/stubs/UnhandledMatchError.php',
|
||||
'ValueError' => __DIR__ . '/..' . '/symfony/polyfill-php80/Resources/stubs/ValueError.php',
|
||||
);
|
||||
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInite875ae8441d070d7dda5f4b47a2117aa::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInite875ae8441d070d7dda5f4b47a2117aa::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInite875ae8441d070d7dda5f4b47a2117aa::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,484 @@
|
|||
{
|
||||
"packages": [
|
||||
{
|
||||
"name": "graham-campbell/result-type",
|
||||
"version": "v1.1.3",
|
||||
"version_normalized": "1.1.3.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/GrahamCampbell/Result-Type.git",
|
||||
"reference": "3ba905c11371512af9d9bdd27d99b782216b6945"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/GrahamCampbell/Result-Type/zipball/3ba905c11371512af9d9bdd27d99b782216b6945",
|
||||
"reference": "3ba905c11371512af9d9bdd27d99b782216b6945",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.2.5 || ^8.0",
|
||||
"phpoption/phpoption": "^1.9.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^8.5.39 || ^9.6.20 || ^10.5.28"
|
||||
},
|
||||
"time": "2024-07-20T21:45:45+00:00",
|
||||
"type": "library",
|
||||
"installation-source": "dist",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"GrahamCampbell\\ResultType\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Graham Campbell",
|
||||
"email": "hello@gjcampbell.co.uk",
|
||||
"homepage": "https://github.com/GrahamCampbell"
|
||||
}
|
||||
],
|
||||
"description": "An Implementation Of The Result Type",
|
||||
"keywords": [
|
||||
"Graham Campbell",
|
||||
"GrahamCampbell",
|
||||
"Result Type",
|
||||
"Result-Type",
|
||||
"result"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/GrahamCampbell/Result-Type/issues",
|
||||
"source": "https://github.com/GrahamCampbell/Result-Type/tree/v1.1.3"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://github.com/GrahamCampbell",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/graham-campbell/result-type",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"install-path": "../graham-campbell/result-type"
|
||||
},
|
||||
{
|
||||
"name": "phpoption/phpoption",
|
||||
"version": "1.9.3",
|
||||
"version_normalized": "1.9.3.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/schmittjoh/php-option.git",
|
||||
"reference": "e3fac8b24f56113f7cb96af14958c0dd16330f54"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/schmittjoh/php-option/zipball/e3fac8b24f56113f7cb96af14958c0dd16330f54",
|
||||
"reference": "e3fac8b24f56113f7cb96af14958c0dd16330f54",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.2.5 || ^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"bamarni/composer-bin-plugin": "^1.8.2",
|
||||
"phpunit/phpunit": "^8.5.39 || ^9.6.20 || ^10.5.28"
|
||||
},
|
||||
"time": "2024-07-20T21:41:07+00:00",
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"bamarni-bin": {
|
||||
"bin-links": true,
|
||||
"forward-command": false
|
||||
},
|
||||
"branch-alias": {
|
||||
"dev-master": "1.9-dev"
|
||||
}
|
||||
},
|
||||
"installation-source": "dist",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"PhpOption\\": "src/PhpOption/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"Apache-2.0"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Johannes M. Schmitt",
|
||||
"email": "schmittjoh@gmail.com",
|
||||
"homepage": "https://github.com/schmittjoh"
|
||||
},
|
||||
{
|
||||
"name": "Graham Campbell",
|
||||
"email": "hello@gjcampbell.co.uk",
|
||||
"homepage": "https://github.com/GrahamCampbell"
|
||||
}
|
||||
],
|
||||
"description": "Option Type for PHP",
|
||||
"keywords": [
|
||||
"language",
|
||||
"option",
|
||||
"php",
|
||||
"type"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/schmittjoh/php-option/issues",
|
||||
"source": "https://github.com/schmittjoh/php-option/tree/1.9.3"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://github.com/GrahamCampbell",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/phpoption/phpoption",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"install-path": "../phpoption/phpoption"
|
||||
},
|
||||
{
|
||||
"name": "symfony/polyfill-ctype",
|
||||
"version": "v1.30.0",
|
||||
"version_normalized": "1.30.0.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/polyfill-ctype.git",
|
||||
"reference": "0424dff1c58f028c451efff2045f5d92410bd540"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/0424dff1c58f028c451efff2045f5d92410bd540",
|
||||
"reference": "0424dff1c58f028c451efff2045f5d92410bd540",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.1"
|
||||
},
|
||||
"provide": {
|
||||
"ext-ctype": "*"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-ctype": "For best performance"
|
||||
},
|
||||
"time": "2024-05-31T15:07:36+00:00",
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"thanks": {
|
||||
"name": "symfony/polyfill",
|
||||
"url": "https://github.com/symfony/polyfill"
|
||||
}
|
||||
},
|
||||
"installation-source": "dist",
|
||||
"autoload": {
|
||||
"files": [
|
||||
"bootstrap.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"Symfony\\Polyfill\\Ctype\\": ""
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Gert de Pagter",
|
||||
"email": "BackEndTea@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Symfony polyfill for ctype functions",
|
||||
"homepage": "https://symfony.com",
|
||||
"keywords": [
|
||||
"compatibility",
|
||||
"ctype",
|
||||
"polyfill",
|
||||
"portable"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/polyfill-ctype/tree/v1.30.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://symfony.com/sponsor",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/fabpot",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"install-path": "../symfony/polyfill-ctype"
|
||||
},
|
||||
{
|
||||
"name": "symfony/polyfill-mbstring",
|
||||
"version": "v1.30.0",
|
||||
"version_normalized": "1.30.0.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/polyfill-mbstring.git",
|
||||
"reference": "fd22ab50000ef01661e2a31d850ebaa297f8e03c"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/fd22ab50000ef01661e2a31d850ebaa297f8e03c",
|
||||
"reference": "fd22ab50000ef01661e2a31d850ebaa297f8e03c",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.1"
|
||||
},
|
||||
"provide": {
|
||||
"ext-mbstring": "*"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-mbstring": "For best performance"
|
||||
},
|
||||
"time": "2024-06-19T12:30:46+00:00",
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"thanks": {
|
||||
"name": "symfony/polyfill",
|
||||
"url": "https://github.com/symfony/polyfill"
|
||||
}
|
||||
},
|
||||
"installation-source": "dist",
|
||||
"autoload": {
|
||||
"files": [
|
||||
"bootstrap.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"Symfony\\Polyfill\\Mbstring\\": ""
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nicolas Grekas",
|
||||
"email": "p@tchwork.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Symfony polyfill for the Mbstring extension",
|
||||
"homepage": "https://symfony.com",
|
||||
"keywords": [
|
||||
"compatibility",
|
||||
"mbstring",
|
||||
"polyfill",
|
||||
"portable",
|
||||
"shim"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/polyfill-mbstring/tree/v1.30.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://symfony.com/sponsor",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/fabpot",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"install-path": "../symfony/polyfill-mbstring"
|
||||
},
|
||||
{
|
||||
"name": "symfony/polyfill-php80",
|
||||
"version": "v1.30.0",
|
||||
"version_normalized": "1.30.0.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/polyfill-php80.git",
|
||||
"reference": "77fa7995ac1b21ab60769b7323d600a991a90433"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/77fa7995ac1b21ab60769b7323d600a991a90433",
|
||||
"reference": "77fa7995ac1b21ab60769b7323d600a991a90433",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.1"
|
||||
},
|
||||
"time": "2024-05-31T15:07:36+00:00",
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"thanks": {
|
||||
"name": "symfony/polyfill",
|
||||
"url": "https://github.com/symfony/polyfill"
|
||||
}
|
||||
},
|
||||
"installation-source": "dist",
|
||||
"autoload": {
|
||||
"files": [
|
||||
"bootstrap.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"Symfony\\Polyfill\\Php80\\": ""
|
||||
},
|
||||
"classmap": [
|
||||
"Resources/stubs"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Ion Bazan",
|
||||
"email": "ion.bazan@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Nicolas Grekas",
|
||||
"email": "p@tchwork.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions",
|
||||
"homepage": "https://symfony.com",
|
||||
"keywords": [
|
||||
"compatibility",
|
||||
"polyfill",
|
||||
"portable",
|
||||
"shim"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/polyfill-php80/tree/v1.30.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://symfony.com/sponsor",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/fabpot",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"install-path": "../symfony/polyfill-php80"
|
||||
},
|
||||
{
|
||||
"name": "vlucas/phpdotenv",
|
||||
"version": "v5.6.1",
|
||||
"version_normalized": "5.6.1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/vlucas/phpdotenv.git",
|
||||
"reference": "a59a13791077fe3d44f90e7133eb68e7d22eaff2"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/a59a13791077fe3d44f90e7133eb68e7d22eaff2",
|
||||
"reference": "a59a13791077fe3d44f90e7133eb68e7d22eaff2",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-pcre": "*",
|
||||
"graham-campbell/result-type": "^1.1.3",
|
||||
"php": "^7.2.5 || ^8.0",
|
||||
"phpoption/phpoption": "^1.9.3",
|
||||
"symfony/polyfill-ctype": "^1.24",
|
||||
"symfony/polyfill-mbstring": "^1.24",
|
||||
"symfony/polyfill-php80": "^1.24"
|
||||
},
|
||||
"require-dev": {
|
||||
"bamarni/composer-bin-plugin": "^1.8.2",
|
||||
"ext-filter": "*",
|
||||
"phpunit/phpunit": "^8.5.34 || ^9.6.13 || ^10.4.2"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-filter": "Required to use the boolean validator."
|
||||
},
|
||||
"time": "2024-07-20T21:52:34+00:00",
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"bamarni-bin": {
|
||||
"bin-links": true,
|
||||
"forward-command": false
|
||||
},
|
||||
"branch-alias": {
|
||||
"dev-master": "5.6-dev"
|
||||
}
|
||||
},
|
||||
"installation-source": "dist",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Dotenv\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"BSD-3-Clause"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Graham Campbell",
|
||||
"email": "hello@gjcampbell.co.uk",
|
||||
"homepage": "https://github.com/GrahamCampbell"
|
||||
},
|
||||
{
|
||||
"name": "Vance Lucas",
|
||||
"email": "vance@vancelucas.com",
|
||||
"homepage": "https://github.com/vlucas"
|
||||
}
|
||||
],
|
||||
"description": "Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.",
|
||||
"keywords": [
|
||||
"dotenv",
|
||||
"env",
|
||||
"environment"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/vlucas/phpdotenv/issues",
|
||||
"source": "https://github.com/vlucas/phpdotenv/tree/v5.6.1"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://github.com/GrahamCampbell",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/vlucas/phpdotenv",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"install-path": "../vlucas/phpdotenv"
|
||||
}
|
||||
],
|
||||
"dev": true,
|
||||
"dev-package-names": []
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
<?php return array(
|
||||
'root' => array(
|
||||
'name' => '__root__',
|
||||
'pretty_version' => 'dev-main',
|
||||
'version' => 'dev-main',
|
||||
'reference' => '9cac1650a1e0493c29e7f14d01e7a9f1756dffd2',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../../',
|
||||
'aliases' => array(),
|
||||
'dev' => true,
|
||||
),
|
||||
'versions' => array(
|
||||
'__root__' => array(
|
||||
'pretty_version' => 'dev-main',
|
||||
'version' => 'dev-main',
|
||||
'reference' => '9cac1650a1e0493c29e7f14d01e7a9f1756dffd2',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../../',
|
||||
'aliases' => array(),
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'graham-campbell/result-type' => array(
|
||||
'pretty_version' => 'v1.1.3',
|
||||
'version' => '1.1.3.0',
|
||||
'reference' => '3ba905c11371512af9d9bdd27d99b782216b6945',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../graham-campbell/result-type',
|
||||
'aliases' => array(),
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'phpoption/phpoption' => array(
|
||||
'pretty_version' => '1.9.3',
|
||||
'version' => '1.9.3.0',
|
||||
'reference' => 'e3fac8b24f56113f7cb96af14958c0dd16330f54',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../phpoption/phpoption',
|
||||
'aliases' => array(),
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'symfony/polyfill-ctype' => array(
|
||||
'pretty_version' => 'v1.30.0',
|
||||
'version' => '1.30.0.0',
|
||||
'reference' => '0424dff1c58f028c451efff2045f5d92410bd540',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../symfony/polyfill-ctype',
|
||||
'aliases' => array(),
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'symfony/polyfill-mbstring' => array(
|
||||
'pretty_version' => 'v1.30.0',
|
||||
'version' => '1.30.0.0',
|
||||
'reference' => 'fd22ab50000ef01661e2a31d850ebaa297f8e03c',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../symfony/polyfill-mbstring',
|
||||
'aliases' => array(),
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'symfony/polyfill-php80' => array(
|
||||
'pretty_version' => 'v1.30.0',
|
||||
'version' => '1.30.0.0',
|
||||
'reference' => '77fa7995ac1b21ab60769b7323d600a991a90433',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../symfony/polyfill-php80',
|
||||
'aliases' => array(),
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'vlucas/phpdotenv' => array(
|
||||
'pretty_version' => 'v5.6.1',
|
||||
'version' => '5.6.1.0',
|
||||
'reference' => 'a59a13791077fe3d44f90e7133eb68e7d22eaff2',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../vlucas/phpdotenv',
|
||||
'aliases' => array(),
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
),
|
||||
);
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
// platform_check.php @generated by Composer
|
||||
|
||||
$issues = array();
|
||||
|
||||
if (!(PHP_VERSION_ID >= 70205)) {
|
||||
$issues[] = 'Your Composer dependencies require a PHP version ">= 7.2.5". You are running ' . PHP_VERSION . '.';
|
||||
}
|
||||
|
||||
if ($issues) {
|
||||
if (!headers_sent()) {
|
||||
header('HTTP/1.1 500 Internal Server Error');
|
||||
}
|
||||
if (!ini_get('display_errors')) {
|
||||
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
|
||||
fwrite(STDERR, 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . implode(PHP_EOL, $issues) . PHP_EOL.PHP_EOL);
|
||||
} elseif (!headers_sent()) {
|
||||
echo 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . str_replace('You are running '.PHP_VERSION.'.', '', implode(PHP_EOL, $issues)) . PHP_EOL.PHP_EOL;
|
||||
}
|
||||
}
|
||||
trigger_error(
|
||||
'Composer detected issues in your platform: ' . implode(' ', $issues),
|
||||
E_USER_ERROR
|
||||
);
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2020-2024 Graham Campbell <hello@gjcampbell.co.uk>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
|
@ -0,0 +1,33 @@
|
|||
{
|
||||
"name": "graham-campbell/result-type",
|
||||
"description": "An Implementation Of The Result Type",
|
||||
"keywords": ["result", "result-type", "Result", "Result Type", "Result-Type", "Graham Campbell", "GrahamCampbell"],
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Graham Campbell",
|
||||
"email": "hello@gjcampbell.co.uk",
|
||||
"homepage": "https://github.com/GrahamCampbell"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.2.5 || ^8.0",
|
||||
"phpoption/phpoption": "^1.9.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^8.5.39 || ^9.6.20 || ^10.5.28"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"GrahamCampbell\\ResultType\\": "src/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"GrahamCampbell\\Tests\\ResultType\\": "tests/"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"preferred-install": "dist"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,121 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of Result Type.
|
||||
*
|
||||
* (c) Graham Campbell <hello@gjcampbell.co.uk>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace GrahamCampbell\ResultType;
|
||||
|
||||
use PhpOption\None;
|
||||
use PhpOption\Some;
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @template E
|
||||
*
|
||||
* @extends \GrahamCampbell\ResultType\Result<T,E>
|
||||
*/
|
||||
final class Error extends Result
|
||||
{
|
||||
/**
|
||||
* @var E
|
||||
*/
|
||||
private $value;
|
||||
|
||||
/**
|
||||
* Internal constructor for an error value.
|
||||
*
|
||||
* @param E $value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function __construct($value)
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new error value.
|
||||
*
|
||||
* @template F
|
||||
*
|
||||
* @param F $value
|
||||
*
|
||||
* @return \GrahamCampbell\ResultType\Result<T,F>
|
||||
*/
|
||||
public static function create($value)
|
||||
{
|
||||
return new self($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the success option value.
|
||||
*
|
||||
* @return \PhpOption\Option<T>
|
||||
*/
|
||||
public function success()
|
||||
{
|
||||
return None::create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Map over the success value.
|
||||
*
|
||||
* @template S
|
||||
*
|
||||
* @param callable(T):S $f
|
||||
*
|
||||
* @return \GrahamCampbell\ResultType\Result<S,E>
|
||||
*/
|
||||
public function map(callable $f)
|
||||
{
|
||||
return self::create($this->value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Flat map over the success value.
|
||||
*
|
||||
* @template S
|
||||
* @template F
|
||||
*
|
||||
* @param callable(T):\GrahamCampbell\ResultType\Result<S,F> $f
|
||||
*
|
||||
* @return \GrahamCampbell\ResultType\Result<S,F>
|
||||
*/
|
||||
public function flatMap(callable $f)
|
||||
{
|
||||
/** @var \GrahamCampbell\ResultType\Result<S,F> */
|
||||
return self::create($this->value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the error option value.
|
||||
*
|
||||
* @return \PhpOption\Option<E>
|
||||
*/
|
||||
public function error()
|
||||
{
|
||||
return Some::create($this->value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Map over the error value.
|
||||
*
|
||||
* @template F
|
||||
*
|
||||
* @param callable(E):F $f
|
||||
*
|
||||
* @return \GrahamCampbell\ResultType\Result<T,F>
|
||||
*/
|
||||
public function mapError(callable $f)
|
||||
{
|
||||
return self::create($f($this->value));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of Result Type.
|
||||
*
|
||||
* (c) Graham Campbell <hello@gjcampbell.co.uk>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace GrahamCampbell\ResultType;
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @template E
|
||||
*/
|
||||
abstract class Result
|
||||
{
|
||||
/**
|
||||
* Get the success option value.
|
||||
*
|
||||
* @return \PhpOption\Option<T>
|
||||
*/
|
||||
abstract public function success();
|
||||
|
||||
/**
|
||||
* Map over the success value.
|
||||
*
|
||||
* @template S
|
||||
*
|
||||
* @param callable(T):S $f
|
||||
*
|
||||
* @return \GrahamCampbell\ResultType\Result<S,E>
|
||||
*/
|
||||
abstract public function map(callable $f);
|
||||
|
||||
/**
|
||||
* Flat map over the success value.
|
||||
*
|
||||
* @template S
|
||||
* @template F
|
||||
*
|
||||
* @param callable(T):\GrahamCampbell\ResultType\Result<S,F> $f
|
||||
*
|
||||
* @return \GrahamCampbell\ResultType\Result<S,F>
|
||||
*/
|
||||
abstract public function flatMap(callable $f);
|
||||
|
||||
/**
|
||||
* Get the error option value.
|
||||
*
|
||||
* @return \PhpOption\Option<E>
|
||||
*/
|
||||
abstract public function error();
|
||||
|
||||
/**
|
||||
* Map over the error value.
|
||||
*
|
||||
* @template F
|
||||
*
|
||||
* @param callable(E):F $f
|
||||
*
|
||||
* @return \GrahamCampbell\ResultType\Result<T,F>
|
||||
*/
|
||||
abstract public function mapError(callable $f);
|
||||
}
|
|
@ -0,0 +1,120 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of Result Type.
|
||||
*
|
||||
* (c) Graham Campbell <hello@gjcampbell.co.uk>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace GrahamCampbell\ResultType;
|
||||
|
||||
use PhpOption\None;
|
||||
use PhpOption\Some;
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @template E
|
||||
*
|
||||
* @extends \GrahamCampbell\ResultType\Result<T,E>
|
||||
*/
|
||||
final class Success extends Result
|
||||
{
|
||||
/**
|
||||
* @var T
|
||||
*/
|
||||
private $value;
|
||||
|
||||
/**
|
||||
* Internal constructor for a success value.
|
||||
*
|
||||
* @param T $value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function __construct($value)
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new error value.
|
||||
*
|
||||
* @template S
|
||||
*
|
||||
* @param S $value
|
||||
*
|
||||
* @return \GrahamCampbell\ResultType\Result<S,E>
|
||||
*/
|
||||
public static function create($value)
|
||||
{
|
||||
return new self($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the success option value.
|
||||
*
|
||||
* @return \PhpOption\Option<T>
|
||||
*/
|
||||
public function success()
|
||||
{
|
||||
return Some::create($this->value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Map over the success value.
|
||||
*
|
||||
* @template S
|
||||
*
|
||||
* @param callable(T):S $f
|
||||
*
|
||||
* @return \GrahamCampbell\ResultType\Result<S,E>
|
||||
*/
|
||||
public function map(callable $f)
|
||||
{
|
||||
return self::create($f($this->value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Flat map over the success value.
|
||||
*
|
||||
* @template S
|
||||
* @template F
|
||||
*
|
||||
* @param callable(T):\GrahamCampbell\ResultType\Result<S,F> $f
|
||||
*
|
||||
* @return \GrahamCampbell\ResultType\Result<S,F>
|
||||
*/
|
||||
public function flatMap(callable $f)
|
||||
{
|
||||
return $f($this->value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the error option value.
|
||||
*
|
||||
* @return \PhpOption\Option<E>
|
||||
*/
|
||||
public function error()
|
||||
{
|
||||
return None::create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Map over the error value.
|
||||
*
|
||||
* @template F
|
||||
*
|
||||
* @param callable(E):F $f
|
||||
*
|
||||
* @return \GrahamCampbell\ResultType\Result<T,F>
|
||||
*/
|
||||
public function mapError(callable $f)
|
||||
{
|
||||
return self::create($this->value);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,201 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
|
@ -0,0 +1,50 @@
|
|||
{
|
||||
"name": "phpoption/phpoption",
|
||||
"description": "Option Type for PHP",
|
||||
"keywords": ["php", "option", "language", "type"],
|
||||
"license": "Apache-2.0",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Johannes M. Schmitt",
|
||||
"email": "schmittjoh@gmail.com",
|
||||
"homepage": "https://github.com/schmittjoh"
|
||||
},
|
||||
{
|
||||
"name": "Graham Campbell",
|
||||
"email": "hello@gjcampbell.co.uk",
|
||||
"homepage": "https://github.com/GrahamCampbell"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.2.5 || ^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"bamarni/composer-bin-plugin": "^1.8.2",
|
||||
"phpunit/phpunit": "^8.5.39 || ^9.6.20 || ^10.5.28"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"PhpOption\\": "src/PhpOption/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"PhpOption\\Tests\\": "tests/PhpOption/Tests/"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"allow-plugins": {
|
||||
"bamarni/composer-bin-plugin": true
|
||||
},
|
||||
"preferred-install": "dist"
|
||||
},
|
||||
"extra": {
|
||||
"bamarni-bin": {
|
||||
"bin-links": true,
|
||||
"forward-command": false
|
||||
},
|
||||
"branch-alias": {
|
||||
"dev-master": "1.9-dev"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,175 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2012 Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace PhpOption;
|
||||
|
||||
use Traversable;
|
||||
|
||||
/**
|
||||
* @template T
|
||||
*
|
||||
* @extends Option<T>
|
||||
*/
|
||||
final class LazyOption extends Option
|
||||
{
|
||||
/** @var callable(mixed...):(Option<T>) */
|
||||
private $callback;
|
||||
|
||||
/** @var array<int, mixed> */
|
||||
private $arguments;
|
||||
|
||||
/** @var Option<T>|null */
|
||||
private $option;
|
||||
|
||||
/**
|
||||
* @template S
|
||||
* @param callable(mixed...):(Option<S>) $callback
|
||||
* @param array<int, mixed> $arguments
|
||||
*
|
||||
* @return LazyOption<S>
|
||||
*/
|
||||
public static function create($callback, array $arguments = []): self
|
||||
{
|
||||
return new self($callback, $arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable(mixed...):(Option<T>) $callback
|
||||
* @param array<int, mixed> $arguments
|
||||
*/
|
||||
public function __construct($callback, array $arguments = [])
|
||||
{
|
||||
if (!is_callable($callback)) {
|
||||
throw new \InvalidArgumentException('Invalid callback given');
|
||||
}
|
||||
|
||||
$this->callback = $callback;
|
||||
$this->arguments = $arguments;
|
||||
}
|
||||
|
||||
public function isDefined(): bool
|
||||
{
|
||||
return $this->option()->isDefined();
|
||||
}
|
||||
|
||||
public function isEmpty(): bool
|
||||
{
|
||||
return $this->option()->isEmpty();
|
||||
}
|
||||
|
||||
public function get()
|
||||
{
|
||||
return $this->option()->get();
|
||||
}
|
||||
|
||||
public function getOrElse($default)
|
||||
{
|
||||
return $this->option()->getOrElse($default);
|
||||
}
|
||||
|
||||
public function getOrCall($callable)
|
||||
{
|
||||
return $this->option()->getOrCall($callable);
|
||||
}
|
||||
|
||||
public function getOrThrow(\Exception $ex)
|
||||
{
|
||||
return $this->option()->getOrThrow($ex);
|
||||
}
|
||||
|
||||
public function orElse(Option $else)
|
||||
{
|
||||
return $this->option()->orElse($else);
|
||||
}
|
||||
|
||||
public function ifDefined($callable)
|
||||
{
|
||||
$this->option()->forAll($callable);
|
||||
}
|
||||
|
||||
public function forAll($callable)
|
||||
{
|
||||
return $this->option()->forAll($callable);
|
||||
}
|
||||
|
||||
public function map($callable)
|
||||
{
|
||||
return $this->option()->map($callable);
|
||||
}
|
||||
|
||||
public function flatMap($callable)
|
||||
{
|
||||
return $this->option()->flatMap($callable);
|
||||
}
|
||||
|
||||
public function filter($callable)
|
||||
{
|
||||
return $this->option()->filter($callable);
|
||||
}
|
||||
|
||||
public function filterNot($callable)
|
||||
{
|
||||
return $this->option()->filterNot($callable);
|
||||
}
|
||||
|
||||
public function select($value)
|
||||
{
|
||||
return $this->option()->select($value);
|
||||
}
|
||||
|
||||
public function reject($value)
|
||||
{
|
||||
return $this->option()->reject($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Traversable<T>
|
||||
*/
|
||||
public function getIterator(): Traversable
|
||||
{
|
||||
return $this->option()->getIterator();
|
||||
}
|
||||
|
||||
public function foldLeft($initialValue, $callable)
|
||||
{
|
||||
return $this->option()->foldLeft($initialValue, $callable);
|
||||
}
|
||||
|
||||
public function foldRight($initialValue, $callable)
|
||||
{
|
||||
return $this->option()->foldRight($initialValue, $callable);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Option<T>
|
||||
*/
|
||||
private function option(): Option
|
||||
{
|
||||
if (null === $this->option) {
|
||||
/** @var mixed */
|
||||
$option = call_user_func_array($this->callback, $this->arguments);
|
||||
if ($option instanceof Option) {
|
||||
$this->option = $option;
|
||||
} else {
|
||||
throw new \RuntimeException(sprintf('Expected instance of %s', Option::class));
|
||||
}
|
||||
}
|
||||
|
||||
return $this->option;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,136 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2012 Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace PhpOption;
|
||||
|
||||
use EmptyIterator;
|
||||
|
||||
/**
|
||||
* @extends Option<mixed>
|
||||
*/
|
||||
final class None extends Option
|
||||
{
|
||||
/** @var None|null */
|
||||
private static $instance;
|
||||
|
||||
/**
|
||||
* @return None
|
||||
*/
|
||||
public static function create(): self
|
||||
{
|
||||
if (null === self::$instance) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
public function get()
|
||||
{
|
||||
throw new \RuntimeException('None has no value.');
|
||||
}
|
||||
|
||||
public function getOrCall($callable)
|
||||
{
|
||||
return $callable();
|
||||
}
|
||||
|
||||
public function getOrElse($default)
|
||||
{
|
||||
return $default;
|
||||
}
|
||||
|
||||
public function getOrThrow(\Exception $ex)
|
||||
{
|
||||
throw $ex;
|
||||
}
|
||||
|
||||
public function isEmpty(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function isDefined(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function orElse(Option $else)
|
||||
{
|
||||
return $else;
|
||||
}
|
||||
|
||||
public function ifDefined($callable)
|
||||
{
|
||||
// Just do nothing in that case.
|
||||
}
|
||||
|
||||
public function forAll($callable)
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function map($callable)
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function flatMap($callable)
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function filter($callable)
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function filterNot($callable)
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function select($value)
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function reject($value)
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getIterator(): EmptyIterator
|
||||
{
|
||||
return new EmptyIterator();
|
||||
}
|
||||
|
||||
public function foldLeft($initialValue, $callable)
|
||||
{
|
||||
return $initialValue;
|
||||
}
|
||||
|
||||
public function foldRight($initialValue, $callable)
|
||||
{
|
||||
return $initialValue;
|
||||
}
|
||||
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,434 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2012 Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace PhpOption;
|
||||
|
||||
use ArrayAccess;
|
||||
use IteratorAggregate;
|
||||
|
||||
/**
|
||||
* @template T
|
||||
*
|
||||
* @implements IteratorAggregate<T>
|
||||
*/
|
||||
abstract class Option implements IteratorAggregate
|
||||
{
|
||||
/**
|
||||
* Creates an option given a return value.
|
||||
*
|
||||
* This is intended for consuming existing APIs and allows you to easily
|
||||
* convert them to an option. By default, we treat ``null`` as the None
|
||||
* case, and everything else as Some.
|
||||
*
|
||||
* @template S
|
||||
*
|
||||
* @param S $value The actual return value.
|
||||
* @param S $noneValue The value which should be considered "None"; null by
|
||||
* default.
|
||||
*
|
||||
* @return Option<S>
|
||||
*/
|
||||
public static function fromValue($value, $noneValue = null)
|
||||
{
|
||||
if ($value === $noneValue) {
|
||||
return None::create();
|
||||
}
|
||||
|
||||
return new Some($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an option from an array's value.
|
||||
*
|
||||
* If the key does not exist in the array, the array is not actually an
|
||||
* array, or the array's value at the given key is null, None is returned.
|
||||
* Otherwise, Some is returned wrapping the value at the given key.
|
||||
*
|
||||
* @template S
|
||||
*
|
||||
* @param array<string|int,S>|ArrayAccess<string|int,S>|null $array A potential array or \ArrayAccess value.
|
||||
* @param string|int|null $key The key to check.
|
||||
*
|
||||
* @return Option<S>
|
||||
*/
|
||||
public static function fromArraysValue($array, $key)
|
||||
{
|
||||
if ($key === null || !(is_array($array) || $array instanceof ArrayAccess) || !isset($array[$key])) {
|
||||
return None::create();
|
||||
}
|
||||
|
||||
return new Some($array[$key]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a lazy-option with the given callback.
|
||||
*
|
||||
* This is also a helper constructor for lazy-consuming existing APIs where
|
||||
* the return value is not yet an option. By default, we treat ``null`` as
|
||||
* None case, and everything else as Some.
|
||||
*
|
||||
* @template S
|
||||
*
|
||||
* @param callable $callback The callback to evaluate.
|
||||
* @param array $arguments The arguments for the callback.
|
||||
* @param S $noneValue The value which should be considered "None";
|
||||
* null by default.
|
||||
*
|
||||
* @return LazyOption<S>
|
||||
*/
|
||||
public static function fromReturn($callback, array $arguments = [], $noneValue = null)
|
||||
{
|
||||
return new LazyOption(static function () use ($callback, $arguments, $noneValue) {
|
||||
/** @var mixed */
|
||||
$return = call_user_func_array($callback, $arguments);
|
||||
|
||||
if ($return === $noneValue) {
|
||||
return None::create();
|
||||
}
|
||||
|
||||
return new Some($return);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Option factory, which creates new option based on passed value.
|
||||
*
|
||||
* If value is already an option, it simply returns. If value is callable,
|
||||
* LazyOption with passed callback created and returned. If Option
|
||||
* returned from callback, it returns directly. On other case value passed
|
||||
* to Option::fromValue() method.
|
||||
*
|
||||
* @template S
|
||||
*
|
||||
* @param Option<S>|callable|S $value
|
||||
* @param S $noneValue Used when $value is mixed or
|
||||
* callable, for None-check.
|
||||
*
|
||||
* @return Option<S>|LazyOption<S>
|
||||
*/
|
||||
public static function ensure($value, $noneValue = null)
|
||||
{
|
||||
if ($value instanceof self) {
|
||||
return $value;
|
||||
} elseif (is_callable($value)) {
|
||||
return new LazyOption(static function () use ($value, $noneValue) {
|
||||
/** @var mixed */
|
||||
$return = $value();
|
||||
|
||||
if ($return instanceof self) {
|
||||
return $return;
|
||||
} else {
|
||||
return self::fromValue($return, $noneValue);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return self::fromValue($value, $noneValue);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lift a function so that it accepts Option as parameters.
|
||||
*
|
||||
* We return a new closure that wraps the original callback. If any of the
|
||||
* parameters passed to the lifted function is empty, the function will
|
||||
* return a value of None. Otherwise, we will pass all parameters to the
|
||||
* original callback and return the value inside a new Option, unless an
|
||||
* Option is returned from the function, in which case, we use that.
|
||||
*
|
||||
* @template S
|
||||
*
|
||||
* @param callable $callback
|
||||
* @param mixed $noneValue
|
||||
*
|
||||
* @return callable
|
||||
*/
|
||||
public static function lift($callback, $noneValue = null)
|
||||
{
|
||||
return static function () use ($callback, $noneValue) {
|
||||
/** @var array<int, mixed> */
|
||||
$args = func_get_args();
|
||||
|
||||
$reduced_args = array_reduce(
|
||||
$args,
|
||||
/** @param bool $status */
|
||||
static function ($status, self $o) {
|
||||
return $o->isEmpty() ? true : $status;
|
||||
},
|
||||
false
|
||||
);
|
||||
// if at least one parameter is empty, return None
|
||||
if ($reduced_args) {
|
||||
return None::create();
|
||||
}
|
||||
|
||||
$args = array_map(
|
||||
/** @return T */
|
||||
static function (self $o) {
|
||||
// it is safe to do so because the fold above checked
|
||||
// that all arguments are of type Some
|
||||
/** @var T */
|
||||
return $o->get();
|
||||
},
|
||||
$args
|
||||
);
|
||||
|
||||
return self::ensure(call_user_func_array($callback, $args), $noneValue);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value if available, or throws an exception otherwise.
|
||||
*
|
||||
* @throws \RuntimeException If value is not available.
|
||||
*
|
||||
* @return T
|
||||
*/
|
||||
abstract public function get();
|
||||
|
||||
/**
|
||||
* Returns the value if available, or the default value if not.
|
||||
*
|
||||
* @template S
|
||||
*
|
||||
* @param S $default
|
||||
*
|
||||
* @return T|S
|
||||
*/
|
||||
abstract public function getOrElse($default);
|
||||
|
||||
/**
|
||||
* Returns the value if available, or the results of the callable.
|
||||
*
|
||||
* This is preferable over ``getOrElse`` if the computation of the default
|
||||
* value is expensive.
|
||||
*
|
||||
* @template S
|
||||
*
|
||||
* @param callable():S $callable
|
||||
*
|
||||
* @return T|S
|
||||
*/
|
||||
abstract public function getOrCall($callable);
|
||||
|
||||
/**
|
||||
* Returns the value if available, or throws the passed exception.
|
||||
*
|
||||
* @param \Exception $ex
|
||||
*
|
||||
* @return T
|
||||
*/
|
||||
abstract public function getOrThrow(\Exception $ex);
|
||||
|
||||
/**
|
||||
* Returns true if no value is available, false otherwise.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract public function isEmpty();
|
||||
|
||||
/**
|
||||
* Returns true if a value is available, false otherwise.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract public function isDefined();
|
||||
|
||||
/**
|
||||
* Returns this option if non-empty, or the passed option otherwise.
|
||||
*
|
||||
* This can be used to try multiple alternatives, and is especially useful
|
||||
* with lazy evaluating options:
|
||||
*
|
||||
* ```php
|
||||
* $repo->findSomething()
|
||||
* ->orElse(new LazyOption(array($repo, 'findSomethingElse')))
|
||||
* ->orElse(new LazyOption(array($repo, 'createSomething')));
|
||||
* ```
|
||||
*
|
||||
* @param Option<T> $else
|
||||
*
|
||||
* @return Option<T>
|
||||
*/
|
||||
abstract public function orElse(self $else);
|
||||
|
||||
/**
|
||||
* This is similar to map() below except that the return value has no meaning;
|
||||
* the passed callable is simply executed if the option is non-empty, and
|
||||
* ignored if the option is empty.
|
||||
*
|
||||
* In all cases, the return value of the callable is discarded.
|
||||
*
|
||||
* ```php
|
||||
* $comment->getMaybeFile()->ifDefined(function($file) {
|
||||
* // Do something with $file here.
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* If you're looking for something like ``ifEmpty``, you can use ``getOrCall``
|
||||
* and ``getOrElse`` in these cases.
|
||||
*
|
||||
* @deprecated Use forAll() instead.
|
||||
*
|
||||
* @param callable(T):mixed $callable
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
abstract public function ifDefined($callable);
|
||||
|
||||
/**
|
||||
* This is similar to map() except that the return value of the callable has no meaning.
|
||||
*
|
||||
* The passed callable is simply executed if the option is non-empty, and ignored if the
|
||||
* option is empty. This method is preferred for callables with side-effects, while map()
|
||||
* is intended for callables without side-effects.
|
||||
*
|
||||
* @param callable(T):mixed $callable
|
||||
*
|
||||
* @return Option<T>
|
||||
*/
|
||||
abstract public function forAll($callable);
|
||||
|
||||
/**
|
||||
* Applies the callable to the value of the option if it is non-empty,
|
||||
* and returns the return value of the callable wrapped in Some().
|
||||
*
|
||||
* If the option is empty, then the callable is not applied.
|
||||
*
|
||||
* ```php
|
||||
* (new Some("foo"))->map('strtoupper')->get(); // "FOO"
|
||||
* ```
|
||||
*
|
||||
* @template S
|
||||
*
|
||||
* @param callable(T):S $callable
|
||||
*
|
||||
* @return Option<S>
|
||||
*/
|
||||
abstract public function map($callable);
|
||||
|
||||
/**
|
||||
* Applies the callable to the value of the option if it is non-empty, and
|
||||
* returns the return value of the callable directly.
|
||||
*
|
||||
* In contrast to ``map``, the return value of the callable is expected to
|
||||
* be an Option itself; it is not automatically wrapped in Some().
|
||||
*
|
||||
* @template S
|
||||
*
|
||||
* @param callable(T):Option<S> $callable must return an Option
|
||||
*
|
||||
* @return Option<S>
|
||||
*/
|
||||
abstract public function flatMap($callable);
|
||||
|
||||
/**
|
||||
* If the option is empty, it is returned immediately without applying the callable.
|
||||
*
|
||||
* If the option is non-empty, the callable is applied, and if it returns true,
|
||||
* the option itself is returned; otherwise, None is returned.
|
||||
*
|
||||
* @param callable(T):bool $callable
|
||||
*
|
||||
* @return Option<T>
|
||||
*/
|
||||
abstract public function filter($callable);
|
||||
|
||||
/**
|
||||
* If the option is empty, it is returned immediately without applying the callable.
|
||||
*
|
||||
* If the option is non-empty, the callable is applied, and if it returns false,
|
||||
* the option itself is returned; otherwise, None is returned.
|
||||
*
|
||||
* @param callable(T):bool $callable
|
||||
*
|
||||
* @return Option<T>
|
||||
*/
|
||||
abstract public function filterNot($callable);
|
||||
|
||||
/**
|
||||
* If the option is empty, it is returned immediately.
|
||||
*
|
||||
* If the option is non-empty, and its value does not equal the passed value
|
||||
* (via a shallow comparison ===), then None is returned. Otherwise, the
|
||||
* Option is returned.
|
||||
*
|
||||
* In other words, this will filter all but the passed value.
|
||||
*
|
||||
* @param T $value
|
||||
*
|
||||
* @return Option<T>
|
||||
*/
|
||||
abstract public function select($value);
|
||||
|
||||
/**
|
||||
* If the option is empty, it is returned immediately.
|
||||
*
|
||||
* If the option is non-empty, and its value does equal the passed value (via
|
||||
* a shallow comparison ===), then None is returned; otherwise, the Option is
|
||||
* returned.
|
||||
*
|
||||
* In other words, this will let all values through except the passed value.
|
||||
*
|
||||
* @param T $value
|
||||
*
|
||||
* @return Option<T>
|
||||
*/
|
||||
abstract public function reject($value);
|
||||
|
||||
/**
|
||||
* Binary operator for the initial value and the option's value.
|
||||
*
|
||||
* If empty, the initial value is returned. If non-empty, the callable
|
||||
* receives the initial value and the option's value as arguments.
|
||||
*
|
||||
* ```php
|
||||
*
|
||||
* $some = new Some(5);
|
||||
* $none = None::create();
|
||||
* $result = $some->foldLeft(1, function($a, $b) { return $a + $b; }); // int(6)
|
||||
* $result = $none->foldLeft(1, function($a, $b) { return $a + $b; }); // int(1)
|
||||
*
|
||||
* // This can be used instead of something like the following:
|
||||
* $option = Option::fromValue($integerOrNull);
|
||||
* $result = 1;
|
||||
* if ( ! $option->isEmpty()) {
|
||||
* $result += $option->get();
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @template S
|
||||
*
|
||||
* @param S $initialValue
|
||||
* @param callable(S, T):S $callable
|
||||
*
|
||||
* @return S
|
||||
*/
|
||||
abstract public function foldLeft($initialValue, $callable);
|
||||
|
||||
/**
|
||||
* foldLeft() but with reversed arguments for the callable.
|
||||
*
|
||||
* @template S
|
||||
*
|
||||
* @param S $initialValue
|
||||
* @param callable(T, S):S $callable
|
||||
*
|
||||
* @return S
|
||||
*/
|
||||
abstract public function foldRight($initialValue, $callable);
|
||||
}
|
|
@ -0,0 +1,169 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2012 Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace PhpOption;
|
||||
|
||||
use ArrayIterator;
|
||||
|
||||
/**
|
||||
* @template T
|
||||
*
|
||||
* @extends Option<T>
|
||||
*/
|
||||
final class Some extends Option
|
||||
{
|
||||
/** @var T */
|
||||
private $value;
|
||||
|
||||
/**
|
||||
* @param T $value
|
||||
*/
|
||||
public function __construct($value)
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @template U
|
||||
*
|
||||
* @param U $value
|
||||
*
|
||||
* @return Some<U>
|
||||
*/
|
||||
public static function create($value): self
|
||||
{
|
||||
return new self($value);
|
||||
}
|
||||
|
||||
public function isDefined(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function isEmpty(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function get()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
public function getOrElse($default)
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
public function getOrCall($callable)
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
public function getOrThrow(\Exception $ex)
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
public function orElse(Option $else)
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function ifDefined($callable)
|
||||
{
|
||||
$this->forAll($callable);
|
||||
}
|
||||
|
||||
public function forAll($callable)
|
||||
{
|
||||
$callable($this->value);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function map($callable)
|
||||
{
|
||||
return new self($callable($this->value));
|
||||
}
|
||||
|
||||
public function flatMap($callable)
|
||||
{
|
||||
/** @var mixed */
|
||||
$rs = $callable($this->value);
|
||||
if (!$rs instanceof Option) {
|
||||
throw new \RuntimeException('Callables passed to flatMap() must return an Option. Maybe you should use map() instead?');
|
||||
}
|
||||
|
||||
return $rs;
|
||||
}
|
||||
|
||||
public function filter($callable)
|
||||
{
|
||||
if (true === $callable($this->value)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
return None::create();
|
||||
}
|
||||
|
||||
public function filterNot($callable)
|
||||
{
|
||||
if (false === $callable($this->value)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
return None::create();
|
||||
}
|
||||
|
||||
public function select($value)
|
||||
{
|
||||
if ($this->value === $value) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
return None::create();
|
||||
}
|
||||
|
||||
public function reject($value)
|
||||
{
|
||||
if ($this->value === $value) {
|
||||
return None::create();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ArrayIterator<int, T>
|
||||
*/
|
||||
public function getIterator(): ArrayIterator
|
||||
{
|
||||
return new ArrayIterator([$this->value]);
|
||||
}
|
||||
|
||||
public function foldLeft($initialValue, $callable)
|
||||
{
|
||||
return $callable($initialValue, $this->value);
|
||||
}
|
||||
|
||||
public function foldRight($initialValue, $callable)
|
||||
{
|
||||
return $callable($this->value, $initialValue);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,232 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Polyfill\Ctype;
|
||||
|
||||
/**
|
||||
* Ctype implementation through regex.
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @author Gert de Pagter <BackEndTea@gmail.com>
|
||||
*/
|
||||
final class Ctype
|
||||
{
|
||||
/**
|
||||
* Returns TRUE if every character in text is either a letter or a digit, FALSE otherwise.
|
||||
*
|
||||
* @see https://php.net/ctype-alnum
|
||||
*
|
||||
* @param mixed $text
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function ctype_alnum($text)
|
||||
{
|
||||
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
|
||||
|
||||
return \is_string($text) && '' !== $text && !preg_match('/[^A-Za-z0-9]/', $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns TRUE if every character in text is a letter, FALSE otherwise.
|
||||
*
|
||||
* @see https://php.net/ctype-alpha
|
||||
*
|
||||
* @param mixed $text
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function ctype_alpha($text)
|
||||
{
|
||||
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
|
||||
|
||||
return \is_string($text) && '' !== $text && !preg_match('/[^A-Za-z]/', $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns TRUE if every character in text is a control character from the current locale, FALSE otherwise.
|
||||
*
|
||||
* @see https://php.net/ctype-cntrl
|
||||
*
|
||||
* @param mixed $text
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function ctype_cntrl($text)
|
||||
{
|
||||
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
|
||||
|
||||
return \is_string($text) && '' !== $text && !preg_match('/[^\x00-\x1f\x7f]/', $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns TRUE if every character in the string text is a decimal digit, FALSE otherwise.
|
||||
*
|
||||
* @see https://php.net/ctype-digit
|
||||
*
|
||||
* @param mixed $text
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function ctype_digit($text)
|
||||
{
|
||||
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
|
||||
|
||||
return \is_string($text) && '' !== $text && !preg_match('/[^0-9]/', $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns TRUE if every character in text is printable and actually creates visible output (no white space), FALSE otherwise.
|
||||
*
|
||||
* @see https://php.net/ctype-graph
|
||||
*
|
||||
* @param mixed $text
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function ctype_graph($text)
|
||||
{
|
||||
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
|
||||
|
||||
return \is_string($text) && '' !== $text && !preg_match('/[^!-~]/', $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns TRUE if every character in text is a lowercase letter.
|
||||
*
|
||||
* @see https://php.net/ctype-lower
|
||||
*
|
||||
* @param mixed $text
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function ctype_lower($text)
|
||||
{
|
||||
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
|
||||
|
||||
return \is_string($text) && '' !== $text && !preg_match('/[^a-z]/', $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns TRUE if every character in text will actually create output (including blanks). Returns FALSE if text contains control characters or characters that do not have any output or control function at all.
|
||||
*
|
||||
* @see https://php.net/ctype-print
|
||||
*
|
||||
* @param mixed $text
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function ctype_print($text)
|
||||
{
|
||||
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
|
||||
|
||||
return \is_string($text) && '' !== $text && !preg_match('/[^ -~]/', $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns TRUE if every character in text is printable, but neither letter, digit or blank, FALSE otherwise.
|
||||
*
|
||||
* @see https://php.net/ctype-punct
|
||||
*
|
||||
* @param mixed $text
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function ctype_punct($text)
|
||||
{
|
||||
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
|
||||
|
||||
return \is_string($text) && '' !== $text && !preg_match('/[^!-\/\:-@\[-`\{-~]/', $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns TRUE if every character in text creates some sort of white space, FALSE otherwise. Besides the blank character this also includes tab, vertical tab, line feed, carriage return and form feed characters.
|
||||
*
|
||||
* @see https://php.net/ctype-space
|
||||
*
|
||||
* @param mixed $text
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function ctype_space($text)
|
||||
{
|
||||
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
|
||||
|
||||
return \is_string($text) && '' !== $text && !preg_match('/[^\s]/', $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns TRUE if every character in text is an uppercase letter.
|
||||
*
|
||||
* @see https://php.net/ctype-upper
|
||||
*
|
||||
* @param mixed $text
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function ctype_upper($text)
|
||||
{
|
||||
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
|
||||
|
||||
return \is_string($text) && '' !== $text && !preg_match('/[^A-Z]/', $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns TRUE if every character in text is a hexadecimal 'digit', that is a decimal digit or a character from [A-Fa-f] , FALSE otherwise.
|
||||
*
|
||||
* @see https://php.net/ctype-xdigit
|
||||
*
|
||||
* @param mixed $text
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function ctype_xdigit($text)
|
||||
{
|
||||
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
|
||||
|
||||
return \is_string($text) && '' !== $text && !preg_match('/[^A-Fa-f0-9]/', $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts integers to their char versions according to normal ctype behaviour, if needed.
|
||||
*
|
||||
* If an integer between -128 and 255 inclusive is provided,
|
||||
* it is interpreted as the ASCII value of a single character
|
||||
* (negative values have 256 added in order to allow characters in the Extended ASCII range).
|
||||
* Any other integer is interpreted as a string containing the decimal digits of the integer.
|
||||
*
|
||||
* @param mixed $int
|
||||
* @param string $function
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private static function convert_int_to_char_for_ctype($int, $function)
|
||||
{
|
||||
if (!\is_int($int)) {
|
||||
return $int;
|
||||
}
|
||||
|
||||
if ($int < -128 || $int > 255) {
|
||||
return (string) $int;
|
||||
}
|
||||
|
||||
if (\PHP_VERSION_ID >= 80100) {
|
||||
@trigger_error($function.'(): Argument of type int will be interpreted as string in the future', \E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
if ($int < 0) {
|
||||
$int += 256;
|
||||
}
|
||||
|
||||
return \chr($int);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
Copyright (c) 2018-present Fabien Potencier
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
|
@ -0,0 +1,12 @@
|
|||
Symfony Polyfill / Ctype
|
||||
========================
|
||||
|
||||
This component provides `ctype_*` functions to users who run php versions without the ctype extension.
|
||||
|
||||
More information can be found in the
|
||||
[main Polyfill README](https://github.com/symfony/polyfill/blob/main/README.md).
|
||||
|
||||
License
|
||||
=======
|
||||
|
||||
This library is released under the [MIT license](LICENSE).
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Symfony\Polyfill\Ctype as p;
|
||||
|
||||
if (\PHP_VERSION_ID >= 80000) {
|
||||
return require __DIR__.'/bootstrap80.php';
|
||||
}
|
||||
|
||||
if (!function_exists('ctype_alnum')) {
|
||||
function ctype_alnum($text) { return p\Ctype::ctype_alnum($text); }
|
||||
}
|
||||
if (!function_exists('ctype_alpha')) {
|
||||
function ctype_alpha($text) { return p\Ctype::ctype_alpha($text); }
|
||||
}
|
||||
if (!function_exists('ctype_cntrl')) {
|
||||
function ctype_cntrl($text) { return p\Ctype::ctype_cntrl($text); }
|
||||
}
|
||||
if (!function_exists('ctype_digit')) {
|
||||
function ctype_digit($text) { return p\Ctype::ctype_digit($text); }
|
||||
}
|
||||
if (!function_exists('ctype_graph')) {
|
||||
function ctype_graph($text) { return p\Ctype::ctype_graph($text); }
|
||||
}
|
||||
if (!function_exists('ctype_lower')) {
|
||||
function ctype_lower($text) { return p\Ctype::ctype_lower($text); }
|
||||
}
|
||||
if (!function_exists('ctype_print')) {
|
||||
function ctype_print($text) { return p\Ctype::ctype_print($text); }
|
||||
}
|
||||
if (!function_exists('ctype_punct')) {
|
||||
function ctype_punct($text) { return p\Ctype::ctype_punct($text); }
|
||||
}
|
||||
if (!function_exists('ctype_space')) {
|
||||
function ctype_space($text) { return p\Ctype::ctype_space($text); }
|
||||
}
|
||||
if (!function_exists('ctype_upper')) {
|
||||
function ctype_upper($text) { return p\Ctype::ctype_upper($text); }
|
||||
}
|
||||
if (!function_exists('ctype_xdigit')) {
|
||||
function ctype_xdigit($text) { return p\Ctype::ctype_xdigit($text); }
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Symfony\Polyfill\Ctype as p;
|
||||
|
||||
if (!function_exists('ctype_alnum')) {
|
||||
function ctype_alnum(mixed $text): bool { return p\Ctype::ctype_alnum($text); }
|
||||
}
|
||||
if (!function_exists('ctype_alpha')) {
|
||||
function ctype_alpha(mixed $text): bool { return p\Ctype::ctype_alpha($text); }
|
||||
}
|
||||
if (!function_exists('ctype_cntrl')) {
|
||||
function ctype_cntrl(mixed $text): bool { return p\Ctype::ctype_cntrl($text); }
|
||||
}
|
||||
if (!function_exists('ctype_digit')) {
|
||||
function ctype_digit(mixed $text): bool { return p\Ctype::ctype_digit($text); }
|
||||
}
|
||||
if (!function_exists('ctype_graph')) {
|
||||
function ctype_graph(mixed $text): bool { return p\Ctype::ctype_graph($text); }
|
||||
}
|
||||
if (!function_exists('ctype_lower')) {
|
||||
function ctype_lower(mixed $text): bool { return p\Ctype::ctype_lower($text); }
|
||||
}
|
||||
if (!function_exists('ctype_print')) {
|
||||
function ctype_print(mixed $text): bool { return p\Ctype::ctype_print($text); }
|
||||
}
|
||||
if (!function_exists('ctype_punct')) {
|
||||
function ctype_punct(mixed $text): bool { return p\Ctype::ctype_punct($text); }
|
||||
}
|
||||
if (!function_exists('ctype_space')) {
|
||||
function ctype_space(mixed $text): bool { return p\Ctype::ctype_space($text); }
|
||||
}
|
||||
if (!function_exists('ctype_upper')) {
|
||||
function ctype_upper(mixed $text): bool { return p\Ctype::ctype_upper($text); }
|
||||
}
|
||||
if (!function_exists('ctype_xdigit')) {
|
||||
function ctype_xdigit(mixed $text): bool { return p\Ctype::ctype_xdigit($text); }
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
{
|
||||
"name": "symfony/polyfill-ctype",
|
||||
"type": "library",
|
||||
"description": "Symfony polyfill for ctype functions",
|
||||
"keywords": ["polyfill", "compatibility", "portable", "ctype"],
|
||||
"homepage": "https://symfony.com",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Gert de Pagter",
|
||||
"email": "BackEndTea@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.1"
|
||||
},
|
||||
"provide": {
|
||||
"ext-ctype": "*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": { "Symfony\\Polyfill\\Ctype\\": "" },
|
||||
"files": [ "bootstrap.php" ]
|
||||
},
|
||||
"suggest": {
|
||||
"ext-ctype": "For best performance"
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"extra": {
|
||||
"thanks": {
|
||||
"name": "symfony/polyfill",
|
||||
"url": "https://github.com/symfony/polyfill"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
Copyright (c) 2015-present Fabien Potencier
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
|
@ -0,0 +1,996 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Polyfill\Mbstring;
|
||||
|
||||
/**
|
||||
* Partial mbstring implementation in PHP, iconv based, UTF-8 centric.
|
||||
*
|
||||
* Implemented:
|
||||
* - mb_chr - Returns a specific character from its Unicode code point
|
||||
* - mb_convert_encoding - Convert character encoding
|
||||
* - mb_convert_variables - Convert character code in variable(s)
|
||||
* - mb_decode_mimeheader - Decode string in MIME header field
|
||||
* - mb_encode_mimeheader - Encode string for MIME header XXX NATIVE IMPLEMENTATION IS REALLY BUGGED
|
||||
* - mb_decode_numericentity - Decode HTML numeric string reference to character
|
||||
* - mb_encode_numericentity - Encode character to HTML numeric string reference
|
||||
* - mb_convert_case - Perform case folding on a string
|
||||
* - mb_detect_encoding - Detect character encoding
|
||||
* - mb_get_info - Get internal settings of mbstring
|
||||
* - mb_http_input - Detect HTTP input character encoding
|
||||
* - mb_http_output - Set/Get HTTP output character encoding
|
||||
* - mb_internal_encoding - Set/Get internal character encoding
|
||||
* - mb_list_encodings - Returns an array of all supported encodings
|
||||
* - mb_ord - Returns the Unicode code point of a character
|
||||
* - mb_output_handler - Callback function converts character encoding in output buffer
|
||||
* - mb_scrub - Replaces ill-formed byte sequences with substitute characters
|
||||
* - mb_strlen - Get string length
|
||||
* - mb_strpos - Find position of first occurrence of string in a string
|
||||
* - mb_strrpos - Find position of last occurrence of a string in a string
|
||||
* - mb_str_split - Convert a string to an array
|
||||
* - mb_strtolower - Make a string lowercase
|
||||
* - mb_strtoupper - Make a string uppercase
|
||||
* - mb_substitute_character - Set/Get substitution character
|
||||
* - mb_substr - Get part of string
|
||||
* - mb_stripos - Finds position of first occurrence of a string within another, case insensitive
|
||||
* - mb_stristr - Finds first occurrence of a string within another, case insensitive
|
||||
* - mb_strrchr - Finds the last occurrence of a character in a string within another
|
||||
* - mb_strrichr - Finds the last occurrence of a character in a string within another, case insensitive
|
||||
* - mb_strripos - Finds position of last occurrence of a string within another, case insensitive
|
||||
* - mb_strstr - Finds first occurrence of a string within another
|
||||
* - mb_strwidth - Return width of string
|
||||
* - mb_substr_count - Count the number of substring occurrences
|
||||
* - mb_ucfirst - Make a string's first character uppercase
|
||||
* - mb_lcfirst - Make a string's first character lowercase
|
||||
*
|
||||
* Not implemented:
|
||||
* - mb_convert_kana - Convert "kana" one from another ("zen-kaku", "han-kaku" and more)
|
||||
* - mb_ereg_* - Regular expression with multibyte support
|
||||
* - mb_parse_str - Parse GET/POST/COOKIE data and set global variable
|
||||
* - mb_preferred_mime_name - Get MIME charset string
|
||||
* - mb_regex_encoding - Returns current encoding for multibyte regex as string
|
||||
* - mb_regex_set_options - Set/Get the default options for mbregex functions
|
||||
* - mb_send_mail - Send encoded mail
|
||||
* - mb_split - Split multibyte string using regular expression
|
||||
* - mb_strcut - Get part of string
|
||||
* - mb_strimwidth - Get truncated string with specified width
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
final class Mbstring
|
||||
{
|
||||
public const MB_CASE_FOLD = \PHP_INT_MAX;
|
||||
|
||||
private const SIMPLE_CASE_FOLD = [
|
||||
['µ', 'ſ', "\xCD\x85", 'ς', "\xCF\x90", "\xCF\x91", "\xCF\x95", "\xCF\x96", "\xCF\xB0", "\xCF\xB1", "\xCF\xB5", "\xE1\xBA\x9B", "\xE1\xBE\xBE"],
|
||||
['μ', 's', 'ι', 'σ', 'β', 'θ', 'φ', 'π', 'κ', 'ρ', 'ε', "\xE1\xB9\xA1", 'ι'],
|
||||
];
|
||||
|
||||
private static $encodingList = ['ASCII', 'UTF-8'];
|
||||
private static $language = 'neutral';
|
||||
private static $internalEncoding = 'UTF-8';
|
||||
|
||||
public static function mb_convert_encoding($s, $toEncoding, $fromEncoding = null)
|
||||
{
|
||||
if (\is_array($s)) {
|
||||
if (PHP_VERSION_ID < 70200) {
|
||||
trigger_error('mb_convert_encoding() expects parameter 1 to be string, array given', \E_USER_WARNING);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$r = [];
|
||||
foreach ($s as $str) {
|
||||
$r[] = self::mb_convert_encoding($str, $toEncoding, $fromEncoding);
|
||||
}
|
||||
|
||||
return $r;
|
||||
}
|
||||
|
||||
if (\is_array($fromEncoding) || (null !== $fromEncoding && false !== strpos($fromEncoding, ','))) {
|
||||
$fromEncoding = self::mb_detect_encoding($s, $fromEncoding);
|
||||
} else {
|
||||
$fromEncoding = self::getEncoding($fromEncoding);
|
||||
}
|
||||
|
||||
$toEncoding = self::getEncoding($toEncoding);
|
||||
|
||||
if ('BASE64' === $fromEncoding) {
|
||||
$s = base64_decode($s);
|
||||
$fromEncoding = $toEncoding;
|
||||
}
|
||||
|
||||
if ('BASE64' === $toEncoding) {
|
||||
return base64_encode($s);
|
||||
}
|
||||
|
||||
if ('HTML-ENTITIES' === $toEncoding || 'HTML' === $toEncoding) {
|
||||
if ('HTML-ENTITIES' === $fromEncoding || 'HTML' === $fromEncoding) {
|
||||
$fromEncoding = 'Windows-1252';
|
||||
}
|
||||
if ('UTF-8' !== $fromEncoding) {
|
||||
$s = iconv($fromEncoding, 'UTF-8//IGNORE', $s);
|
||||
}
|
||||
|
||||
return preg_replace_callback('/[\x80-\xFF]+/', [__CLASS__, 'html_encoding_callback'], $s);
|
||||
}
|
||||
|
||||
if ('HTML-ENTITIES' === $fromEncoding) {
|
||||
$s = html_entity_decode($s, \ENT_COMPAT, 'UTF-8');
|
||||
$fromEncoding = 'UTF-8';
|
||||
}
|
||||
|
||||
return iconv($fromEncoding, $toEncoding.'//IGNORE', $s);
|
||||
}
|
||||
|
||||
public static function mb_convert_variables($toEncoding, $fromEncoding, &...$vars)
|
||||
{
|
||||
$ok = true;
|
||||
array_walk_recursive($vars, function (&$v) use (&$ok, $toEncoding, $fromEncoding) {
|
||||
if (false === $v = self::mb_convert_encoding($v, $toEncoding, $fromEncoding)) {
|
||||
$ok = false;
|
||||
}
|
||||
});
|
||||
|
||||
return $ok ? $fromEncoding : false;
|
||||
}
|
||||
|
||||
public static function mb_decode_mimeheader($s)
|
||||
{
|
||||
return iconv_mime_decode($s, 2, self::$internalEncoding);
|
||||
}
|
||||
|
||||
public static function mb_encode_mimeheader($s, $charset = null, $transferEncoding = null, $linefeed = null, $indent = null)
|
||||
{
|
||||
trigger_error('mb_encode_mimeheader() is bugged. Please use iconv_mime_encode() instead', \E_USER_WARNING);
|
||||
}
|
||||
|
||||
public static function mb_decode_numericentity($s, $convmap, $encoding = null)
|
||||
{
|
||||
if (null !== $s && !\is_scalar($s) && !(\is_object($s) && method_exists($s, '__toString'))) {
|
||||
trigger_error('mb_decode_numericentity() expects parameter 1 to be string, '.\gettype($s).' given', \E_USER_WARNING);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!\is_array($convmap) || (80000 > \PHP_VERSION_ID && !$convmap)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (null !== $encoding && !\is_scalar($encoding)) {
|
||||
trigger_error('mb_decode_numericentity() expects parameter 3 to be string, '.\gettype($s).' given', \E_USER_WARNING);
|
||||
|
||||
return ''; // Instead of null (cf. mb_encode_numericentity).
|
||||
}
|
||||
|
||||
$s = (string) $s;
|
||||
if ('' === $s) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$encoding = self::getEncoding($encoding);
|
||||
|
||||
if ('UTF-8' === $encoding) {
|
||||
$encoding = null;
|
||||
if (!preg_match('//u', $s)) {
|
||||
$s = @iconv('UTF-8', 'UTF-8//IGNORE', $s);
|
||||
}
|
||||
} else {
|
||||
$s = iconv($encoding, 'UTF-8//IGNORE', $s);
|
||||
}
|
||||
|
||||
$cnt = floor(\count($convmap) / 4) * 4;
|
||||
|
||||
for ($i = 0; $i < $cnt; $i += 4) {
|
||||
// collector_decode_htmlnumericentity ignores $convmap[$i + 3]
|
||||
$convmap[$i] += $convmap[$i + 2];
|
||||
$convmap[$i + 1] += $convmap[$i + 2];
|
||||
}
|
||||
|
||||
$s = preg_replace_callback('/&#(?:0*([0-9]+)|x0*([0-9a-fA-F]+))(?!&);?/', function (array $m) use ($cnt, $convmap) {
|
||||
$c = isset($m[2]) ? (int) hexdec($m[2]) : $m[1];
|
||||
for ($i = 0; $i < $cnt; $i += 4) {
|
||||
if ($c >= $convmap[$i] && $c <= $convmap[$i + 1]) {
|
||||
return self::mb_chr($c - $convmap[$i + 2]);
|
||||
}
|
||||
}
|
||||
|
||||
return $m[0];
|
||||
}, $s);
|
||||
|
||||
if (null === $encoding) {
|
||||
return $s;
|
||||
}
|
||||
|
||||
return iconv('UTF-8', $encoding.'//IGNORE', $s);
|
||||
}
|
||||
|
||||
public static function mb_encode_numericentity($s, $convmap, $encoding = null, $is_hex = false)
|
||||
{
|
||||
if (null !== $s && !\is_scalar($s) && !(\is_object($s) && method_exists($s, '__toString'))) {
|
||||
trigger_error('mb_encode_numericentity() expects parameter 1 to be string, '.\gettype($s).' given', \E_USER_WARNING);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!\is_array($convmap) || (80000 > \PHP_VERSION_ID && !$convmap)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (null !== $encoding && !\is_scalar($encoding)) {
|
||||
trigger_error('mb_encode_numericentity() expects parameter 3 to be string, '.\gettype($s).' given', \E_USER_WARNING);
|
||||
|
||||
return null; // Instead of '' (cf. mb_decode_numericentity).
|
||||
}
|
||||
|
||||
if (null !== $is_hex && !\is_scalar($is_hex)) {
|
||||
trigger_error('mb_encode_numericentity() expects parameter 4 to be boolean, '.\gettype($s).' given', \E_USER_WARNING);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$s = (string) $s;
|
||||
if ('' === $s) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$encoding = self::getEncoding($encoding);
|
||||
|
||||
if ('UTF-8' === $encoding) {
|
||||
$encoding = null;
|
||||
if (!preg_match('//u', $s)) {
|
||||
$s = @iconv('UTF-8', 'UTF-8//IGNORE', $s);
|
||||
}
|
||||
} else {
|
||||
$s = iconv($encoding, 'UTF-8//IGNORE', $s);
|
||||
}
|
||||
|
||||
static $ulenMask = ["\xC0" => 2, "\xD0" => 2, "\xE0" => 3, "\xF0" => 4];
|
||||
|
||||
$cnt = floor(\count($convmap) / 4) * 4;
|
||||
$i = 0;
|
||||
$len = \strlen($s);
|
||||
$result = '';
|
||||
|
||||
while ($i < $len) {
|
||||
$ulen = $s[$i] < "\x80" ? 1 : $ulenMask[$s[$i] & "\xF0"];
|
||||
$uchr = substr($s, $i, $ulen);
|
||||
$i += $ulen;
|
||||
$c = self::mb_ord($uchr);
|
||||
|
||||
for ($j = 0; $j < $cnt; $j += 4) {
|
||||
if ($c >= $convmap[$j] && $c <= $convmap[$j + 1]) {
|
||||
$cOffset = ($c + $convmap[$j + 2]) & $convmap[$j + 3];
|
||||
$result .= $is_hex ? sprintf('&#x%X;', $cOffset) : '&#'.$cOffset.';';
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
$result .= $uchr;
|
||||
}
|
||||
|
||||
if (null === $encoding) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
return iconv('UTF-8', $encoding.'//IGNORE', $result);
|
||||
}
|
||||
|
||||
public static function mb_convert_case($s, $mode, $encoding = null)
|
||||
{
|
||||
$s = (string) $s;
|
||||
if ('' === $s) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$encoding = self::getEncoding($encoding);
|
||||
|
||||
if ('UTF-8' === $encoding) {
|
||||
$encoding = null;
|
||||
if (!preg_match('//u', $s)) {
|
||||
$s = @iconv('UTF-8', 'UTF-8//IGNORE', $s);
|
||||
}
|
||||
} else {
|
||||
$s = iconv($encoding, 'UTF-8//IGNORE', $s);
|
||||
}
|
||||
|
||||
if (\MB_CASE_TITLE == $mode) {
|
||||
static $titleRegexp = null;
|
||||
if (null === $titleRegexp) {
|
||||
$titleRegexp = self::getData('titleCaseRegexp');
|
||||
}
|
||||
$s = preg_replace_callback($titleRegexp, [__CLASS__, 'title_case'], $s);
|
||||
} else {
|
||||
if (\MB_CASE_UPPER == $mode) {
|
||||
static $upper = null;
|
||||
if (null === $upper) {
|
||||
$upper = self::getData('upperCase');
|
||||
}
|
||||
$map = $upper;
|
||||
} else {
|
||||
if (self::MB_CASE_FOLD === $mode) {
|
||||
static $caseFolding = null;
|
||||
if (null === $caseFolding) {
|
||||
$caseFolding = self::getData('caseFolding');
|
||||
}
|
||||
$s = strtr($s, $caseFolding);
|
||||
}
|
||||
|
||||
static $lower = null;
|
||||
if (null === $lower) {
|
||||
$lower = self::getData('lowerCase');
|
||||
}
|
||||
$map = $lower;
|
||||
}
|
||||
|
||||
static $ulenMask = ["\xC0" => 2, "\xD0" => 2, "\xE0" => 3, "\xF0" => 4];
|
||||
|
||||
$i = 0;
|
||||
$len = \strlen($s);
|
||||
|
||||
while ($i < $len) {
|
||||
$ulen = $s[$i] < "\x80" ? 1 : $ulenMask[$s[$i] & "\xF0"];
|
||||
$uchr = substr($s, $i, $ulen);
|
||||
$i += $ulen;
|
||||
|
||||
if (isset($map[$uchr])) {
|
||||
$uchr = $map[$uchr];
|
||||
$nlen = \strlen($uchr);
|
||||
|
||||
if ($nlen == $ulen) {
|
||||
$nlen = $i;
|
||||
do {
|
||||
$s[--$nlen] = $uchr[--$ulen];
|
||||
} while ($ulen);
|
||||
} else {
|
||||
$s = substr_replace($s, $uchr, $i - $ulen, $ulen);
|
||||
$len += $nlen - $ulen;
|
||||
$i += $nlen - $ulen;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (null === $encoding) {
|
||||
return $s;
|
||||
}
|
||||
|
||||
return iconv('UTF-8', $encoding.'//IGNORE', $s);
|
||||
}
|
||||
|
||||
public static function mb_internal_encoding($encoding = null)
|
||||
{
|
||||
if (null === $encoding) {
|
||||
return self::$internalEncoding;
|
||||
}
|
||||
|
||||
$normalizedEncoding = self::getEncoding($encoding);
|
||||
|
||||
if ('UTF-8' === $normalizedEncoding || false !== @iconv($normalizedEncoding, $normalizedEncoding, ' ')) {
|
||||
self::$internalEncoding = $normalizedEncoding;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (80000 > \PHP_VERSION_ID) {
|
||||
return false;
|
||||
}
|
||||
|
||||
throw new \ValueError(sprintf('Argument #1 ($encoding) must be a valid encoding, "%s" given', $encoding));
|
||||
}
|
||||
|
||||
public static function mb_language($lang = null)
|
||||
{
|
||||
if (null === $lang) {
|
||||
return self::$language;
|
||||
}
|
||||
|
||||
switch ($normalizedLang = strtolower($lang)) {
|
||||
case 'uni':
|
||||
case 'neutral':
|
||||
self::$language = $normalizedLang;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (80000 > \PHP_VERSION_ID) {
|
||||
return false;
|
||||
}
|
||||
|
||||
throw new \ValueError(sprintf('Argument #1 ($language) must be a valid language, "%s" given', $lang));
|
||||
}
|
||||
|
||||
public static function mb_list_encodings()
|
||||
{
|
||||
return ['UTF-8'];
|
||||
}
|
||||
|
||||
public static function mb_encoding_aliases($encoding)
|
||||
{
|
||||
switch (strtoupper($encoding)) {
|
||||
case 'UTF8':
|
||||
case 'UTF-8':
|
||||
return ['utf8'];
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function mb_check_encoding($var = null, $encoding = null)
|
||||
{
|
||||
if (\PHP_VERSION_ID < 70200 && \is_array($var)) {
|
||||
trigger_error('mb_check_encoding() expects parameter 1 to be string, array given', \E_USER_WARNING);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if (null === $encoding) {
|
||||
if (null === $var) {
|
||||
return false;
|
||||
}
|
||||
$encoding = self::$internalEncoding;
|
||||
}
|
||||
|
||||
if (!\is_array($var)) {
|
||||
return self::mb_detect_encoding($var, [$encoding]) || false !== @iconv($encoding, $encoding, $var);
|
||||
}
|
||||
|
||||
foreach ($var as $key => $value) {
|
||||
if (!self::mb_check_encoding($key, $encoding)) {
|
||||
return false;
|
||||
}
|
||||
if (!self::mb_check_encoding($value, $encoding)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function mb_detect_encoding($str, $encodingList = null, $strict = false)
|
||||
{
|
||||
if (null === $encodingList) {
|
||||
$encodingList = self::$encodingList;
|
||||
} else {
|
||||
if (!\is_array($encodingList)) {
|
||||
$encodingList = array_map('trim', explode(',', $encodingList));
|
||||
}
|
||||
$encodingList = array_map('strtoupper', $encodingList);
|
||||
}
|
||||
|
||||
foreach ($encodingList as $enc) {
|
||||
switch ($enc) {
|
||||
case 'ASCII':
|
||||
if (!preg_match('/[\x80-\xFF]/', $str)) {
|
||||
return $enc;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'UTF8':
|
||||
case 'UTF-8':
|
||||
if (preg_match('//u', $str)) {
|
||||
return 'UTF-8';
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if (0 === strncmp($enc, 'ISO-8859-', 9)) {
|
||||
return $enc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function mb_detect_order($encodingList = null)
|
||||
{
|
||||
if (null === $encodingList) {
|
||||
return self::$encodingList;
|
||||
}
|
||||
|
||||
if (!\is_array($encodingList)) {
|
||||
$encodingList = array_map('trim', explode(',', $encodingList));
|
||||
}
|
||||
$encodingList = array_map('strtoupper', $encodingList);
|
||||
|
||||
foreach ($encodingList as $enc) {
|
||||
switch ($enc) {
|
||||
default:
|
||||
if (strncmp($enc, 'ISO-8859-', 9)) {
|
||||
return false;
|
||||
}
|
||||
// no break
|
||||
case 'ASCII':
|
||||
case 'UTF8':
|
||||
case 'UTF-8':
|
||||
}
|
||||
}
|
||||
|
||||
self::$encodingList = $encodingList;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function mb_strlen($s, $encoding = null)
|
||||
{
|
||||
$encoding = self::getEncoding($encoding);
|
||||
if ('CP850' === $encoding || 'ASCII' === $encoding) {
|
||||
return \strlen($s);
|
||||
}
|
||||
|
||||
return @iconv_strlen($s, $encoding);
|
||||
}
|
||||
|
||||
public static function mb_strpos($haystack, $needle, $offset = 0, $encoding = null)
|
||||
{
|
||||
$encoding = self::getEncoding($encoding);
|
||||
if ('CP850' === $encoding || 'ASCII' === $encoding) {
|
||||
return strpos($haystack, $needle, $offset);
|
||||
}
|
||||
|
||||
$needle = (string) $needle;
|
||||
if ('' === $needle) {
|
||||
if (80000 > \PHP_VERSION_ID) {
|
||||
trigger_error(__METHOD__.': Empty delimiter', \E_USER_WARNING);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return iconv_strpos($haystack, $needle, $offset, $encoding);
|
||||
}
|
||||
|
||||
public static function mb_strrpos($haystack, $needle, $offset = 0, $encoding = null)
|
||||
{
|
||||
$encoding = self::getEncoding($encoding);
|
||||
if ('CP850' === $encoding || 'ASCII' === $encoding) {
|
||||
return strrpos($haystack, $needle, $offset);
|
||||
}
|
||||
|
||||
if ($offset != (int) $offset) {
|
||||
$offset = 0;
|
||||
} elseif ($offset = (int) $offset) {
|
||||
if ($offset < 0) {
|
||||
if (0 > $offset += self::mb_strlen($needle)) {
|
||||
$haystack = self::mb_substr($haystack, 0, $offset, $encoding);
|
||||
}
|
||||
$offset = 0;
|
||||
} else {
|
||||
$haystack = self::mb_substr($haystack, $offset, 2147483647, $encoding);
|
||||
}
|
||||
}
|
||||
|
||||
$pos = '' !== $needle || 80000 > \PHP_VERSION_ID
|
||||
? iconv_strrpos($haystack, $needle, $encoding)
|
||||
: self::mb_strlen($haystack, $encoding);
|
||||
|
||||
return false !== $pos ? $offset + $pos : false;
|
||||
}
|
||||
|
||||
public static function mb_str_split($string, $split_length = 1, $encoding = null)
|
||||
{
|
||||
if (null !== $string && !\is_scalar($string) && !(\is_object($string) && method_exists($string, '__toString'))) {
|
||||
trigger_error('mb_str_split() expects parameter 1 to be string, '.\gettype($string).' given', \E_USER_WARNING);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if (1 > $split_length = (int) $split_length) {
|
||||
if (80000 > \PHP_VERSION_ID) {
|
||||
trigger_error('The length of each segment must be greater than zero', \E_USER_WARNING);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
throw new \ValueError('Argument #2 ($length) must be greater than 0');
|
||||
}
|
||||
|
||||
if (null === $encoding) {
|
||||
$encoding = mb_internal_encoding();
|
||||
}
|
||||
|
||||
if ('UTF-8' === $encoding = self::getEncoding($encoding)) {
|
||||
$rx = '/(';
|
||||
while (65535 < $split_length) {
|
||||
$rx .= '.{65535}';
|
||||
$split_length -= 65535;
|
||||
}
|
||||
$rx .= '.{'.$split_length.'})/us';
|
||||
|
||||
return preg_split($rx, $string, -1, \PREG_SPLIT_DELIM_CAPTURE | \PREG_SPLIT_NO_EMPTY);
|
||||
}
|
||||
|
||||
$result = [];
|
||||
$length = mb_strlen($string, $encoding);
|
||||
|
||||
for ($i = 0; $i < $length; $i += $split_length) {
|
||||
$result[] = mb_substr($string, $i, $split_length, $encoding);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function mb_strtolower($s, $encoding = null)
|
||||
{
|
||||
return self::mb_convert_case($s, \MB_CASE_LOWER, $encoding);
|
||||
}
|
||||
|
||||
public static function mb_strtoupper($s, $encoding = null)
|
||||
{
|
||||
return self::mb_convert_case($s, \MB_CASE_UPPER, $encoding);
|
||||
}
|
||||
|
||||
public static function mb_substitute_character($c = null)
|
||||
{
|
||||
if (null === $c) {
|
||||
return 'none';
|
||||
}
|
||||
if (0 === strcasecmp($c, 'none')) {
|
||||
return true;
|
||||
}
|
||||
if (80000 > \PHP_VERSION_ID) {
|
||||
return false;
|
||||
}
|
||||
if (\is_int($c) || 'long' === $c || 'entity' === $c) {
|
||||
return false;
|
||||
}
|
||||
|
||||
throw new \ValueError('Argument #1 ($substitute_character) must be "none", "long", "entity" or a valid codepoint');
|
||||
}
|
||||
|
||||
public static function mb_substr($s, $start, $length = null, $encoding = null)
|
||||
{
|
||||
$encoding = self::getEncoding($encoding);
|
||||
if ('CP850' === $encoding || 'ASCII' === $encoding) {
|
||||
return (string) substr($s, $start, null === $length ? 2147483647 : $length);
|
||||
}
|
||||
|
||||
if ($start < 0) {
|
||||
$start = iconv_strlen($s, $encoding) + $start;
|
||||
if ($start < 0) {
|
||||
$start = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (null === $length) {
|
||||
$length = 2147483647;
|
||||
} elseif ($length < 0) {
|
||||
$length = iconv_strlen($s, $encoding) + $length - $start;
|
||||
if ($length < 0) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
return (string) iconv_substr($s, $start, $length, $encoding);
|
||||
}
|
||||
|
||||
public static function mb_stripos($haystack, $needle, $offset = 0, $encoding = null)
|
||||
{
|
||||
[$haystack, $needle] = str_replace(self::SIMPLE_CASE_FOLD[0], self::SIMPLE_CASE_FOLD[1], [
|
||||
self::mb_convert_case($haystack, \MB_CASE_LOWER, $encoding),
|
||||
self::mb_convert_case($needle, \MB_CASE_LOWER, $encoding),
|
||||
]);
|
||||
|
||||
return self::mb_strpos($haystack, $needle, $offset, $encoding);
|
||||
}
|
||||
|
||||
public static function mb_stristr($haystack, $needle, $part = false, $encoding = null)
|
||||
{
|
||||
$pos = self::mb_stripos($haystack, $needle, 0, $encoding);
|
||||
|
||||
return self::getSubpart($pos, $part, $haystack, $encoding);
|
||||
}
|
||||
|
||||
public static function mb_strrchr($haystack, $needle, $part = false, $encoding = null)
|
||||
{
|
||||
$encoding = self::getEncoding($encoding);
|
||||
if ('CP850' === $encoding || 'ASCII' === $encoding) {
|
||||
$pos = strrpos($haystack, $needle);
|
||||
} else {
|
||||
$needle = self::mb_substr($needle, 0, 1, $encoding);
|
||||
$pos = iconv_strrpos($haystack, $needle, $encoding);
|
||||
}
|
||||
|
||||
return self::getSubpart($pos, $part, $haystack, $encoding);
|
||||
}
|
||||
|
||||
public static function mb_strrichr($haystack, $needle, $part = false, $encoding = null)
|
||||
{
|
||||
$needle = self::mb_substr($needle, 0, 1, $encoding);
|
||||
$pos = self::mb_strripos($haystack, $needle, $encoding);
|
||||
|
||||
return self::getSubpart($pos, $part, $haystack, $encoding);
|
||||
}
|
||||
|
||||
public static function mb_strripos($haystack, $needle, $offset = 0, $encoding = null)
|
||||
{
|
||||
$haystack = self::mb_convert_case($haystack, \MB_CASE_LOWER, $encoding);
|
||||
$needle = self::mb_convert_case($needle, \MB_CASE_LOWER, $encoding);
|
||||
|
||||
$haystack = str_replace(self::SIMPLE_CASE_FOLD[0], self::SIMPLE_CASE_FOLD[1], $haystack);
|
||||
$needle = str_replace(self::SIMPLE_CASE_FOLD[0], self::SIMPLE_CASE_FOLD[1], $needle);
|
||||
|
||||
return self::mb_strrpos($haystack, $needle, $offset, $encoding);
|
||||
}
|
||||
|
||||
public static function mb_strstr($haystack, $needle, $part = false, $encoding = null)
|
||||
{
|
||||
$pos = strpos($haystack, $needle);
|
||||
if (false === $pos) {
|
||||
return false;
|
||||
}
|
||||
if ($part) {
|
||||
return substr($haystack, 0, $pos);
|
||||
}
|
||||
|
||||
return substr($haystack, $pos);
|
||||
}
|
||||
|
||||
public static function mb_get_info($type = 'all')
|
||||
{
|
||||
$info = [
|
||||
'internal_encoding' => self::$internalEncoding,
|
||||
'http_output' => 'pass',
|
||||
'http_output_conv_mimetypes' => '^(text/|application/xhtml\+xml)',
|
||||
'func_overload' => 0,
|
||||
'func_overload_list' => 'no overload',
|
||||
'mail_charset' => 'UTF-8',
|
||||
'mail_header_encoding' => 'BASE64',
|
||||
'mail_body_encoding' => 'BASE64',
|
||||
'illegal_chars' => 0,
|
||||
'encoding_translation' => 'Off',
|
||||
'language' => self::$language,
|
||||
'detect_order' => self::$encodingList,
|
||||
'substitute_character' => 'none',
|
||||
'strict_detection' => 'Off',
|
||||
];
|
||||
|
||||
if ('all' === $type) {
|
||||
return $info;
|
||||
}
|
||||
if (isset($info[$type])) {
|
||||
return $info[$type];
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function mb_http_input($type = '')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function mb_http_output($encoding = null)
|
||||
{
|
||||
return null !== $encoding ? 'pass' === $encoding : 'pass';
|
||||
}
|
||||
|
||||
public static function mb_strwidth($s, $encoding = null)
|
||||
{
|
||||
$encoding = self::getEncoding($encoding);
|
||||
|
||||
if ('UTF-8' !== $encoding) {
|
||||
$s = iconv($encoding, 'UTF-8//IGNORE', $s);
|
||||
}
|
||||
|
||||
$s = preg_replace('/[\x{1100}-\x{115F}\x{2329}\x{232A}\x{2E80}-\x{303E}\x{3040}-\x{A4CF}\x{AC00}-\x{D7A3}\x{F900}-\x{FAFF}\x{FE10}-\x{FE19}\x{FE30}-\x{FE6F}\x{FF00}-\x{FF60}\x{FFE0}-\x{FFE6}\x{20000}-\x{2FFFD}\x{30000}-\x{3FFFD}]/u', '', $s, -1, $wide);
|
||||
|
||||
return ($wide << 1) + iconv_strlen($s, 'UTF-8');
|
||||
}
|
||||
|
||||
public static function mb_substr_count($haystack, $needle, $encoding = null)
|
||||
{
|
||||
return substr_count($haystack, $needle);
|
||||
}
|
||||
|
||||
public static function mb_output_handler($contents, $status)
|
||||
{
|
||||
return $contents;
|
||||
}
|
||||
|
||||
public static function mb_chr($code, $encoding = null)
|
||||
{
|
||||
if (0x80 > $code %= 0x200000) {
|
||||
$s = \chr($code);
|
||||
} elseif (0x800 > $code) {
|
||||
$s = \chr(0xC0 | $code >> 6).\chr(0x80 | $code & 0x3F);
|
||||
} elseif (0x10000 > $code) {
|
||||
$s = \chr(0xE0 | $code >> 12).\chr(0x80 | $code >> 6 & 0x3F).\chr(0x80 | $code & 0x3F);
|
||||
} else {
|
||||
$s = \chr(0xF0 | $code >> 18).\chr(0x80 | $code >> 12 & 0x3F).\chr(0x80 | $code >> 6 & 0x3F).\chr(0x80 | $code & 0x3F);
|
||||
}
|
||||
|
||||
if ('UTF-8' !== $encoding = self::getEncoding($encoding)) {
|
||||
$s = mb_convert_encoding($s, $encoding, 'UTF-8');
|
||||
}
|
||||
|
||||
return $s;
|
||||
}
|
||||
|
||||
public static function mb_ord($s, $encoding = null)
|
||||
{
|
||||
if ('UTF-8' !== $encoding = self::getEncoding($encoding)) {
|
||||
$s = mb_convert_encoding($s, 'UTF-8', $encoding);
|
||||
}
|
||||
|
||||
if (1 === \strlen($s)) {
|
||||
return \ord($s);
|
||||
}
|
||||
|
||||
$code = ($s = unpack('C*', substr($s, 0, 4))) ? $s[1] : 0;
|
||||
if (0xF0 <= $code) {
|
||||
return (($code - 0xF0) << 18) + (($s[2] - 0x80) << 12) + (($s[3] - 0x80) << 6) + $s[4] - 0x80;
|
||||
}
|
||||
if (0xE0 <= $code) {
|
||||
return (($code - 0xE0) << 12) + (($s[2] - 0x80) << 6) + $s[3] - 0x80;
|
||||
}
|
||||
if (0xC0 <= $code) {
|
||||
return (($code - 0xC0) << 6) + $s[2] - 0x80;
|
||||
}
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
public static function mb_str_pad(string $string, int $length, string $pad_string = ' ', int $pad_type = \STR_PAD_RIGHT, ?string $encoding = null): string
|
||||
{
|
||||
if (!\in_array($pad_type, [\STR_PAD_RIGHT, \STR_PAD_LEFT, \STR_PAD_BOTH], true)) {
|
||||
throw new \ValueError('mb_str_pad(): Argument #4 ($pad_type) must be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH');
|
||||
}
|
||||
|
||||
if (null === $encoding) {
|
||||
$encoding = self::mb_internal_encoding();
|
||||
} else {
|
||||
self::assertEncoding($encoding, 'mb_str_pad(): Argument #5 ($encoding) must be a valid encoding, "%s" given');
|
||||
}
|
||||
|
||||
if (self::mb_strlen($pad_string, $encoding) <= 0) {
|
||||
throw new \ValueError('mb_str_pad(): Argument #3 ($pad_string) must be a non-empty string');
|
||||
}
|
||||
|
||||
$paddingRequired = $length - self::mb_strlen($string, $encoding);
|
||||
|
||||
if ($paddingRequired < 1) {
|
||||
return $string;
|
||||
}
|
||||
|
||||
switch ($pad_type) {
|
||||
case \STR_PAD_LEFT:
|
||||
return self::mb_substr(str_repeat($pad_string, $paddingRequired), 0, $paddingRequired, $encoding).$string;
|
||||
case \STR_PAD_RIGHT:
|
||||
return $string.self::mb_substr(str_repeat($pad_string, $paddingRequired), 0, $paddingRequired, $encoding);
|
||||
default:
|
||||
$leftPaddingLength = floor($paddingRequired / 2);
|
||||
$rightPaddingLength = $paddingRequired - $leftPaddingLength;
|
||||
|
||||
return self::mb_substr(str_repeat($pad_string, $leftPaddingLength), 0, $leftPaddingLength, $encoding).$string.self::mb_substr(str_repeat($pad_string, $rightPaddingLength), 0, $rightPaddingLength, $encoding);
|
||||
}
|
||||
}
|
||||
|
||||
public static function mb_ucfirst(string $string, ?string $encoding = null): string
|
||||
{
|
||||
if (null === $encoding) {
|
||||
$encoding = self::mb_internal_encoding();
|
||||
} else {
|
||||
self::assertEncoding($encoding, 'mb_ucfirst(): Argument #2 ($encoding) must be a valid encoding, "%s" given');
|
||||
}
|
||||
|
||||
$firstChar = mb_substr($string, 0, 1, $encoding);
|
||||
$firstChar = mb_convert_case($firstChar, \MB_CASE_TITLE, $encoding);
|
||||
|
||||
return $firstChar.mb_substr($string, 1, null, $encoding);
|
||||
}
|
||||
|
||||
public static function mb_lcfirst(string $string, ?string $encoding = null): string
|
||||
{
|
||||
if (null === $encoding) {
|
||||
$encoding = self::mb_internal_encoding();
|
||||
} else {
|
||||
self::assertEncoding($encoding, 'mb_lcfirst(): Argument #2 ($encoding) must be a valid encoding, "%s" given');
|
||||
}
|
||||
|
||||
$firstChar = mb_substr($string, 0, 1, $encoding);
|
||||
$firstChar = mb_convert_case($firstChar, \MB_CASE_LOWER, $encoding);
|
||||
|
||||
return $firstChar.mb_substr($string, 1, null, $encoding);
|
||||
}
|
||||
|
||||
private static function getSubpart($pos, $part, $haystack, $encoding)
|
||||
{
|
||||
if (false === $pos) {
|
||||
return false;
|
||||
}
|
||||
if ($part) {
|
||||
return self::mb_substr($haystack, 0, $pos, $encoding);
|
||||
}
|
||||
|
||||
return self::mb_substr($haystack, $pos, null, $encoding);
|
||||
}
|
||||
|
||||
private static function html_encoding_callback(array $m)
|
||||
{
|
||||
$i = 1;
|
||||
$entities = '';
|
||||
$m = unpack('C*', htmlentities($m[0], \ENT_COMPAT, 'UTF-8'));
|
||||
|
||||
while (isset($m[$i])) {
|
||||
if (0x80 > $m[$i]) {
|
||||
$entities .= \chr($m[$i++]);
|
||||
continue;
|
||||
}
|
||||
if (0xF0 <= $m[$i]) {
|
||||
$c = (($m[$i++] - 0xF0) << 18) + (($m[$i++] - 0x80) << 12) + (($m[$i++] - 0x80) << 6) + $m[$i++] - 0x80;
|
||||
} elseif (0xE0 <= $m[$i]) {
|
||||
$c = (($m[$i++] - 0xE0) << 12) + (($m[$i++] - 0x80) << 6) + $m[$i++] - 0x80;
|
||||
} else {
|
||||
$c = (($m[$i++] - 0xC0) << 6) + $m[$i++] - 0x80;
|
||||
}
|
||||
|
||||
$entities .= '&#'.$c.';';
|
||||
}
|
||||
|
||||
return $entities;
|
||||
}
|
||||
|
||||
private static function title_case(array $s)
|
||||
{
|
||||
return self::mb_convert_case($s[1], \MB_CASE_UPPER, 'UTF-8').self::mb_convert_case($s[2], \MB_CASE_LOWER, 'UTF-8');
|
||||
}
|
||||
|
||||
private static function getData($file)
|
||||
{
|
||||
if (file_exists($file = __DIR__.'/Resources/unidata/'.$file.'.php')) {
|
||||
return require $file;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static function getEncoding($encoding)
|
||||
{
|
||||
if (null === $encoding) {
|
||||
return self::$internalEncoding;
|
||||
}
|
||||
|
||||
if ('UTF-8' === $encoding) {
|
||||
return 'UTF-8';
|
||||
}
|
||||
|
||||
$encoding = strtoupper($encoding);
|
||||
|
||||
if ('8BIT' === $encoding || 'BINARY' === $encoding) {
|
||||
return 'CP850';
|
||||
}
|
||||
|
||||
if ('UTF8' === $encoding) {
|
||||
return 'UTF-8';
|
||||
}
|
||||
|
||||
return $encoding;
|
||||
}
|
||||
|
||||
private static function assertEncoding(string $encoding, string $errorFormat): void
|
||||
{
|
||||
try {
|
||||
$validEncoding = @self::mb_check_encoding('', $encoding);
|
||||
} catch (\ValueError $e) {
|
||||
throw new \ValueError(\sprintf($errorFormat, $encoding));
|
||||
}
|
||||
|
||||
// BC for PHP 7.3 and lower
|
||||
if (!$validEncoding) {
|
||||
throw new \ValueError(\sprintf($errorFormat, $encoding));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
Symfony Polyfill / Mbstring
|
||||
===========================
|
||||
|
||||
This component provides a partial, native PHP implementation for the
|
||||
[Mbstring](https://php.net/mbstring) extension.
|
||||
|
||||
More information can be found in the
|
||||
[main Polyfill README](https://github.com/symfony/polyfill/blob/main/README.md).
|
||||
|
||||
License
|
||||
=======
|
||||
|
||||
This library is released under the [MIT license](LICENSE).
|
|
@ -0,0 +1,119 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'İ' => 'i̇',
|
||||
'µ' => 'μ',
|
||||
'ſ' => 's',
|
||||
'ͅ' => 'ι',
|
||||
'ς' => 'σ',
|
||||
'ϐ' => 'β',
|
||||
'ϑ' => 'θ',
|
||||
'ϕ' => 'φ',
|
||||
'ϖ' => 'π',
|
||||
'ϰ' => 'κ',
|
||||
'ϱ' => 'ρ',
|
||||
'ϵ' => 'ε',
|
||||
'ẛ' => 'ṡ',
|
||||
'ι' => 'ι',
|
||||
'ß' => 'ss',
|
||||
'ʼn' => 'ʼn',
|
||||
'ǰ' => 'ǰ',
|
||||
'ΐ' => 'ΐ',
|
||||
'ΰ' => 'ΰ',
|
||||
'և' => 'եւ',
|
||||
'ẖ' => 'ẖ',
|
||||
'ẗ' => 'ẗ',
|
||||
'ẘ' => 'ẘ',
|
||||
'ẙ' => 'ẙ',
|
||||
'ẚ' => 'aʾ',
|
||||
'ẞ' => 'ss',
|
||||
'ὐ' => 'ὐ',
|
||||
'ὒ' => 'ὒ',
|
||||
'ὔ' => 'ὔ',
|
||||
'ὖ' => 'ὖ',
|
||||
'ᾀ' => 'ἀι',
|
||||
'ᾁ' => 'ἁι',
|
||||
'ᾂ' => 'ἂι',
|
||||
'ᾃ' => 'ἃι',
|
||||
'ᾄ' => 'ἄι',
|
||||
'ᾅ' => 'ἅι',
|
||||
'ᾆ' => 'ἆι',
|
||||
'ᾇ' => 'ἇι',
|
||||
'ᾈ' => 'ἀι',
|
||||
'ᾉ' => 'ἁι',
|
||||
'ᾊ' => 'ἂι',
|
||||
'ᾋ' => 'ἃι',
|
||||
'ᾌ' => 'ἄι',
|
||||
'ᾍ' => 'ἅι',
|
||||
'ᾎ' => 'ἆι',
|
||||
'ᾏ' => 'ἇι',
|
||||
'ᾐ' => 'ἠι',
|
||||
'ᾑ' => 'ἡι',
|
||||
'ᾒ' => 'ἢι',
|
||||
'ᾓ' => 'ἣι',
|
||||
'ᾔ' => 'ἤι',
|
||||
'ᾕ' => 'ἥι',
|
||||
'ᾖ' => 'ἦι',
|
||||
'ᾗ' => 'ἧι',
|
||||
'ᾘ' => 'ἠι',
|
||||
'ᾙ' => 'ἡι',
|
||||
'ᾚ' => 'ἢι',
|
||||
'ᾛ' => 'ἣι',
|
||||
'ᾜ' => 'ἤι',
|
||||
'ᾝ' => 'ἥι',
|
||||
'ᾞ' => 'ἦι',
|
||||
'ᾟ' => 'ἧι',
|
||||
'ᾠ' => 'ὠι',
|
||||
'ᾡ' => 'ὡι',
|
||||
'ᾢ' => 'ὢι',
|
||||
'ᾣ' => 'ὣι',
|
||||
'ᾤ' => 'ὤι',
|
||||
'ᾥ' => 'ὥι',
|
||||
'ᾦ' => 'ὦι',
|
||||
'ᾧ' => 'ὧι',
|
||||
'ᾨ' => 'ὠι',
|
||||
'ᾩ' => 'ὡι',
|
||||
'ᾪ' => 'ὢι',
|
||||
'ᾫ' => 'ὣι',
|
||||
'ᾬ' => 'ὤι',
|
||||
'ᾭ' => 'ὥι',
|
||||
'ᾮ' => 'ὦι',
|
||||
'ᾯ' => 'ὧι',
|
||||
'ᾲ' => 'ὰι',
|
||||
'ᾳ' => 'αι',
|
||||
'ᾴ' => 'άι',
|
||||
'ᾶ' => 'ᾶ',
|
||||
'ᾷ' => 'ᾶι',
|
||||
'ᾼ' => 'αι',
|
||||
'ῂ' => 'ὴι',
|
||||
'ῃ' => 'ηι',
|
||||
'ῄ' => 'ήι',
|
||||
'ῆ' => 'ῆ',
|
||||
'ῇ' => 'ῆι',
|
||||
'ῌ' => 'ηι',
|
||||
'ῒ' => 'ῒ',
|
||||
'ῖ' => 'ῖ',
|
||||
'ῗ' => 'ῗ',
|
||||
'ῢ' => 'ῢ',
|
||||
'ῤ' => 'ῤ',
|
||||
'ῦ' => 'ῦ',
|
||||
'ῧ' => 'ῧ',
|
||||
'ῲ' => 'ὼι',
|
||||
'ῳ' => 'ωι',
|
||||
'ῴ' => 'ώι',
|
||||
'ῶ' => 'ῶ',
|
||||
'ῷ' => 'ῶι',
|
||||
'ῼ' => 'ωι',
|
||||
'ff' => 'ff',
|
||||
'fi' => 'fi',
|
||||
'fl' => 'fl',
|
||||
'ffi' => 'ffi',
|
||||
'ffl' => 'ffl',
|
||||
'ſt' => 'st',
|
||||
'st' => 'st',
|
||||
'ﬓ' => 'մն',
|
||||
'ﬔ' => 'մե',
|
||||
'ﬕ' => 'մի',
|
||||
'ﬖ' => 'վն',
|
||||
'ﬗ' => 'մխ',
|
||||
];
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,159 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Symfony\Polyfill\Mbstring as p;
|
||||
|
||||
if (\PHP_VERSION_ID >= 80000) {
|
||||
return require __DIR__.'/bootstrap80.php';
|
||||
}
|
||||
|
||||
if (!function_exists('mb_convert_encoding')) {
|
||||
function mb_convert_encoding($string, $to_encoding, $from_encoding = null) { return p\Mbstring::mb_convert_encoding($string, $to_encoding, $from_encoding); }
|
||||
}
|
||||
if (!function_exists('mb_decode_mimeheader')) {
|
||||
function mb_decode_mimeheader($string) { return p\Mbstring::mb_decode_mimeheader($string); }
|
||||
}
|
||||
if (!function_exists('mb_encode_mimeheader')) {
|
||||
function mb_encode_mimeheader($string, $charset = null, $transfer_encoding = null, $newline = "\r\n", $indent = 0) { return p\Mbstring::mb_encode_mimeheader($string, $charset, $transfer_encoding, $newline, $indent); }
|
||||
}
|
||||
if (!function_exists('mb_decode_numericentity')) {
|
||||
function mb_decode_numericentity($string, $map, $encoding = null) { return p\Mbstring::mb_decode_numericentity($string, $map, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_encode_numericentity')) {
|
||||
function mb_encode_numericentity($string, $map, $encoding = null, $hex = false) { return p\Mbstring::mb_encode_numericentity($string, $map, $encoding, $hex); }
|
||||
}
|
||||
if (!function_exists('mb_convert_case')) {
|
||||
function mb_convert_case($string, $mode, $encoding = null) { return p\Mbstring::mb_convert_case($string, $mode, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_internal_encoding')) {
|
||||
function mb_internal_encoding($encoding = null) { return p\Mbstring::mb_internal_encoding($encoding); }
|
||||
}
|
||||
if (!function_exists('mb_language')) {
|
||||
function mb_language($language = null) { return p\Mbstring::mb_language($language); }
|
||||
}
|
||||
if (!function_exists('mb_list_encodings')) {
|
||||
function mb_list_encodings() { return p\Mbstring::mb_list_encodings(); }
|
||||
}
|
||||
if (!function_exists('mb_encoding_aliases')) {
|
||||
function mb_encoding_aliases($encoding) { return p\Mbstring::mb_encoding_aliases($encoding); }
|
||||
}
|
||||
if (!function_exists('mb_check_encoding')) {
|
||||
function mb_check_encoding($value = null, $encoding = null) { return p\Mbstring::mb_check_encoding($value, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_detect_encoding')) {
|
||||
function mb_detect_encoding($string, $encodings = null, $strict = false) { return p\Mbstring::mb_detect_encoding($string, $encodings, $strict); }
|
||||
}
|
||||
if (!function_exists('mb_detect_order')) {
|
||||
function mb_detect_order($encoding = null) { return p\Mbstring::mb_detect_order($encoding); }
|
||||
}
|
||||
if (!function_exists('mb_parse_str')) {
|
||||
function mb_parse_str($string, &$result = []) { parse_str($string, $result); return (bool) $result; }
|
||||
}
|
||||
if (!function_exists('mb_strlen')) {
|
||||
function mb_strlen($string, $encoding = null) { return p\Mbstring::mb_strlen($string, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_strpos')) {
|
||||
function mb_strpos($haystack, $needle, $offset = 0, $encoding = null) { return p\Mbstring::mb_strpos($haystack, $needle, $offset, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_strtolower')) {
|
||||
function mb_strtolower($string, $encoding = null) { return p\Mbstring::mb_strtolower($string, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_strtoupper')) {
|
||||
function mb_strtoupper($string, $encoding = null) { return p\Mbstring::mb_strtoupper($string, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_substitute_character')) {
|
||||
function mb_substitute_character($substitute_character = null) { return p\Mbstring::mb_substitute_character($substitute_character); }
|
||||
}
|
||||
if (!function_exists('mb_substr')) {
|
||||
function mb_substr($string, $start, $length = 2147483647, $encoding = null) { return p\Mbstring::mb_substr($string, $start, $length, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_stripos')) {
|
||||
function mb_stripos($haystack, $needle, $offset = 0, $encoding = null) { return p\Mbstring::mb_stripos($haystack, $needle, $offset, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_stristr')) {
|
||||
function mb_stristr($haystack, $needle, $before_needle = false, $encoding = null) { return p\Mbstring::mb_stristr($haystack, $needle, $before_needle, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_strrchr')) {
|
||||
function mb_strrchr($haystack, $needle, $before_needle = false, $encoding = null) { return p\Mbstring::mb_strrchr($haystack, $needle, $before_needle, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_strrichr')) {
|
||||
function mb_strrichr($haystack, $needle, $before_needle = false, $encoding = null) { return p\Mbstring::mb_strrichr($haystack, $needle, $before_needle, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_strripos')) {
|
||||
function mb_strripos($haystack, $needle, $offset = 0, $encoding = null) { return p\Mbstring::mb_strripos($haystack, $needle, $offset, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_strrpos')) {
|
||||
function mb_strrpos($haystack, $needle, $offset = 0, $encoding = null) { return p\Mbstring::mb_strrpos($haystack, $needle, $offset, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_strstr')) {
|
||||
function mb_strstr($haystack, $needle, $before_needle = false, $encoding = null) { return p\Mbstring::mb_strstr($haystack, $needle, $before_needle, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_get_info')) {
|
||||
function mb_get_info($type = 'all') { return p\Mbstring::mb_get_info($type); }
|
||||
}
|
||||
if (!function_exists('mb_http_output')) {
|
||||
function mb_http_output($encoding = null) { return p\Mbstring::mb_http_output($encoding); }
|
||||
}
|
||||
if (!function_exists('mb_strwidth')) {
|
||||
function mb_strwidth($string, $encoding = null) { return p\Mbstring::mb_strwidth($string, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_substr_count')) {
|
||||
function mb_substr_count($haystack, $needle, $encoding = null) { return p\Mbstring::mb_substr_count($haystack, $needle, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_output_handler')) {
|
||||
function mb_output_handler($string, $status) { return p\Mbstring::mb_output_handler($string, $status); }
|
||||
}
|
||||
if (!function_exists('mb_http_input')) {
|
||||
function mb_http_input($type = null) { return p\Mbstring::mb_http_input($type); }
|
||||
}
|
||||
|
||||
if (!function_exists('mb_convert_variables')) {
|
||||
function mb_convert_variables($to_encoding, $from_encoding, &...$vars) { return p\Mbstring::mb_convert_variables($to_encoding, $from_encoding, ...$vars); }
|
||||
}
|
||||
|
||||
if (!function_exists('mb_ord')) {
|
||||
function mb_ord($string, $encoding = null) { return p\Mbstring::mb_ord($string, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_chr')) {
|
||||
function mb_chr($codepoint, $encoding = null) { return p\Mbstring::mb_chr($codepoint, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_scrub')) {
|
||||
function mb_scrub($string, $encoding = null) { $encoding = null === $encoding ? mb_internal_encoding() : $encoding; return mb_convert_encoding($string, $encoding, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_str_split')) {
|
||||
function mb_str_split($string, $length = 1, $encoding = null) { return p\Mbstring::mb_str_split($string, $length, $encoding); }
|
||||
}
|
||||
|
||||
if (!function_exists('mb_str_pad')) {
|
||||
function mb_str_pad(string $string, int $length, string $pad_string = ' ', int $pad_type = STR_PAD_RIGHT, ?string $encoding = null): string { return p\Mbstring::mb_str_pad($string, $length, $pad_string, $pad_type, $encoding); }
|
||||
}
|
||||
|
||||
if (!function_exists('mb_ucfirst')) {
|
||||
function mb_ucfirst(string $string, ?string $encoding = null): string { return p\Mbstring::mb_ucfirst($string, $encoding); }
|
||||
}
|
||||
|
||||
if (!function_exists('mb_lcfirst')) {
|
||||
function mb_lcfirst(string $string, ?string $encoding = null): string { return p\Mbstring::mb_lcfirst($string, $encoding); }
|
||||
}
|
||||
|
||||
if (extension_loaded('mbstring')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!defined('MB_CASE_UPPER')) {
|
||||
define('MB_CASE_UPPER', 0);
|
||||
}
|
||||
if (!defined('MB_CASE_LOWER')) {
|
||||
define('MB_CASE_LOWER', 1);
|
||||
}
|
||||
if (!defined('MB_CASE_TITLE')) {
|
||||
define('MB_CASE_TITLE', 2);
|
||||
}
|
|
@ -0,0 +1,155 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Symfony\Polyfill\Mbstring as p;
|
||||
|
||||
if (!function_exists('mb_convert_encoding')) {
|
||||
function mb_convert_encoding(array|string|null $string, ?string $to_encoding, array|string|null $from_encoding = null): array|string|false { return p\Mbstring::mb_convert_encoding($string ?? '', (string) $to_encoding, $from_encoding); }
|
||||
}
|
||||
if (!function_exists('mb_decode_mimeheader')) {
|
||||
function mb_decode_mimeheader(?string $string): string { return p\Mbstring::mb_decode_mimeheader((string) $string); }
|
||||
}
|
||||
if (!function_exists('mb_encode_mimeheader')) {
|
||||
function mb_encode_mimeheader(?string $string, ?string $charset = null, ?string $transfer_encoding = null, ?string $newline = "\r\n", ?int $indent = 0): string { return p\Mbstring::mb_encode_mimeheader((string) $string, $charset, $transfer_encoding, (string) $newline, (int) $indent); }
|
||||
}
|
||||
if (!function_exists('mb_decode_numericentity')) {
|
||||
function mb_decode_numericentity(?string $string, array $map, ?string $encoding = null): string { return p\Mbstring::mb_decode_numericentity((string) $string, $map, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_encode_numericentity')) {
|
||||
function mb_encode_numericentity(?string $string, array $map, ?string $encoding = null, ?bool $hex = false): string { return p\Mbstring::mb_encode_numericentity((string) $string, $map, $encoding, (bool) $hex); }
|
||||
}
|
||||
if (!function_exists('mb_convert_case')) {
|
||||
function mb_convert_case(?string $string, ?int $mode, ?string $encoding = null): string { return p\Mbstring::mb_convert_case((string) $string, (int) $mode, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_internal_encoding')) {
|
||||
function mb_internal_encoding(?string $encoding = null): string|bool { return p\Mbstring::mb_internal_encoding($encoding); }
|
||||
}
|
||||
if (!function_exists('mb_language')) {
|
||||
function mb_language(?string $language = null): string|bool { return p\Mbstring::mb_language($language); }
|
||||
}
|
||||
if (!function_exists('mb_list_encodings')) {
|
||||
function mb_list_encodings(): array { return p\Mbstring::mb_list_encodings(); }
|
||||
}
|
||||
if (!function_exists('mb_encoding_aliases')) {
|
||||
function mb_encoding_aliases(?string $encoding): array { return p\Mbstring::mb_encoding_aliases((string) $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_check_encoding')) {
|
||||
function mb_check_encoding(array|string|null $value = null, ?string $encoding = null): bool { return p\Mbstring::mb_check_encoding($value, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_detect_encoding')) {
|
||||
function mb_detect_encoding(?string $string, array|string|null $encodings = null, ?bool $strict = false): string|false { return p\Mbstring::mb_detect_encoding((string) $string, $encodings, (bool) $strict); }
|
||||
}
|
||||
if (!function_exists('mb_detect_order')) {
|
||||
function mb_detect_order(array|string|null $encoding = null): array|bool { return p\Mbstring::mb_detect_order($encoding); }
|
||||
}
|
||||
if (!function_exists('mb_parse_str')) {
|
||||
function mb_parse_str(?string $string, &$result = []): bool { parse_str((string) $string, $result); return (bool) $result; }
|
||||
}
|
||||
if (!function_exists('mb_strlen')) {
|
||||
function mb_strlen(?string $string, ?string $encoding = null): int { return p\Mbstring::mb_strlen((string) $string, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_strpos')) {
|
||||
function mb_strpos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { return p\Mbstring::mb_strpos((string) $haystack, (string) $needle, (int) $offset, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_strtolower')) {
|
||||
function mb_strtolower(?string $string, ?string $encoding = null): string { return p\Mbstring::mb_strtolower((string) $string, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_strtoupper')) {
|
||||
function mb_strtoupper(?string $string, ?string $encoding = null): string { return p\Mbstring::mb_strtoupper((string) $string, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_substitute_character')) {
|
||||
function mb_substitute_character(string|int|null $substitute_character = null): string|int|bool { return p\Mbstring::mb_substitute_character($substitute_character); }
|
||||
}
|
||||
if (!function_exists('mb_substr')) {
|
||||
function mb_substr(?string $string, ?int $start, ?int $length = null, ?string $encoding = null): string { return p\Mbstring::mb_substr((string) $string, (int) $start, $length, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_stripos')) {
|
||||
function mb_stripos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { return p\Mbstring::mb_stripos((string) $haystack, (string) $needle, (int) $offset, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_stristr')) {
|
||||
function mb_stristr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null): string|false { return p\Mbstring::mb_stristr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_strrchr')) {
|
||||
function mb_strrchr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null): string|false { return p\Mbstring::mb_strrchr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_strrichr')) {
|
||||
function mb_strrichr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null): string|false { return p\Mbstring::mb_strrichr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_strripos')) {
|
||||
function mb_strripos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { return p\Mbstring::mb_strripos((string) $haystack, (string) $needle, (int) $offset, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_strrpos')) {
|
||||
function mb_strrpos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { return p\Mbstring::mb_strrpos((string) $haystack, (string) $needle, (int) $offset, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_strstr')) {
|
||||
function mb_strstr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null): string|false { return p\Mbstring::mb_strstr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_get_info')) {
|
||||
function mb_get_info(?string $type = 'all'): array|string|int|false { return p\Mbstring::mb_get_info((string) $type); }
|
||||
}
|
||||
if (!function_exists('mb_http_output')) {
|
||||
function mb_http_output(?string $encoding = null): string|bool { return p\Mbstring::mb_http_output($encoding); }
|
||||
}
|
||||
if (!function_exists('mb_strwidth')) {
|
||||
function mb_strwidth(?string $string, ?string $encoding = null): int { return p\Mbstring::mb_strwidth((string) $string, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_substr_count')) {
|
||||
function mb_substr_count(?string $haystack, ?string $needle, ?string $encoding = null): int { return p\Mbstring::mb_substr_count((string) $haystack, (string) $needle, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_output_handler')) {
|
||||
function mb_output_handler(?string $string, ?int $status): string { return p\Mbstring::mb_output_handler((string) $string, (int) $status); }
|
||||
}
|
||||
if (!function_exists('mb_http_input')) {
|
||||
function mb_http_input(?string $type = null): array|string|false { return p\Mbstring::mb_http_input($type); }
|
||||
}
|
||||
|
||||
if (!function_exists('mb_convert_variables')) {
|
||||
function mb_convert_variables(?string $to_encoding, array|string|null $from_encoding, mixed &$var, mixed &...$vars): string|false { return p\Mbstring::mb_convert_variables((string) $to_encoding, $from_encoding ?? '', $var, ...$vars); }
|
||||
}
|
||||
|
||||
if (!function_exists('mb_ord')) {
|
||||
function mb_ord(?string $string, ?string $encoding = null): int|false { return p\Mbstring::mb_ord((string) $string, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_chr')) {
|
||||
function mb_chr(?int $codepoint, ?string $encoding = null): string|false { return p\Mbstring::mb_chr((int) $codepoint, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_scrub')) {
|
||||
function mb_scrub(?string $string, ?string $encoding = null): string { $encoding ??= mb_internal_encoding(); return mb_convert_encoding((string) $string, $encoding, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_str_split')) {
|
||||
function mb_str_split(?string $string, ?int $length = 1, ?string $encoding = null): array { return p\Mbstring::mb_str_split((string) $string, (int) $length, $encoding); }
|
||||
}
|
||||
|
||||
if (!function_exists('mb_str_pad')) {
|
||||
function mb_str_pad(string $string, int $length, string $pad_string = ' ', int $pad_type = STR_PAD_RIGHT, ?string $encoding = null): string { return p\Mbstring::mb_str_pad($string, $length, $pad_string, $pad_type, $encoding); }
|
||||
}
|
||||
|
||||
if (!function_exists('mb_ucfirst')) {
|
||||
function mb_ucfirst($string, ?string $encoding = null): string { return p\Mbstring::mb_ucfirst($string, $encoding); }
|
||||
}
|
||||
|
||||
if (!function_exists('mb_lcfirst')) {
|
||||
function mb_lcfirst($string, ?string $encoding = null): string { return p\Mbstring::mb_lcfirst($string, $encoding); }
|
||||
}
|
||||
|
||||
if (extension_loaded('mbstring')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!defined('MB_CASE_UPPER')) {
|
||||
define('MB_CASE_UPPER', 0);
|
||||
}
|
||||
if (!defined('MB_CASE_LOWER')) {
|
||||
define('MB_CASE_LOWER', 1);
|
||||
}
|
||||
if (!defined('MB_CASE_TITLE')) {
|
||||
define('MB_CASE_TITLE', 2);
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
{
|
||||
"name": "symfony/polyfill-mbstring",
|
||||
"type": "library",
|
||||
"description": "Symfony polyfill for the Mbstring extension",
|
||||
"keywords": ["polyfill", "shim", "compatibility", "portable", "mbstring"],
|
||||
"homepage": "https://symfony.com",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nicolas Grekas",
|
||||
"email": "p@tchwork.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.1"
|
||||
},
|
||||
"provide": {
|
||||
"ext-mbstring": "*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": { "Symfony\\Polyfill\\Mbstring\\": "" },
|
||||
"files": [ "bootstrap.php" ]
|
||||
},
|
||||
"suggest": {
|
||||
"ext-mbstring": "For best performance"
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"extra": {
|
||||
"thanks": {
|
||||
"name": "symfony/polyfill",
|
||||
"url": "https://github.com/symfony/polyfill"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
Copyright (c) 2020-present Fabien Potencier
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
|
@ -0,0 +1,115 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Polyfill\Php80;
|
||||
|
||||
/**
|
||||
* @author Ion Bazan <ion.bazan@gmail.com>
|
||||
* @author Nico Oelgart <nicoswd@gmail.com>
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
final class Php80
|
||||
{
|
||||
public static function fdiv(float $dividend, float $divisor): float
|
||||
{
|
||||
return @($dividend / $divisor);
|
||||
}
|
||||
|
||||
public static function get_debug_type($value): string
|
||||
{
|
||||
switch (true) {
|
||||
case null === $value: return 'null';
|
||||
case \is_bool($value): return 'bool';
|
||||
case \is_string($value): return 'string';
|
||||
case \is_array($value): return 'array';
|
||||
case \is_int($value): return 'int';
|
||||
case \is_float($value): return 'float';
|
||||
case \is_object($value): break;
|
||||
case $value instanceof \__PHP_Incomplete_Class: return '__PHP_Incomplete_Class';
|
||||
default:
|
||||
if (null === $type = @get_resource_type($value)) {
|
||||
return 'unknown';
|
||||
}
|
||||
|
||||
if ('Unknown' === $type) {
|
||||
$type = 'closed';
|
||||
}
|
||||
|
||||
return "resource ($type)";
|
||||
}
|
||||
|
||||
$class = \get_class($value);
|
||||
|
||||
if (false === strpos($class, '@')) {
|
||||
return $class;
|
||||
}
|
||||
|
||||
return (get_parent_class($class) ?: key(class_implements($class)) ?: 'class').'@anonymous';
|
||||
}
|
||||
|
||||
public static function get_resource_id($res): int
|
||||
{
|
||||
if (!\is_resource($res) && null === @get_resource_type($res)) {
|
||||
throw new \TypeError(sprintf('Argument 1 passed to get_resource_id() must be of the type resource, %s given', get_debug_type($res)));
|
||||
}
|
||||
|
||||
return (int) $res;
|
||||
}
|
||||
|
||||
public static function preg_last_error_msg(): string
|
||||
{
|
||||
switch (preg_last_error()) {
|
||||
case \PREG_INTERNAL_ERROR:
|
||||
return 'Internal error';
|
||||
case \PREG_BAD_UTF8_ERROR:
|
||||
return 'Malformed UTF-8 characters, possibly incorrectly encoded';
|
||||
case \PREG_BAD_UTF8_OFFSET_ERROR:
|
||||
return 'The offset did not correspond to the beginning of a valid UTF-8 code point';
|
||||
case \PREG_BACKTRACK_LIMIT_ERROR:
|
||||
return 'Backtrack limit exhausted';
|
||||
case \PREG_RECURSION_LIMIT_ERROR:
|
||||
return 'Recursion limit exhausted';
|
||||
case \PREG_JIT_STACKLIMIT_ERROR:
|
||||
return 'JIT stack limit exhausted';
|
||||
case \PREG_NO_ERROR:
|
||||
return 'No error';
|
||||
default:
|
||||
return 'Unknown error';
|
||||
}
|
||||
}
|
||||
|
||||
public static function str_contains(string $haystack, string $needle): bool
|
||||
{
|
||||
return '' === $needle || false !== strpos($haystack, $needle);
|
||||
}
|
||||
|
||||
public static function str_starts_with(string $haystack, string $needle): bool
|
||||
{
|
||||
return 0 === strncmp($haystack, $needle, \strlen($needle));
|
||||
}
|
||||
|
||||
public static function str_ends_with(string $haystack, string $needle): bool
|
||||
{
|
||||
if ('' === $needle || $needle === $haystack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ('' === $haystack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$needleLength = \strlen($needle);
|
||||
|
||||
return $needleLength <= \strlen($haystack) && 0 === substr_compare($haystack, $needle, -$needleLength);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,103 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Polyfill\Php80;
|
||||
|
||||
/**
|
||||
* @author Fedonyuk Anton <info@ensostudio.ru>
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class PhpToken implements \Stringable
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $text;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $line;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $pos;
|
||||
|
||||
public function __construct(int $id, string $text, int $line = -1, int $position = -1)
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->text = $text;
|
||||
$this->line = $line;
|
||||
$this->pos = $position;
|
||||
}
|
||||
|
||||
public function getTokenName(): ?string
|
||||
{
|
||||
if ('UNKNOWN' === $name = token_name($this->id)) {
|
||||
$name = \strlen($this->text) > 1 || \ord($this->text) < 32 ? null : $this->text;
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|string|array $kind
|
||||
*/
|
||||
public function is($kind): bool
|
||||
{
|
||||
foreach ((array) $kind as $value) {
|
||||
if (\in_array($value, [$this->id, $this->text], true)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isIgnorable(): bool
|
||||
{
|
||||
return \in_array($this->id, [\T_WHITESPACE, \T_COMMENT, \T_DOC_COMMENT, \T_OPEN_TAG], true);
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return (string) $this->text;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return static[]
|
||||
*/
|
||||
public static function tokenize(string $code, int $flags = 0): array
|
||||
{
|
||||
$line = 1;
|
||||
$position = 0;
|
||||
$tokens = token_get_all($code, $flags);
|
||||
foreach ($tokens as $index => $token) {
|
||||
if (\is_string($token)) {
|
||||
$id = \ord($token);
|
||||
$text = $token;
|
||||
} else {
|
||||
[$id, $text, $line] = $token;
|
||||
}
|
||||
$tokens[$index] = new static($id, $text, $line, $position);
|
||||
$position += \strlen($text);
|
||||
}
|
||||
|
||||
return $tokens;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
Symfony Polyfill / Php80
|
||||
========================
|
||||
|
||||
This component provides features added to PHP 8.0 core:
|
||||
|
||||
- [`Stringable`](https://php.net/stringable) interface
|
||||
- [`fdiv`](https://php.net/fdiv)
|
||||
- [`ValueError`](https://php.net/valueerror) class
|
||||
- [`UnhandledMatchError`](https://php.net/unhandledmatcherror) class
|
||||
- `FILTER_VALIDATE_BOOL` constant
|
||||
- [`get_debug_type`](https://php.net/get_debug_type)
|
||||
- [`PhpToken`](https://php.net/phptoken) class
|
||||
- [`preg_last_error_msg`](https://php.net/preg_last_error_msg)
|
||||
- [`str_contains`](https://php.net/str_contains)
|
||||
- [`str_starts_with`](https://php.net/str_starts_with)
|
||||
- [`str_ends_with`](https://php.net/str_ends_with)
|
||||
- [`get_resource_id`](https://php.net/get_resource_id)
|
||||
|
||||
More information can be found in the
|
||||
[main Polyfill README](https://github.com/symfony/polyfill/blob/main/README.md).
|
||||
|
||||
License
|
||||
=======
|
||||
|
||||
This library is released under the [MIT license](LICENSE).
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
#[Attribute(Attribute::TARGET_CLASS)]
|
||||
final class Attribute
|
||||
{
|
||||
public const TARGET_CLASS = 1;
|
||||
public const TARGET_FUNCTION = 2;
|
||||
public const TARGET_METHOD = 4;
|
||||
public const TARGET_PROPERTY = 8;
|
||||
public const TARGET_CLASS_CONSTANT = 16;
|
||||
public const TARGET_PARAMETER = 32;
|
||||
public const TARGET_ALL = 63;
|
||||
public const IS_REPEATABLE = 64;
|
||||
|
||||
/** @var int */
|
||||
public $flags;
|
||||
|
||||
public function __construct(int $flags = self::TARGET_ALL)
|
||||
{
|
||||
$this->flags = $flags;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
if (\PHP_VERSION_ID < 80000 && extension_loaded('tokenizer')) {
|
||||
class PhpToken extends Symfony\Polyfill\Php80\PhpToken
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
if (\PHP_VERSION_ID < 80000) {
|
||||
interface Stringable
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function __toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
if (\PHP_VERSION_ID < 80000) {
|
||||
class UnhandledMatchError extends Error
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
if (\PHP_VERSION_ID < 80000) {
|
||||
class ValueError extends Error
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Symfony\Polyfill\Php80 as p;
|
||||
|
||||
if (\PHP_VERSION_ID >= 80000) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!defined('FILTER_VALIDATE_BOOL') && defined('FILTER_VALIDATE_BOOLEAN')) {
|
||||
define('FILTER_VALIDATE_BOOL', \FILTER_VALIDATE_BOOLEAN);
|
||||
}
|
||||
|
||||
if (!function_exists('fdiv')) {
|
||||
function fdiv(float $num1, float $num2): float { return p\Php80::fdiv($num1, $num2); }
|
||||
}
|
||||
if (!function_exists('preg_last_error_msg')) {
|
||||
function preg_last_error_msg(): string { return p\Php80::preg_last_error_msg(); }
|
||||
}
|
||||
if (!function_exists('str_contains')) {
|
||||
function str_contains(?string $haystack, ?string $needle): bool { return p\Php80::str_contains($haystack ?? '', $needle ?? ''); }
|
||||
}
|
||||
if (!function_exists('str_starts_with')) {
|
||||
function str_starts_with(?string $haystack, ?string $needle): bool { return p\Php80::str_starts_with($haystack ?? '', $needle ?? ''); }
|
||||
}
|
||||
if (!function_exists('str_ends_with')) {
|
||||
function str_ends_with(?string $haystack, ?string $needle): bool { return p\Php80::str_ends_with($haystack ?? '', $needle ?? ''); }
|
||||
}
|
||||
if (!function_exists('get_debug_type')) {
|
||||
function get_debug_type($value): string { return p\Php80::get_debug_type($value); }
|
||||
}
|
||||
if (!function_exists('get_resource_id')) {
|
||||
function get_resource_id($resource): int { return p\Php80::get_resource_id($resource); }
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
{
|
||||
"name": "symfony/polyfill-php80",
|
||||
"type": "library",
|
||||
"description": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions",
|
||||
"keywords": ["polyfill", "shim", "compatibility", "portable"],
|
||||
"homepage": "https://symfony.com",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Ion Bazan",
|
||||
"email": "ion.bazan@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Nicolas Grekas",
|
||||
"email": "p@tchwork.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.1"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": { "Symfony\\Polyfill\\Php80\\": "" },
|
||||
"files": [ "bootstrap.php" ],
|
||||
"classmap": [ "Resources/stubs" ]
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"extra": {
|
||||
"thanks": {
|
||||
"name": "symfony/polyfill",
|
||||
"url": "https://github.com/symfony/polyfill"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
BSD 3-Clause License
|
||||
|
||||
Copyright (c) 2014, Graham Campbell.
|
||||
Copyright (c) 2013, Vance Lucas.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@ -0,0 +1,60 @@
|
|||
{
|
||||
"name": "vlucas/phpdotenv",
|
||||
"description": "Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.",
|
||||
"keywords": ["env", "dotenv", "environment"],
|
||||
"license": "BSD-3-Clause",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Graham Campbell",
|
||||
"email": "hello@gjcampbell.co.uk",
|
||||
"homepage": "https://github.com/GrahamCampbell"
|
||||
},
|
||||
{
|
||||
"name": "Vance Lucas",
|
||||
"email": "vance@vancelucas.com",
|
||||
"homepage": "https://github.com/vlucas"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.2.5 || ^8.0",
|
||||
"ext-pcre": "*",
|
||||
"graham-campbell/result-type": "^1.1.3",
|
||||
"phpoption/phpoption": "^1.9.3",
|
||||
"symfony/polyfill-ctype": "^1.24",
|
||||
"symfony/polyfill-mbstring": "^1.24",
|
||||
"symfony/polyfill-php80": "^1.24"
|
||||
},
|
||||
"require-dev": {
|
||||
"ext-filter": "*",
|
||||
"bamarni/composer-bin-plugin": "^1.8.2",
|
||||
"phpunit/phpunit":"^8.5.34 || ^9.6.13 || ^10.4.2"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Dotenv\\": "src/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Dotenv\\Tests\\": "tests/Dotenv/"
|
||||
}
|
||||
},
|
||||
"suggest": {
|
||||
"ext-filter": "Required to use the boolean validator."
|
||||
},
|
||||
"config": {
|
||||
"allow-plugins": {
|
||||
"bamarni/composer-bin-plugin": true
|
||||
},
|
||||
"preferred-install": "dist"
|
||||
},
|
||||
"extra": {
|
||||
"bamarni-bin": {
|
||||
"bin-links": true,
|
||||
"forward-command": false
|
||||
},
|
||||
"branch-alias": {
|
||||
"dev-master": "5.6-dev"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,267 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv;
|
||||
|
||||
use Dotenv\Exception\InvalidPathException;
|
||||
use Dotenv\Loader\Loader;
|
||||
use Dotenv\Loader\LoaderInterface;
|
||||
use Dotenv\Parser\Parser;
|
||||
use Dotenv\Parser\ParserInterface;
|
||||
use Dotenv\Repository\Adapter\ArrayAdapter;
|
||||
use Dotenv\Repository\Adapter\PutenvAdapter;
|
||||
use Dotenv\Repository\RepositoryBuilder;
|
||||
use Dotenv\Repository\RepositoryInterface;
|
||||
use Dotenv\Store\StoreBuilder;
|
||||
use Dotenv\Store\StoreInterface;
|
||||
use Dotenv\Store\StringStore;
|
||||
|
||||
class Dotenv
|
||||
{
|
||||
/**
|
||||
* The store instance.
|
||||
*
|
||||
* @var \Dotenv\Store\StoreInterface
|
||||
*/
|
||||
private $store;
|
||||
|
||||
/**
|
||||
* The parser instance.
|
||||
*
|
||||
* @var \Dotenv\Parser\ParserInterface
|
||||
*/
|
||||
private $parser;
|
||||
|
||||
/**
|
||||
* The loader instance.
|
||||
*
|
||||
* @var \Dotenv\Loader\LoaderInterface
|
||||
*/
|
||||
private $loader;
|
||||
|
||||
/**
|
||||
* The repository instance.
|
||||
*
|
||||
* @var \Dotenv\Repository\RepositoryInterface
|
||||
*/
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* Create a new dotenv instance.
|
||||
*
|
||||
* @param \Dotenv\Store\StoreInterface $store
|
||||
* @param \Dotenv\Parser\ParserInterface $parser
|
||||
* @param \Dotenv\Loader\LoaderInterface $loader
|
||||
* @param \Dotenv\Repository\RepositoryInterface $repository
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(
|
||||
StoreInterface $store,
|
||||
ParserInterface $parser,
|
||||
LoaderInterface $loader,
|
||||
RepositoryInterface $repository
|
||||
) {
|
||||
$this->store = $store;
|
||||
$this->parser = $parser;
|
||||
$this->loader = $loader;
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new dotenv instance.
|
||||
*
|
||||
* @param \Dotenv\Repository\RepositoryInterface $repository
|
||||
* @param string|string[] $paths
|
||||
* @param string|string[]|null $names
|
||||
* @param bool $shortCircuit
|
||||
* @param string|null $fileEncoding
|
||||
*
|
||||
* @return \Dotenv\Dotenv
|
||||
*/
|
||||
public static function create(RepositoryInterface $repository, $paths, $names = null, bool $shortCircuit = true, ?string $fileEncoding = null)
|
||||
{
|
||||
$builder = $names === null ? StoreBuilder::createWithDefaultName() : StoreBuilder::createWithNoNames();
|
||||
|
||||
foreach ((array) $paths as $path) {
|
||||
$builder = $builder->addPath($path);
|
||||
}
|
||||
|
||||
foreach ((array) $names as $name) {
|
||||
$builder = $builder->addName($name);
|
||||
}
|
||||
|
||||
if ($shortCircuit) {
|
||||
$builder = $builder->shortCircuit();
|
||||
}
|
||||
|
||||
return new self($builder->fileEncoding($fileEncoding)->make(), new Parser(), new Loader(), $repository);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new mutable dotenv instance with default repository.
|
||||
*
|
||||
* @param string|string[] $paths
|
||||
* @param string|string[]|null $names
|
||||
* @param bool $shortCircuit
|
||||
* @param string|null $fileEncoding
|
||||
*
|
||||
* @return \Dotenv\Dotenv
|
||||
*/
|
||||
public static function createMutable($paths, $names = null, bool $shortCircuit = true, ?string $fileEncoding = null)
|
||||
{
|
||||
$repository = RepositoryBuilder::createWithDefaultAdapters()->make();
|
||||
|
||||
return self::create($repository, $paths, $names, $shortCircuit, $fileEncoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new mutable dotenv instance with default repository with the putenv adapter.
|
||||
*
|
||||
* @param string|string[] $paths
|
||||
* @param string|string[]|null $names
|
||||
* @param bool $shortCircuit
|
||||
* @param string|null $fileEncoding
|
||||
*
|
||||
* @return \Dotenv\Dotenv
|
||||
*/
|
||||
public static function createUnsafeMutable($paths, $names = null, bool $shortCircuit = true, ?string $fileEncoding = null)
|
||||
{
|
||||
$repository = RepositoryBuilder::createWithDefaultAdapters()
|
||||
->addAdapter(PutenvAdapter::class)
|
||||
->make();
|
||||
|
||||
return self::create($repository, $paths, $names, $shortCircuit, $fileEncoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new immutable dotenv instance with default repository.
|
||||
*
|
||||
* @param string|string[] $paths
|
||||
* @param string|string[]|null $names
|
||||
* @param bool $shortCircuit
|
||||
* @param string|null $fileEncoding
|
||||
*
|
||||
* @return \Dotenv\Dotenv
|
||||
*/
|
||||
public static function createImmutable($paths, $names = null, bool $shortCircuit = true, ?string $fileEncoding = null)
|
||||
{
|
||||
$repository = RepositoryBuilder::createWithDefaultAdapters()->immutable()->make();
|
||||
|
||||
return self::create($repository, $paths, $names, $shortCircuit, $fileEncoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new immutable dotenv instance with default repository with the putenv adapter.
|
||||
*
|
||||
* @param string|string[] $paths
|
||||
* @param string|string[]|null $names
|
||||
* @param bool $shortCircuit
|
||||
* @param string|null $fileEncoding
|
||||
*
|
||||
* @return \Dotenv\Dotenv
|
||||
*/
|
||||
public static function createUnsafeImmutable($paths, $names = null, bool $shortCircuit = true, ?string $fileEncoding = null)
|
||||
{
|
||||
$repository = RepositoryBuilder::createWithDefaultAdapters()
|
||||
->addAdapter(PutenvAdapter::class)
|
||||
->immutable()
|
||||
->make();
|
||||
|
||||
return self::create($repository, $paths, $names, $shortCircuit, $fileEncoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new dotenv instance with an array backed repository.
|
||||
*
|
||||
* @param string|string[] $paths
|
||||
* @param string|string[]|null $names
|
||||
* @param bool $shortCircuit
|
||||
* @param string|null $fileEncoding
|
||||
*
|
||||
* @return \Dotenv\Dotenv
|
||||
*/
|
||||
public static function createArrayBacked($paths, $names = null, bool $shortCircuit = true, ?string $fileEncoding = null)
|
||||
{
|
||||
$repository = RepositoryBuilder::createWithNoAdapters()->addAdapter(ArrayAdapter::class)->make();
|
||||
|
||||
return self::create($repository, $paths, $names, $shortCircuit, $fileEncoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the given content and resolve nested variables.
|
||||
*
|
||||
* This method behaves just like load(), only without mutating your actual
|
||||
* environment. We do this by using an array backed repository.
|
||||
*
|
||||
* @param string $content
|
||||
*
|
||||
* @throws \Dotenv\Exception\InvalidFileException
|
||||
*
|
||||
* @return array<string,string|null>
|
||||
*/
|
||||
public static function parse(string $content)
|
||||
{
|
||||
$repository = RepositoryBuilder::createWithNoAdapters()->addAdapter(ArrayAdapter::class)->make();
|
||||
|
||||
$phpdotenv = new self(new StringStore($content), new Parser(), new Loader(), $repository);
|
||||
|
||||
return $phpdotenv->load();
|
||||
}
|
||||
|
||||
/**
|
||||
* Read and load environment file(s).
|
||||
*
|
||||
* @throws \Dotenv\Exception\InvalidPathException|\Dotenv\Exception\InvalidEncodingException|\Dotenv\Exception\InvalidFileException
|
||||
*
|
||||
* @return array<string,string|null>
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
$entries = $this->parser->parse($this->store->read());
|
||||
|
||||
return $this->loader->load($this->repository, $entries);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read and load environment file(s), silently failing if no files can be read.
|
||||
*
|
||||
* @throws \Dotenv\Exception\InvalidEncodingException|\Dotenv\Exception\InvalidFileException
|
||||
*
|
||||
* @return array<string,string|null>
|
||||
*/
|
||||
public function safeLoad()
|
||||
{
|
||||
try {
|
||||
return $this->load();
|
||||
} catch (InvalidPathException $e) {
|
||||
// suppressing exception
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Required ensures that the specified variables exist, and returns a new validator object.
|
||||
*
|
||||
* @param string|string[] $variables
|
||||
*
|
||||
* @return \Dotenv\Validator
|
||||
*/
|
||||
public function required($variables)
|
||||
{
|
||||
return (new Validator($this->repository, (array) $variables))->required();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new validator object that won't check if the specified variables exist.
|
||||
*
|
||||
* @param string|string[] $variables
|
||||
*
|
||||
* @return \Dotenv\Validator
|
||||
*/
|
||||
public function ifPresent($variables)
|
||||
{
|
||||
return new Validator($this->repository, (array) $variables);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Exception;
|
||||
|
||||
use Throwable;
|
||||
|
||||
interface ExceptionInterface extends Throwable
|
||||
{
|
||||
//
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Exception;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
final class InvalidEncodingException extends InvalidArgumentException implements ExceptionInterface
|
||||
{
|
||||
//
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Exception;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
final class InvalidFileException extends InvalidArgumentException implements ExceptionInterface
|
||||
{
|
||||
//
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Exception;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
final class InvalidPathException extends InvalidArgumentException implements ExceptionInterface
|
||||
{
|
||||
//
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Exception;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
final class ValidationException extends RuntimeException implements ExceptionInterface
|
||||
{
|
||||
//
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Loader;
|
||||
|
||||
use Dotenv\Parser\Entry;
|
||||
use Dotenv\Parser\Value;
|
||||
use Dotenv\Repository\RepositoryInterface;
|
||||
|
||||
final class Loader implements LoaderInterface
|
||||
{
|
||||
/**
|
||||
* Load the given entries into the repository.
|
||||
*
|
||||
* We'll substitute any nested variables, and send each variable to the
|
||||
* repository, with the effect of actually mutating the environment.
|
||||
*
|
||||
* @param \Dotenv\Repository\RepositoryInterface $repository
|
||||
* @param \Dotenv\Parser\Entry[] $entries
|
||||
*
|
||||
* @return array<string,string|null>
|
||||
*/
|
||||
public function load(RepositoryInterface $repository, array $entries)
|
||||
{
|
||||
return \array_reduce($entries, static function (array $vars, Entry $entry) use ($repository) {
|
||||
$name = $entry->getName();
|
||||
|
||||
$value = $entry->getValue()->map(static function (Value $value) use ($repository) {
|
||||
return Resolver::resolve($repository, $value);
|
||||
});
|
||||
|
||||
if ($value->isDefined()) {
|
||||
$inner = $value->get();
|
||||
if ($repository->set($name, $inner)) {
|
||||
return \array_merge($vars, [$name => $inner]);
|
||||
}
|
||||
} else {
|
||||
if ($repository->clear($name)) {
|
||||
return \array_merge($vars, [$name => null]);
|
||||
}
|
||||
}
|
||||
|
||||
return $vars;
|
||||
}, []);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Loader;
|
||||
|
||||
use Dotenv\Repository\RepositoryInterface;
|
||||
|
||||
interface LoaderInterface
|
||||
{
|
||||
/**
|
||||
* Load the given entries into the repository.
|
||||
*
|
||||
* @param \Dotenv\Repository\RepositoryInterface $repository
|
||||
* @param \Dotenv\Parser\Entry[] $entries
|
||||
*
|
||||
* @return array<string,string|null>
|
||||
*/
|
||||
public function load(RepositoryInterface $repository, array $entries);
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Loader;
|
||||
|
||||
use Dotenv\Parser\Value;
|
||||
use Dotenv\Repository\RepositoryInterface;
|
||||
use Dotenv\Util\Regex;
|
||||
use Dotenv\Util\Str;
|
||||
use PhpOption\Option;
|
||||
|
||||
final class Resolver
|
||||
{
|
||||
/**
|
||||
* This class is a singleton.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the nested variables in the given value.
|
||||
*
|
||||
* Replaces ${varname} patterns in the allowed positions in the variable
|
||||
* value by an existing environment variable.
|
||||
*
|
||||
* @param \Dotenv\Repository\RepositoryInterface $repository
|
||||
* @param \Dotenv\Parser\Value $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function resolve(RepositoryInterface $repository, Value $value)
|
||||
{
|
||||
return \array_reduce($value->getVars(), static function (string $s, int $i) use ($repository) {
|
||||
return Str::substr($s, 0, $i).self::resolveVariable($repository, Str::substr($s, $i));
|
||||
}, $value->getChars());
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a single nested variable.
|
||||
*
|
||||
* @param \Dotenv\Repository\RepositoryInterface $repository
|
||||
* @param string $str
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function resolveVariable(RepositoryInterface $repository, string $str)
|
||||
{
|
||||
return Regex::replaceCallback(
|
||||
'/\A\${([a-zA-Z0-9_.]+)}/',
|
||||
static function (array $matches) use ($repository) {
|
||||
return Option::fromValue($repository->get($matches[1]))
|
||||
->getOrElse($matches[0]);
|
||||
},
|
||||
$str,
|
||||
1
|
||||
)->success()->getOrElse($str);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Parser;
|
||||
|
||||
use PhpOption\Option;
|
||||
|
||||
final class Entry
|
||||
{
|
||||
/**
|
||||
* The entry name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* The entry value.
|
||||
*
|
||||
* @var \Dotenv\Parser\Value|null
|
||||
*/
|
||||
private $value;
|
||||
|
||||
/**
|
||||
* Create a new entry instance.
|
||||
*
|
||||
* @param string $name
|
||||
* @param \Dotenv\Parser\Value|null $value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(string $name, ?Value $value = null)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry value.
|
||||
*
|
||||
* @return \PhpOption\Option<\Dotenv\Parser\Value>
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
/** @var \PhpOption\Option<\Dotenv\Parser\Value> */
|
||||
return Option::fromValue($this->value);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,300 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Parser;
|
||||
|
||||
use Dotenv\Util\Regex;
|
||||
use Dotenv\Util\Str;
|
||||
use GrahamCampbell\ResultType\Error;
|
||||
use GrahamCampbell\ResultType\Result;
|
||||
use GrahamCampbell\ResultType\Success;
|
||||
|
||||
final class EntryParser
|
||||
{
|
||||
private const INITIAL_STATE = 0;
|
||||
private const UNQUOTED_STATE = 1;
|
||||
private const SINGLE_QUOTED_STATE = 2;
|
||||
private const DOUBLE_QUOTED_STATE = 3;
|
||||
private const ESCAPE_SEQUENCE_STATE = 4;
|
||||
private const WHITESPACE_STATE = 5;
|
||||
private const COMMENT_STATE = 6;
|
||||
private const REJECT_STATES = [self::SINGLE_QUOTED_STATE, self::DOUBLE_QUOTED_STATE, self::ESCAPE_SEQUENCE_STATE];
|
||||
|
||||
/**
|
||||
* This class is a singleton.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a raw entry into a proper entry.
|
||||
*
|
||||
* That is, turn a raw environment variable entry into a name and possibly
|
||||
* a value. We wrap the answer in a result type.
|
||||
*
|
||||
* @param string $entry
|
||||
*
|
||||
* @return \GrahamCampbell\ResultType\Result<\Dotenv\Parser\Entry,string>
|
||||
*/
|
||||
public static function parse(string $entry)
|
||||
{
|
||||
return self::splitStringIntoParts($entry)->flatMap(static function (array $parts) {
|
||||
[$name, $value] = $parts;
|
||||
|
||||
return self::parseName($name)->flatMap(static function (string $name) use ($value) {
|
||||
/** @var Result<Value|null,string> */
|
||||
$parsedValue = $value === null ? Success::create(null) : self::parseValue($value);
|
||||
|
||||
return $parsedValue->map(static function (?Value $value) use ($name) {
|
||||
return new Entry($name, $value);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Split the compound string into parts.
|
||||
*
|
||||
* @param string $line
|
||||
*
|
||||
* @return \GrahamCampbell\ResultType\Result<array{string,string|null},string>
|
||||
*/
|
||||
private static function splitStringIntoParts(string $line)
|
||||
{
|
||||
/** @var array{string,string|null} */
|
||||
$result = Str::pos($line, '=')->map(static function () use ($line) {
|
||||
return \array_map('trim', \explode('=', $line, 2));
|
||||
})->getOrElse([$line, null]);
|
||||
|
||||
if ($result[0] === '') {
|
||||
/** @var \GrahamCampbell\ResultType\Result<array{string,string|null},string> */
|
||||
return Error::create(self::getErrorMessage('an unexpected equals', $line));
|
||||
}
|
||||
|
||||
/** @var \GrahamCampbell\ResultType\Result<array{string,string|null},string> */
|
||||
return Success::create($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the given variable name.
|
||||
*
|
||||
* That is, strip the optional quotes and leading "export" from the
|
||||
* variable name. We wrap the answer in a result type.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return \GrahamCampbell\ResultType\Result<string,string>
|
||||
*/
|
||||
private static function parseName(string $name)
|
||||
{
|
||||
if (Str::len($name) > 8 && Str::substr($name, 0, 6) === 'export' && \ctype_space(Str::substr($name, 6, 1))) {
|
||||
$name = \ltrim(Str::substr($name, 6));
|
||||
}
|
||||
|
||||
if (self::isQuotedName($name)) {
|
||||
$name = Str::substr($name, 1, -1);
|
||||
}
|
||||
|
||||
if (!self::isValidName($name)) {
|
||||
/** @var \GrahamCampbell\ResultType\Result<string,string> */
|
||||
return Error::create(self::getErrorMessage('an invalid name', $name));
|
||||
}
|
||||
|
||||
/** @var \GrahamCampbell\ResultType\Result<string,string> */
|
||||
return Success::create($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the given variable name quoted?
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private static function isQuotedName(string $name)
|
||||
{
|
||||
if (Str::len($name) < 3) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$first = Str::substr($name, 0, 1);
|
||||
$last = Str::substr($name, -1, 1);
|
||||
|
||||
return ($first === '"' && $last === '"') || ($first === '\'' && $last === '\'');
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the given variable name valid?
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private static function isValidName(string $name)
|
||||
{
|
||||
return Regex::matches('~(*UTF8)\A[\p{Ll}\p{Lu}\p{M}\p{N}_.]+\z~', $name)->success()->getOrElse(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the given variable value.
|
||||
*
|
||||
* This has the effect of stripping quotes and comments, dealing with
|
||||
* special characters, and locating nested variables, but not resolving
|
||||
* them. Formally, we run a finite state automaton with an output tape: a
|
||||
* transducer. We wrap the answer in a result type.
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return \GrahamCampbell\ResultType\Result<\Dotenv\Parser\Value,string>
|
||||
*/
|
||||
private static function parseValue(string $value)
|
||||
{
|
||||
if (\trim($value) === '') {
|
||||
/** @var \GrahamCampbell\ResultType\Result<\Dotenv\Parser\Value,string> */
|
||||
return Success::create(Value::blank());
|
||||
}
|
||||
|
||||
return \array_reduce(\iterator_to_array(Lexer::lex($value)), static function (Result $data, string $token) {
|
||||
return $data->flatMap(static function (array $data) use ($token) {
|
||||
return self::processToken($data[1], $token)->map(static function (array $val) use ($data) {
|
||||
return [$data[0]->append($val[0], $val[1]), $val[2]];
|
||||
});
|
||||
});
|
||||
}, Success::create([Value::blank(), self::INITIAL_STATE]))->flatMap(static function (array $result) {
|
||||
/** @psalm-suppress DocblockTypeContradiction */
|
||||
if (in_array($result[1], self::REJECT_STATES, true)) {
|
||||
/** @var \GrahamCampbell\ResultType\Result<\Dotenv\Parser\Value,string> */
|
||||
return Error::create('a missing closing quote');
|
||||
}
|
||||
|
||||
/** @var \GrahamCampbell\ResultType\Result<\Dotenv\Parser\Value,string> */
|
||||
return Success::create($result[0]);
|
||||
})->mapError(static function (string $err) use ($value) {
|
||||
return self::getErrorMessage($err, $value);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the given token.
|
||||
*
|
||||
* @param int $state
|
||||
* @param string $token
|
||||
*
|
||||
* @return \GrahamCampbell\ResultType\Result<array{string,bool,int},string>
|
||||
*/
|
||||
private static function processToken(int $state, string $token)
|
||||
{
|
||||
switch ($state) {
|
||||
case self::INITIAL_STATE:
|
||||
if ($token === '\'') {
|
||||
/** @var \GrahamCampbell\ResultType\Result<array{string,bool,int},string> */
|
||||
return Success::create(['', false, self::SINGLE_QUOTED_STATE]);
|
||||
} elseif ($token === '"') {
|
||||
/** @var \GrahamCampbell\ResultType\Result<array{string,bool,int},string> */
|
||||
return Success::create(['', false, self::DOUBLE_QUOTED_STATE]);
|
||||
} elseif ($token === '#') {
|
||||
/** @var \GrahamCampbell\ResultType\Result<array{string,bool,int},string> */
|
||||
return Success::create(['', false, self::COMMENT_STATE]);
|
||||
} elseif ($token === '$') {
|
||||
/** @var \GrahamCampbell\ResultType\Result<array{string,bool,int},string> */
|
||||
return Success::create([$token, true, self::UNQUOTED_STATE]);
|
||||
} else {
|
||||
/** @var \GrahamCampbell\ResultType\Result<array{string,bool,int},string> */
|
||||
return Success::create([$token, false, self::UNQUOTED_STATE]);
|
||||
}
|
||||
case self::UNQUOTED_STATE:
|
||||
if ($token === '#') {
|
||||
/** @var \GrahamCampbell\ResultType\Result<array{string,bool,int},string> */
|
||||
return Success::create(['', false, self::COMMENT_STATE]);
|
||||
} elseif (\ctype_space($token)) {
|
||||
/** @var \GrahamCampbell\ResultType\Result<array{string,bool,int},string> */
|
||||
return Success::create(['', false, self::WHITESPACE_STATE]);
|
||||
} elseif ($token === '$') {
|
||||
/** @var \GrahamCampbell\ResultType\Result<array{string,bool,int},string> */
|
||||
return Success::create([$token, true, self::UNQUOTED_STATE]);
|
||||
} else {
|
||||
/** @var \GrahamCampbell\ResultType\Result<array{string,bool,int},string> */
|
||||
return Success::create([$token, false, self::UNQUOTED_STATE]);
|
||||
}
|
||||
case self::SINGLE_QUOTED_STATE:
|
||||
if ($token === '\'') {
|
||||
/** @var \GrahamCampbell\ResultType\Result<array{string,bool,int},string> */
|
||||
return Success::create(['', false, self::WHITESPACE_STATE]);
|
||||
} else {
|
||||
/** @var \GrahamCampbell\ResultType\Result<array{string,bool,int},string> */
|
||||
return Success::create([$token, false, self::SINGLE_QUOTED_STATE]);
|
||||
}
|
||||
case self::DOUBLE_QUOTED_STATE:
|
||||
if ($token === '"') {
|
||||
/** @var \GrahamCampbell\ResultType\Result<array{string,bool,int},string> */
|
||||
return Success::create(['', false, self::WHITESPACE_STATE]);
|
||||
} elseif ($token === '\\') {
|
||||
/** @var \GrahamCampbell\ResultType\Result<array{string,bool,int},string> */
|
||||
return Success::create(['', false, self::ESCAPE_SEQUENCE_STATE]);
|
||||
} elseif ($token === '$') {
|
||||
/** @var \GrahamCampbell\ResultType\Result<array{string,bool,int},string> */
|
||||
return Success::create([$token, true, self::DOUBLE_QUOTED_STATE]);
|
||||
} else {
|
||||
/** @var \GrahamCampbell\ResultType\Result<array{string,bool,int},string> */
|
||||
return Success::create([$token, false, self::DOUBLE_QUOTED_STATE]);
|
||||
}
|
||||
case self::ESCAPE_SEQUENCE_STATE:
|
||||
if ($token === '"' || $token === '\\') {
|
||||
/** @var \GrahamCampbell\ResultType\Result<array{string,bool,int},string> */
|
||||
return Success::create([$token, false, self::DOUBLE_QUOTED_STATE]);
|
||||
} elseif ($token === '$') {
|
||||
/** @var \GrahamCampbell\ResultType\Result<array{string,bool,int},string> */
|
||||
return Success::create([$token, false, self::DOUBLE_QUOTED_STATE]);
|
||||
} else {
|
||||
$first = Str::substr($token, 0, 1);
|
||||
if (\in_array($first, ['f', 'n', 'r', 't', 'v'], true)) {
|
||||
/** @var \GrahamCampbell\ResultType\Result<array{string,bool,int},string> */
|
||||
return Success::create([\stripcslashes('\\'.$first).Str::substr($token, 1), false, self::DOUBLE_QUOTED_STATE]);
|
||||
} else {
|
||||
/** @var \GrahamCampbell\ResultType\Result<array{string,bool,int},string> */
|
||||
return Error::create('an unexpected escape sequence');
|
||||
}
|
||||
}
|
||||
case self::WHITESPACE_STATE:
|
||||
if ($token === '#') {
|
||||
/** @var \GrahamCampbell\ResultType\Result<array{string,bool,int},string> */
|
||||
return Success::create(['', false, self::COMMENT_STATE]);
|
||||
} elseif (!\ctype_space($token)) {
|
||||
/** @var \GrahamCampbell\ResultType\Result<array{string,bool,int},string> */
|
||||
return Error::create('unexpected whitespace');
|
||||
} else {
|
||||
/** @var \GrahamCampbell\ResultType\Result<array{string,bool,int},string> */
|
||||
return Success::create(['', false, self::WHITESPACE_STATE]);
|
||||
}
|
||||
case self::COMMENT_STATE:
|
||||
/** @var \GrahamCampbell\ResultType\Result<array{string,bool,int},string> */
|
||||
return Success::create(['', false, self::COMMENT_STATE]);
|
||||
default:
|
||||
throw new \Error('Parser entered invalid state.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a friendly error message.
|
||||
*
|
||||
* @param string $cause
|
||||
* @param string $subject
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function getErrorMessage(string $cause, string $subject)
|
||||
{
|
||||
return \sprintf(
|
||||
'Encountered %s at [%s].',
|
||||
$cause,
|
||||
\strtok($subject, "\n")
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Parser;
|
||||
|
||||
final class Lexer
|
||||
{
|
||||
/**
|
||||
* The regex for each type of token.
|
||||
*/
|
||||
private const PATTERNS = [
|
||||
'[\r\n]{1,1000}', '[^\S\r\n]{1,1000}', '\\\\', '\'', '"', '\\#', '\\$', '([^(\s\\\\\'"\\#\\$)]|\\(|\\)){1,1000}',
|
||||
];
|
||||
|
||||
/**
|
||||
* This class is a singleton.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert content into a token stream.
|
||||
*
|
||||
* Multibyte string processing is not needed here, and nether is error
|
||||
* handling, for performance reasons.
|
||||
*
|
||||
* @param string $content
|
||||
*
|
||||
* @return \Generator<string>
|
||||
*/
|
||||
public static function lex(string $content)
|
||||
{
|
||||
static $regex;
|
||||
|
||||
if ($regex === null) {
|
||||
$regex = '(('.\implode(')|(', self::PATTERNS).'))A';
|
||||
}
|
||||
|
||||
$offset = 0;
|
||||
|
||||
while (isset($content[$offset])) {
|
||||
if (!\preg_match($regex, $content, $matches, 0, $offset)) {
|
||||
throw new \Error(\sprintf('Lexer encountered unexpected character [%s].', $content[$offset]));
|
||||
}
|
||||
|
||||
$offset += \strlen($matches[0]);
|
||||
|
||||
yield $matches[0];
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,127 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Parser;
|
||||
|
||||
use Dotenv\Util\Regex;
|
||||
use Dotenv\Util\Str;
|
||||
|
||||
final class Lines
|
||||
{
|
||||
/**
|
||||
* This class is a singleton.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the array of lines of environment variables.
|
||||
*
|
||||
* This will produce an array of raw entries, one per variable.
|
||||
*
|
||||
* @param string[] $lines
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public static function process(array $lines)
|
||||
{
|
||||
$output = [];
|
||||
$multiline = false;
|
||||
$multilineBuffer = [];
|
||||
|
||||
foreach ($lines as $line) {
|
||||
[$multiline, $line, $multilineBuffer] = self::multilineProcess($multiline, $line, $multilineBuffer);
|
||||
|
||||
if (!$multiline && !self::isCommentOrWhitespace($line)) {
|
||||
$output[] = $line;
|
||||
}
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to make all multiline variable process.
|
||||
*
|
||||
* @param bool $multiline
|
||||
* @param string $line
|
||||
* @param string[] $buffer
|
||||
*
|
||||
* @return array{bool,string,string[]}
|
||||
*/
|
||||
private static function multilineProcess(bool $multiline, string $line, array $buffer)
|
||||
{
|
||||
$startsOnCurrentLine = $multiline ? false : self::looksLikeMultilineStart($line);
|
||||
|
||||
// check if $line can be multiline variable
|
||||
if ($startsOnCurrentLine) {
|
||||
$multiline = true;
|
||||
}
|
||||
|
||||
if ($multiline) {
|
||||
\array_push($buffer, $line);
|
||||
|
||||
if (self::looksLikeMultilineStop($line, $startsOnCurrentLine)) {
|
||||
$multiline = false;
|
||||
$line = \implode("\n", $buffer);
|
||||
$buffer = [];
|
||||
}
|
||||
}
|
||||
|
||||
return [$multiline, $line, $buffer];
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given line can be the start of a multiline variable.
|
||||
*
|
||||
* @param string $line
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private static function looksLikeMultilineStart(string $line)
|
||||
{
|
||||
return Str::pos($line, '="')->map(static function () use ($line) {
|
||||
return self::looksLikeMultilineStop($line, true) === false;
|
||||
})->getOrElse(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given line can be the start of a multiline variable.
|
||||
*
|
||||
* @param string $line
|
||||
* @param bool $started
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private static function looksLikeMultilineStop(string $line, bool $started)
|
||||
{
|
||||
if ($line === '"') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return Regex::occurrences('/(?=([^\\\\]"))/', \str_replace('\\\\', '', $line))->map(static function (int $count) use ($started) {
|
||||
return $started ? $count > 1 : $count >= 1;
|
||||
})->success()->getOrElse(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the line in the file is a comment or whitespace.
|
||||
*
|
||||
* @param string $line
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private static function isCommentOrWhitespace(string $line)
|
||||
{
|
||||
$line = \trim($line);
|
||||
|
||||
return $line === '' || (isset($line[0]) && $line[0] === '#');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Parser;
|
||||
|
||||
use Dotenv\Exception\InvalidFileException;
|
||||
use Dotenv\Util\Regex;
|
||||
use GrahamCampbell\ResultType\Result;
|
||||
use GrahamCampbell\ResultType\Success;
|
||||
|
||||
final class Parser implements ParserInterface
|
||||
{
|
||||
/**
|
||||
* Parse content into an entry array.
|
||||
*
|
||||
* @param string $content
|
||||
*
|
||||
* @throws \Dotenv\Exception\InvalidFileException
|
||||
*
|
||||
* @return \Dotenv\Parser\Entry[]
|
||||
*/
|
||||
public function parse(string $content)
|
||||
{
|
||||
return Regex::split("/(\r\n|\n|\r)/", $content)->mapError(static function () {
|
||||
return 'Could not split into separate lines.';
|
||||
})->flatMap(static function (array $lines) {
|
||||
return self::process(Lines::process($lines));
|
||||
})->mapError(static function (string $error) {
|
||||
throw new InvalidFileException(\sprintf('Failed to parse dotenv file. %s', $error));
|
||||
})->success()->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the raw entries into proper entries.
|
||||
*
|
||||
* @param string[] $entries
|
||||
*
|
||||
* @return \GrahamCampbell\ResultType\Result<\Dotenv\Parser\Entry[],string>
|
||||
*/
|
||||
private static function process(array $entries)
|
||||
{
|
||||
/** @var \GrahamCampbell\ResultType\Result<\Dotenv\Parser\Entry[],string> */
|
||||
return \array_reduce($entries, static function (Result $result, string $raw) {
|
||||
return $result->flatMap(static function (array $entries) use ($raw) {
|
||||
return EntryParser::parse($raw)->map(static function (Entry $entry) use ($entries) {
|
||||
/** @var \Dotenv\Parser\Entry[] */
|
||||
return \array_merge($entries, [$entry]);
|
||||
});
|
||||
});
|
||||
}, Success::create([]));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Parser;
|
||||
|
||||
interface ParserInterface
|
||||
{
|
||||
/**
|
||||
* Parse content into an entry array.
|
||||
*
|
||||
* @param string $content
|
||||
*
|
||||
* @throws \Dotenv\Exception\InvalidFileException
|
||||
*
|
||||
* @return \Dotenv\Parser\Entry[]
|
||||
*/
|
||||
public function parse(string $content);
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Parser;
|
||||
|
||||
use Dotenv\Util\Str;
|
||||
|
||||
final class Value
|
||||
{
|
||||
/**
|
||||
* The string representation of the parsed value.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $chars;
|
||||
|
||||
/**
|
||||
* The locations of the variables in the value.
|
||||
*
|
||||
* @var int[]
|
||||
*/
|
||||
private $vars;
|
||||
|
||||
/**
|
||||
* Internal constructor for a value.
|
||||
*
|
||||
* @param string $chars
|
||||
* @param int[] $vars
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function __construct(string $chars, array $vars)
|
||||
{
|
||||
$this->chars = $chars;
|
||||
$this->vars = $vars;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an empty value instance.
|
||||
*
|
||||
* @return \Dotenv\Parser\Value
|
||||
*/
|
||||
public static function blank()
|
||||
{
|
||||
return new self('', []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new value instance, appending the characters.
|
||||
*
|
||||
* @param string $chars
|
||||
* @param bool $var
|
||||
*
|
||||
* @return \Dotenv\Parser\Value
|
||||
*/
|
||||
public function append(string $chars, bool $var)
|
||||
{
|
||||
return new self(
|
||||
$this->chars.$chars,
|
||||
$var ? \array_merge($this->vars, [Str::len($this->chars)]) : $this->vars
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the string representation of the parsed value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getChars()
|
||||
{
|
||||
return $this->chars;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the locations of the variables in the value.
|
||||
*
|
||||
* @return int[]
|
||||
*/
|
||||
public function getVars()
|
||||
{
|
||||
$vars = $this->vars;
|
||||
|
||||
\rsort($vars);
|
||||
|
||||
return $vars;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Repository\Adapter;
|
||||
|
||||
interface AdapterInterface extends ReaderInterface, WriterInterface
|
||||
{
|
||||
/**
|
||||
* Create a new instance of the adapter, if it is available.
|
||||
*
|
||||
* @return \PhpOption\Option<\Dotenv\Repository\Adapter\AdapterInterface>
|
||||
*/
|
||||
public static function create();
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Repository\Adapter;
|
||||
|
||||
use PhpOption\None;
|
||||
use PhpOption\Option;
|
||||
use PhpOption\Some;
|
||||
|
||||
final class ApacheAdapter implements AdapterInterface
|
||||
{
|
||||
/**
|
||||
* Create a new apache adapter instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of the adapter, if it is available.
|
||||
*
|
||||
* @return \PhpOption\Option<\Dotenv\Repository\Adapter\AdapterInterface>
|
||||
*/
|
||||
public static function create()
|
||||
{
|
||||
if (self::isSupported()) {
|
||||
/** @var \PhpOption\Option<AdapterInterface> */
|
||||
return Some::create(new self());
|
||||
}
|
||||
|
||||
return None::create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the adapter is supported.
|
||||
*
|
||||
* This happens if PHP is running as an Apache module.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private static function isSupported()
|
||||
{
|
||||
return \function_exists('apache_getenv') && \function_exists('apache_setenv');
|
||||
}
|
||||
|
||||
/**
|
||||
* Read an environment variable, if it exists.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return \PhpOption\Option<string>
|
||||
*/
|
||||
public function read(string $name)
|
||||
{
|
||||
/** @var \PhpOption\Option<string> */
|
||||
return Option::fromValue(apache_getenv($name))->filter(static function ($value) {
|
||||
return \is_string($value) && $value !== '';
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Write to an environment variable, if possible.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
* @param string $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function write(string $name, string $value)
|
||||
{
|
||||
return apache_setenv($name, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an environment variable, if possible.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function delete(string $name)
|
||||
{
|
||||
return apache_setenv($name, '');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Repository\Adapter;
|
||||
|
||||
use PhpOption\Option;
|
||||
use PhpOption\Some;
|
||||
|
||||
final class ArrayAdapter implements AdapterInterface
|
||||
{
|
||||
/**
|
||||
* The variables and their values.
|
||||
*
|
||||
* @var array<string,string>
|
||||
*/
|
||||
private $variables;
|
||||
|
||||
/**
|
||||
* Create a new array adapter instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
$this->variables = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of the adapter, if it is available.
|
||||
*
|
||||
* @return \PhpOption\Option<\Dotenv\Repository\Adapter\AdapterInterface>
|
||||
*/
|
||||
public static function create()
|
||||
{
|
||||
/** @var \PhpOption\Option<AdapterInterface> */
|
||||
return Some::create(new self());
|
||||
}
|
||||
|
||||
/**
|
||||
* Read an environment variable, if it exists.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return \PhpOption\Option<string>
|
||||
*/
|
||||
public function read(string $name)
|
||||
{
|
||||
return Option::fromArraysValue($this->variables, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write to an environment variable, if possible.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
* @param string $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function write(string $name, string $value)
|
||||
{
|
||||
$this->variables[$name] = $value;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an environment variable, if possible.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function delete(string $name)
|
||||
{
|
||||
unset($this->variables[$name]);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Repository\Adapter;
|
||||
|
||||
use PhpOption\Option;
|
||||
use PhpOption\Some;
|
||||
|
||||
final class EnvConstAdapter implements AdapterInterface
|
||||
{
|
||||
/**
|
||||
* Create a new env const adapter instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of the adapter, if it is available.
|
||||
*
|
||||
* @return \PhpOption\Option<\Dotenv\Repository\Adapter\AdapterInterface>
|
||||
*/
|
||||
public static function create()
|
||||
{
|
||||
/** @var \PhpOption\Option<AdapterInterface> */
|
||||
return Some::create(new self());
|
||||
}
|
||||
|
||||
/**
|
||||
* Read an environment variable, if it exists.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return \PhpOption\Option<string>
|
||||
*/
|
||||
public function read(string $name)
|
||||
{
|
||||
/** @var \PhpOption\Option<string> */
|
||||
return Option::fromArraysValue($_ENV, $name)
|
||||
->filter(static function ($value) {
|
||||
return \is_scalar($value);
|
||||
})
|
||||
->map(static function ($value) {
|
||||
if ($value === false) {
|
||||
return 'false';
|
||||
}
|
||||
|
||||
if ($value === true) {
|
||||
return 'true';
|
||||
}
|
||||
|
||||
/** @psalm-suppress PossiblyInvalidCast */
|
||||
return (string) $value;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Write to an environment variable, if possible.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
* @param string $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function write(string $name, string $value)
|
||||
{
|
||||
$_ENV[$name] = $value;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an environment variable, if possible.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function delete(string $name)
|
||||
{
|
||||
unset($_ENV[$name]);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Repository\Adapter;
|
||||
|
||||
final class GuardedWriter implements WriterInterface
|
||||
{
|
||||
/**
|
||||
* The inner writer to use.
|
||||
*
|
||||
* @var \Dotenv\Repository\Adapter\WriterInterface
|
||||
*/
|
||||
private $writer;
|
||||
|
||||
/**
|
||||
* The variable name allow list.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
private $allowList;
|
||||
|
||||
/**
|
||||
* Create a new guarded writer instance.
|
||||
*
|
||||
* @param \Dotenv\Repository\Adapter\WriterInterface $writer
|
||||
* @param string[] $allowList
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(WriterInterface $writer, array $allowList)
|
||||
{
|
||||
$this->writer = $writer;
|
||||
$this->allowList = $allowList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write to an environment variable, if possible.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
* @param string $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function write(string $name, string $value)
|
||||
{
|
||||
// Don't set non-allowed variables
|
||||
if (!$this->isAllowed($name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set the value on the inner writer
|
||||
return $this->writer->write($name, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an environment variable, if possible.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function delete(string $name)
|
||||
{
|
||||
// Don't clear non-allowed variables
|
||||
if (!$this->isAllowed($name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set the value on the inner writer
|
||||
return $this->writer->delete($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given variable is allowed.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isAllowed(string $name)
|
||||
{
|
||||
return \in_array($name, $this->allowList, true);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Repository\Adapter;
|
||||
|
||||
final class ImmutableWriter implements WriterInterface
|
||||
{
|
||||
/**
|
||||
* The inner writer to use.
|
||||
*
|
||||
* @var \Dotenv\Repository\Adapter\WriterInterface
|
||||
*/
|
||||
private $writer;
|
||||
|
||||
/**
|
||||
* The inner reader to use.
|
||||
*
|
||||
* @var \Dotenv\Repository\Adapter\ReaderInterface
|
||||
*/
|
||||
private $reader;
|
||||
|
||||
/**
|
||||
* The record of loaded variables.
|
||||
*
|
||||
* @var array<string,string>
|
||||
*/
|
||||
private $loaded;
|
||||
|
||||
/**
|
||||
* Create a new immutable writer instance.
|
||||
*
|
||||
* @param \Dotenv\Repository\Adapter\WriterInterface $writer
|
||||
* @param \Dotenv\Repository\Adapter\ReaderInterface $reader
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(WriterInterface $writer, ReaderInterface $reader)
|
||||
{
|
||||
$this->writer = $writer;
|
||||
$this->reader = $reader;
|
||||
$this->loaded = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Write to an environment variable, if possible.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
* @param string $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function write(string $name, string $value)
|
||||
{
|
||||
// Don't overwrite existing environment variables
|
||||
// Ruby's dotenv does this with `ENV[key] ||= value`
|
||||
if ($this->isExternallyDefined($name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set the value on the inner writer
|
||||
if (!$this->writer->write($name, $value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Record that we have loaded the variable
|
||||
$this->loaded[$name] = '';
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an environment variable, if possible.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function delete(string $name)
|
||||
{
|
||||
// Don't clear existing environment variables
|
||||
if ($this->isExternallyDefined($name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Clear the value on the inner writer
|
||||
if (!$this->writer->delete($name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Leave the variable as fair game
|
||||
unset($this->loaded[$name]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given variable is externally defined.
|
||||
*
|
||||
* That is, is it an "existing" variable.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isExternallyDefined(string $name)
|
||||
{
|
||||
return $this->reader->read($name)->isDefined() && !isset($this->loaded[$name]);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Repository\Adapter;
|
||||
|
||||
use PhpOption\None;
|
||||
|
||||
final class MultiReader implements ReaderInterface
|
||||
{
|
||||
/**
|
||||
* The set of readers to use.
|
||||
*
|
||||
* @var \Dotenv\Repository\Adapter\ReaderInterface[]
|
||||
*/
|
||||
private $readers;
|
||||
|
||||
/**
|
||||
* Create a new multi-reader instance.
|
||||
*
|
||||
* @param \Dotenv\Repository\Adapter\ReaderInterface[] $readers
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $readers)
|
||||
{
|
||||
$this->readers = $readers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read an environment variable, if it exists.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return \PhpOption\Option<string>
|
||||
*/
|
||||
public function read(string $name)
|
||||
{
|
||||
foreach ($this->readers as $reader) {
|
||||
$result = $reader->read($name);
|
||||
if ($result->isDefined()) {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
return None::create();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Repository\Adapter;
|
||||
|
||||
final class MultiWriter implements WriterInterface
|
||||
{
|
||||
/**
|
||||
* The set of writers to use.
|
||||
*
|
||||
* @var \Dotenv\Repository\Adapter\WriterInterface[]
|
||||
*/
|
||||
private $writers;
|
||||
|
||||
/**
|
||||
* Create a new multi-writer instance.
|
||||
*
|
||||
* @param \Dotenv\Repository\Adapter\WriterInterface[] $writers
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $writers)
|
||||
{
|
||||
$this->writers = $writers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write to an environment variable, if possible.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
* @param string $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function write(string $name, string $value)
|
||||
{
|
||||
foreach ($this->writers as $writers) {
|
||||
if (!$writers->write($name, $value)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an environment variable, if possible.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function delete(string $name)
|
||||
{
|
||||
foreach ($this->writers as $writers) {
|
||||
if (!$writers->delete($name)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Repository\Adapter;
|
||||
|
||||
use PhpOption\None;
|
||||
use PhpOption\Option;
|
||||
use PhpOption\Some;
|
||||
|
||||
final class PutenvAdapter implements AdapterInterface
|
||||
{
|
||||
/**
|
||||
* Create a new putenv adapter instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of the adapter, if it is available.
|
||||
*
|
||||
* @return \PhpOption\Option<\Dotenv\Repository\Adapter\AdapterInterface>
|
||||
*/
|
||||
public static function create()
|
||||
{
|
||||
if (self::isSupported()) {
|
||||
/** @var \PhpOption\Option<AdapterInterface> */
|
||||
return Some::create(new self());
|
||||
}
|
||||
|
||||
return None::create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the adapter is supported.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private static function isSupported()
|
||||
{
|
||||
return \function_exists('getenv') && \function_exists('putenv');
|
||||
}
|
||||
|
||||
/**
|
||||
* Read an environment variable, if it exists.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return \PhpOption\Option<string>
|
||||
*/
|
||||
public function read(string $name)
|
||||
{
|
||||
/** @var \PhpOption\Option<string> */
|
||||
return Option::fromValue(\getenv($name), false)->filter(static function ($value) {
|
||||
return \is_string($value);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Write to an environment variable, if possible.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
* @param string $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function write(string $name, string $value)
|
||||
{
|
||||
\putenv("$name=$value");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an environment variable, if possible.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function delete(string $name)
|
||||
{
|
||||
\putenv($name);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Repository\Adapter;
|
||||
|
||||
interface ReaderInterface
|
||||
{
|
||||
/**
|
||||
* Read an environment variable, if it exists.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return \PhpOption\Option<string>
|
||||
*/
|
||||
public function read(string $name);
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Repository\Adapter;
|
||||
|
||||
final class ReplacingWriter implements WriterInterface
|
||||
{
|
||||
/**
|
||||
* The inner writer to use.
|
||||
*
|
||||
* @var \Dotenv\Repository\Adapter\WriterInterface
|
||||
*/
|
||||
private $writer;
|
||||
|
||||
/**
|
||||
* The inner reader to use.
|
||||
*
|
||||
* @var \Dotenv\Repository\Adapter\ReaderInterface
|
||||
*/
|
||||
private $reader;
|
||||
|
||||
/**
|
||||
* The record of seen variables.
|
||||
*
|
||||
* @var array<string,string>
|
||||
*/
|
||||
private $seen;
|
||||
|
||||
/**
|
||||
* Create a new replacement writer instance.
|
||||
*
|
||||
* @param \Dotenv\Repository\Adapter\WriterInterface $writer
|
||||
* @param \Dotenv\Repository\Adapter\ReaderInterface $reader
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(WriterInterface $writer, ReaderInterface $reader)
|
||||
{
|
||||
$this->writer = $writer;
|
||||
$this->reader = $reader;
|
||||
$this->seen = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Write to an environment variable, if possible.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
* @param string $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function write(string $name, string $value)
|
||||
{
|
||||
if ($this->exists($name)) {
|
||||
return $this->writer->write($name, $value);
|
||||
}
|
||||
|
||||
// succeed if nothing to do
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an environment variable, if possible.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function delete(string $name)
|
||||
{
|
||||
if ($this->exists($name)) {
|
||||
return $this->writer->delete($name);
|
||||
}
|
||||
|
||||
// succeed if nothing to do
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the given environment variable exist.
|
||||
*
|
||||
* Returns true if it currently exists, or existed at any point in the past
|
||||
* that we are aware of.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function exists(string $name)
|
||||
{
|
||||
if (isset($this->seen[$name])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->reader->read($name)->isDefined()) {
|
||||
$this->seen[$name] = '';
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Repository\Adapter;
|
||||
|
||||
use PhpOption\Option;
|
||||
use PhpOption\Some;
|
||||
|
||||
final class ServerConstAdapter implements AdapterInterface
|
||||
{
|
||||
/**
|
||||
* Create a new server const adapter instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of the adapter, if it is available.
|
||||
*
|
||||
* @return \PhpOption\Option<\Dotenv\Repository\Adapter\AdapterInterface>
|
||||
*/
|
||||
public static function create()
|
||||
{
|
||||
/** @var \PhpOption\Option<AdapterInterface> */
|
||||
return Some::create(new self());
|
||||
}
|
||||
|
||||
/**
|
||||
* Read an environment variable, if it exists.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return \PhpOption\Option<string>
|
||||
*/
|
||||
public function read(string $name)
|
||||
{
|
||||
/** @var \PhpOption\Option<string> */
|
||||
return Option::fromArraysValue($_SERVER, $name)
|
||||
->filter(static function ($value) {
|
||||
return \is_scalar($value);
|
||||
})
|
||||
->map(static function ($value) {
|
||||
if ($value === false) {
|
||||
return 'false';
|
||||
}
|
||||
|
||||
if ($value === true) {
|
||||
return 'true';
|
||||
}
|
||||
|
||||
/** @psalm-suppress PossiblyInvalidCast */
|
||||
return (string) $value;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Write to an environment variable, if possible.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
* @param string $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function write(string $name, string $value)
|
||||
{
|
||||
$_SERVER[$name] = $value;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an environment variable, if possible.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function delete(string $name)
|
||||
{
|
||||
unset($_SERVER[$name]);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Repository\Adapter;
|
||||
|
||||
interface WriterInterface
|
||||
{
|
||||
/**
|
||||
* Write to an environment variable, if possible.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
* @param string $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function write(string $name, string $value);
|
||||
|
||||
/**
|
||||
* Delete an environment variable, if possible.
|
||||
*
|
||||
* @param non-empty-string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function delete(string $name);
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Repository;
|
||||
|
||||
use Dotenv\Repository\Adapter\ReaderInterface;
|
||||
use Dotenv\Repository\Adapter\WriterInterface;
|
||||
use InvalidArgumentException;
|
||||
|
||||
final class AdapterRepository implements RepositoryInterface
|
||||
{
|
||||
/**
|
||||
* The reader to use.
|
||||
*
|
||||
* @var \Dotenv\Repository\Adapter\ReaderInterface
|
||||
*/
|
||||
private $reader;
|
||||
|
||||
/**
|
||||
* The writer to use.
|
||||
*
|
||||
* @var \Dotenv\Repository\Adapter\WriterInterface
|
||||
*/
|
||||
private $writer;
|
||||
|
||||
/**
|
||||
* Create a new adapter repository instance.
|
||||
*
|
||||
* @param \Dotenv\Repository\Adapter\ReaderInterface $reader
|
||||
* @param \Dotenv\Repository\Adapter\WriterInterface $writer
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(ReaderInterface $reader, WriterInterface $writer)
|
||||
{
|
||||
$this->reader = $reader;
|
||||
$this->writer = $writer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given environment variable is defined.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function has(string $name)
|
||||
{
|
||||
return '' !== $name && $this->reader->read($name)->isDefined();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an environment variable.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function get(string $name)
|
||||
{
|
||||
if ('' === $name) {
|
||||
throw new InvalidArgumentException('Expected name to be a non-empty string.');
|
||||
}
|
||||
|
||||
return $this->reader->read($name)->getOrElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an environment variable.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function set(string $name, string $value)
|
||||
{
|
||||
if ('' === $name) {
|
||||
throw new InvalidArgumentException('Expected name to be a non-empty string.');
|
||||
}
|
||||
|
||||
return $this->writer->write($name, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear an environment variable.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function clear(string $name)
|
||||
{
|
||||
if ('' === $name) {
|
||||
throw new InvalidArgumentException('Expected name to be a non-empty string.');
|
||||
}
|
||||
|
||||
return $this->writer->delete($name);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,272 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Repository;
|
||||
|
||||
use Dotenv\Repository\Adapter\AdapterInterface;
|
||||
use Dotenv\Repository\Adapter\EnvConstAdapter;
|
||||
use Dotenv\Repository\Adapter\GuardedWriter;
|
||||
use Dotenv\Repository\Adapter\ImmutableWriter;
|
||||
use Dotenv\Repository\Adapter\MultiReader;
|
||||
use Dotenv\Repository\Adapter\MultiWriter;
|
||||
use Dotenv\Repository\Adapter\ReaderInterface;
|
||||
use Dotenv\Repository\Adapter\ServerConstAdapter;
|
||||
use Dotenv\Repository\Adapter\WriterInterface;
|
||||
use InvalidArgumentException;
|
||||
use PhpOption\Some;
|
||||
use ReflectionClass;
|
||||
|
||||
final class RepositoryBuilder
|
||||
{
|
||||
/**
|
||||
* The set of default adapters.
|
||||
*/
|
||||
private const DEFAULT_ADAPTERS = [
|
||||
ServerConstAdapter::class,
|
||||
EnvConstAdapter::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* The set of readers to use.
|
||||
*
|
||||
* @var \Dotenv\Repository\Adapter\ReaderInterface[]
|
||||
*/
|
||||
private $readers;
|
||||
|
||||
/**
|
||||
* The set of writers to use.
|
||||
*
|
||||
* @var \Dotenv\Repository\Adapter\WriterInterface[]
|
||||
*/
|
||||
private $writers;
|
||||
|
||||
/**
|
||||
* Are we immutable?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $immutable;
|
||||
|
||||
/**
|
||||
* The variable name allow list.
|
||||
*
|
||||
* @var string[]|null
|
||||
*/
|
||||
private $allowList;
|
||||
|
||||
/**
|
||||
* Create a new repository builder instance.
|
||||
*
|
||||
* @param \Dotenv\Repository\Adapter\ReaderInterface[] $readers
|
||||
* @param \Dotenv\Repository\Adapter\WriterInterface[] $writers
|
||||
* @param bool $immutable
|
||||
* @param string[]|null $allowList
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function __construct(array $readers = [], array $writers = [], bool $immutable = false, ?array $allowList = null)
|
||||
{
|
||||
$this->readers = $readers;
|
||||
$this->writers = $writers;
|
||||
$this->immutable = $immutable;
|
||||
$this->allowList = $allowList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new repository builder instance with no adapters added.
|
||||
*
|
||||
* @return \Dotenv\Repository\RepositoryBuilder
|
||||
*/
|
||||
public static function createWithNoAdapters()
|
||||
{
|
||||
return new self();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new repository builder instance with the default adapters added.
|
||||
*
|
||||
* @return \Dotenv\Repository\RepositoryBuilder
|
||||
*/
|
||||
public static function createWithDefaultAdapters()
|
||||
{
|
||||
$adapters = \iterator_to_array(self::defaultAdapters());
|
||||
|
||||
return new self($adapters, $adapters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the array of default adapters.
|
||||
*
|
||||
* @return \Generator<\Dotenv\Repository\Adapter\AdapterInterface>
|
||||
*/
|
||||
private static function defaultAdapters()
|
||||
{
|
||||
foreach (self::DEFAULT_ADAPTERS as $adapter) {
|
||||
$instance = $adapter::create();
|
||||
if ($instance->isDefined()) {
|
||||
yield $instance->get();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given name if of an adapterclass.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private static function isAnAdapterClass(string $name)
|
||||
{
|
||||
if (!\class_exists($name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (new ReflectionClass($name))->implementsInterface(AdapterInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a repository builder with the given reader added.
|
||||
*
|
||||
* Accepts either a reader instance, or a class-string for an adapter. If
|
||||
* the adapter is not supported, then we silently skip adding it.
|
||||
*
|
||||
* @param \Dotenv\Repository\Adapter\ReaderInterface|string $reader
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return \Dotenv\Repository\RepositoryBuilder
|
||||
*/
|
||||
public function addReader($reader)
|
||||
{
|
||||
if (!(\is_string($reader) && self::isAnAdapterClass($reader)) && !($reader instanceof ReaderInterface)) {
|
||||
throw new InvalidArgumentException(
|
||||
\sprintf(
|
||||
'Expected either an instance of %s or a class-string implementing %s',
|
||||
ReaderInterface::class,
|
||||
AdapterInterface::class
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$optional = Some::create($reader)->flatMap(static function ($reader) {
|
||||
return \is_string($reader) ? $reader::create() : Some::create($reader);
|
||||
});
|
||||
|
||||
$readers = \array_merge($this->readers, \iterator_to_array($optional));
|
||||
|
||||
return new self($readers, $this->writers, $this->immutable, $this->allowList);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a repository builder with the given writer added.
|
||||
*
|
||||
* Accepts either a writer instance, or a class-string for an adapter. If
|
||||
* the adapter is not supported, then we silently skip adding it.
|
||||
*
|
||||
* @param \Dotenv\Repository\Adapter\WriterInterface|string $writer
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return \Dotenv\Repository\RepositoryBuilder
|
||||
*/
|
||||
public function addWriter($writer)
|
||||
{
|
||||
if (!(\is_string($writer) && self::isAnAdapterClass($writer)) && !($writer instanceof WriterInterface)) {
|
||||
throw new InvalidArgumentException(
|
||||
\sprintf(
|
||||
'Expected either an instance of %s or a class-string implementing %s',
|
||||
WriterInterface::class,
|
||||
AdapterInterface::class
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$optional = Some::create($writer)->flatMap(static function ($writer) {
|
||||
return \is_string($writer) ? $writer::create() : Some::create($writer);
|
||||
});
|
||||
|
||||
$writers = \array_merge($this->writers, \iterator_to_array($optional));
|
||||
|
||||
return new self($this->readers, $writers, $this->immutable, $this->allowList);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a repository builder with the given adapter added.
|
||||
*
|
||||
* Accepts either an adapter instance, or a class-string for an adapter. If
|
||||
* the adapter is not supported, then we silently skip adding it. We will
|
||||
* add the adapter as both a reader and a writer.
|
||||
*
|
||||
* @param \Dotenv\Repository\Adapter\WriterInterface|string $adapter
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return \Dotenv\Repository\RepositoryBuilder
|
||||
*/
|
||||
public function addAdapter($adapter)
|
||||
{
|
||||
if (!(\is_string($adapter) && self::isAnAdapterClass($adapter)) && !($adapter instanceof AdapterInterface)) {
|
||||
throw new InvalidArgumentException(
|
||||
\sprintf(
|
||||
'Expected either an instance of %s or a class-string implementing %s',
|
||||
WriterInterface::class,
|
||||
AdapterInterface::class
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$optional = Some::create($adapter)->flatMap(static function ($adapter) {
|
||||
return \is_string($adapter) ? $adapter::create() : Some::create($adapter);
|
||||
});
|
||||
|
||||
$readers = \array_merge($this->readers, \iterator_to_array($optional));
|
||||
$writers = \array_merge($this->writers, \iterator_to_array($optional));
|
||||
|
||||
return new self($readers, $writers, $this->immutable, $this->allowList);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a repository builder with mutability enabled.
|
||||
*
|
||||
* @return \Dotenv\Repository\RepositoryBuilder
|
||||
*/
|
||||
public function immutable()
|
||||
{
|
||||
return new self($this->readers, $this->writers, true, $this->allowList);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a repository builder with the given allow list.
|
||||
*
|
||||
* @param string[]|null $allowList
|
||||
*
|
||||
* @return \Dotenv\Repository\RepositoryBuilder
|
||||
*/
|
||||
public function allowList(?array $allowList = null)
|
||||
{
|
||||
return new self($this->readers, $this->writers, $this->immutable, $allowList);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new repository instance.
|
||||
*
|
||||
* @return \Dotenv\Repository\RepositoryInterface
|
||||
*/
|
||||
public function make()
|
||||
{
|
||||
$reader = new MultiReader($this->readers);
|
||||
$writer = new MultiWriter($this->writers);
|
||||
|
||||
if ($this->immutable) {
|
||||
$writer = new ImmutableWriter($writer, $reader);
|
||||
}
|
||||
|
||||
if ($this->allowList !== null) {
|
||||
$writer = new GuardedWriter($writer, $this->allowList);
|
||||
}
|
||||
|
||||
return new AdapterRepository($reader, $writer);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Repository;
|
||||
|
||||
interface RepositoryInterface
|
||||
{
|
||||
/**
|
||||
* Determine if the given environment variable is defined.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function has(string $name);
|
||||
|
||||
/**
|
||||
* Get an environment variable.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function get(string $name);
|
||||
|
||||
/**
|
||||
* Set an environment variable.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function set(string $name, string $value);
|
||||
|
||||
/**
|
||||
* Clear an environment variable.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function clear(string $name);
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Store\File;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class Paths
|
||||
{
|
||||
/**
|
||||
* This class is a singleton.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the full paths to the files.
|
||||
*
|
||||
* @param string[] $paths
|
||||
* @param string[] $names
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public static function filePaths(array $paths, array $names)
|
||||
{
|
||||
$files = [];
|
||||
|
||||
foreach ($paths as $path) {
|
||||
foreach ($names as $name) {
|
||||
$files[] = \rtrim($path, \DIRECTORY_SEPARATOR).\DIRECTORY_SEPARATOR.$name;
|
||||
}
|
||||
}
|
||||
|
||||
return $files;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Store\File;
|
||||
|
||||
use Dotenv\Exception\InvalidEncodingException;
|
||||
use Dotenv\Util\Str;
|
||||
use PhpOption\Option;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class Reader
|
||||
{
|
||||
/**
|
||||
* This class is a singleton.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the file(s), and return their raw content.
|
||||
*
|
||||
* We provide the file path as the key, and its content as the value. If
|
||||
* short circuit mode is enabled, then the returned array with have length
|
||||
* at most one. File paths that couldn't be read are omitted entirely.
|
||||
*
|
||||
* @param string[] $filePaths
|
||||
* @param bool $shortCircuit
|
||||
* @param string|null $fileEncoding
|
||||
*
|
||||
* @throws \Dotenv\Exception\InvalidEncodingException
|
||||
*
|
||||
* @return array<string,string>
|
||||
*/
|
||||
public static function read(array $filePaths, bool $shortCircuit = true, ?string $fileEncoding = null)
|
||||
{
|
||||
$output = [];
|
||||
|
||||
foreach ($filePaths as $filePath) {
|
||||
$content = self::readFromFile($filePath, $fileEncoding);
|
||||
if ($content->isDefined()) {
|
||||
$output[$filePath] = $content->get();
|
||||
if ($shortCircuit) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the given file.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string|null $encoding
|
||||
*
|
||||
* @throws \Dotenv\Exception\InvalidEncodingException
|
||||
*
|
||||
* @return \PhpOption\Option<string>
|
||||
*/
|
||||
private static function readFromFile(string $path, ?string $encoding = null)
|
||||
{
|
||||
/** @var Option<string> */
|
||||
$content = Option::fromValue(@\file_get_contents($path), false);
|
||||
|
||||
return $content->flatMap(static function (string $content) use ($encoding) {
|
||||
return Str::utf8($content, $encoding)->mapError(static function (string $error) {
|
||||
throw new InvalidEncodingException($error);
|
||||
})->success();
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotenv\Store;
|
||||
|
||||
use Dotenv\Exception\InvalidPathException;
|
||||
use Dotenv\Store\File\Reader;
|
||||
|
||||
final class FileStore implements StoreInterface
|
||||
{
|
||||
/**
|
||||
* The file paths.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
private $filePaths;
|
||||
|
||||
/**
|
||||
* Should file loading short circuit?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $shortCircuit;
|
||||
|
||||
/**
|
||||
* The file encoding.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
private $fileEncoding;
|
||||
|
||||
/**
|
||||
* Create a new file store instance.
|
||||
*
|
||||
* @param string[] $filePaths
|
||||
* @param bool $shortCircuit
|
||||
* @param string|null $fileEncoding
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $filePaths, bool $shortCircuit, ?string $fileEncoding = null)
|
||||
{
|
||||
$this->filePaths = $filePaths;
|
||||
$this->shortCircuit = $shortCircuit;
|
||||
$this->fileEncoding = $fileEncoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the content of the environment file(s).
|
||||
*
|
||||
* @throws \Dotenv\Exception\InvalidEncodingException|\Dotenv\Exception\InvalidPathException
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function read()
|
||||
{
|
||||
if ($this->filePaths === []) {
|
||||
throw new InvalidPathException('At least one environment file path must be provided.');
|
||||
}
|
||||
|
||||
$contents = Reader::read($this->filePaths, $this->shortCircuit, $this->fileEncoding);
|
||||
|
||||
if (\count($contents) > 0) {
|
||||
return \implode("\n", $contents);
|
||||
}
|
||||
|
||||
throw new InvalidPathException(
|
||||
\sprintf('Unable to read any of the environment file(s) at [%s].', \implode(', ', $this->filePaths))
|
||||
);
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue