Subir proyecto
This commit is contained in:
+3
@@ -0,0 +1,3 @@
|
||||
# Ignore artifacts:
|
||||
build
|
||||
coverage
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["@prettier/plugin-php"]
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"name": "rocklobsterinc/form-data-tree",
|
||||
"description": "FormDataTree for PHP",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Takayuki Miyoshi",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=8.3",
|
||||
"rocklobsterinc/functions": "^v1.0"
|
||||
},
|
||||
"archive": {
|
||||
"exclude": [
|
||||
"/.*",
|
||||
"/package-lock.json",
|
||||
"/package.json"
|
||||
]
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"RockLobsterInc\\FormDataTree\\": "src/"
|
||||
},
|
||||
"files": [
|
||||
"src/functions.php"
|
||||
]
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "parallel-lint src/"
|
||||
},
|
||||
"require-dev": {
|
||||
"php-parallel-lint/php-parallel-lint": "^1.4"
|
||||
}
|
||||
}
|
||||
Generated
Vendored
+126
@@ -0,0 +1,126 @@
|
||||
{
|
||||
"_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": "95cf8acd6f2155e2ac4066f970bd21a9",
|
||||
"packages": [
|
||||
{
|
||||
"name": "rocklobsterinc/functions",
|
||||
"version": "v1.0.6",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/rocklobster-in/functions-php.git",
|
||||
"reference": "5390f54a2cbcadadc373ca069f46c7e02fe36fc6"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/rocklobster-in/functions-php/zipball/5390f54a2cbcadadc373ca069f46c7e02fe36fc6",
|
||||
"reference": "5390f54a2cbcadadc373ca069f46c7e02fe36fc6",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=8.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"php-parallel-lint/php-parallel-lint": "^1.4"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"files": [
|
||||
"src/functions.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Takayuki Miyoshi",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"description": "Rock Lobster's PHP function library",
|
||||
"support": {
|
||||
"issues": "https://github.com/rocklobster-in/functions-php/issues",
|
||||
"source": "https://github.com/rocklobster-in/functions-php/tree/v1.0.6"
|
||||
},
|
||||
"time": "2026-08-14T06:28:00+00:00"
|
||||
}
|
||||
],
|
||||
"packages-dev": [
|
||||
{
|
||||
"name": "php-parallel-lint/php-parallel-lint",
|
||||
"version": "v1.4.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/php-parallel-lint/PHP-Parallel-Lint.git",
|
||||
"reference": "6db563514f27e19595a19f45a4bf757b6401194e"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/php-parallel-lint/PHP-Parallel-Lint/zipball/6db563514f27e19595a19f45a4bf757b6401194e",
|
||||
"reference": "6db563514f27e19595a19f45a4bf757b6401194e",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-json": "*",
|
||||
"php": ">=5.3.0"
|
||||
},
|
||||
"replace": {
|
||||
"grogy/php-parallel-lint": "*",
|
||||
"jakub-onderka/php-parallel-lint": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"nette/tester": "^1.3 || ^2.0",
|
||||
"php-parallel-lint/php-console-highlighter": "0.* || ^1.0",
|
||||
"squizlabs/php_codesniffer": "^3.6"
|
||||
},
|
||||
"suggest": {
|
||||
"php-parallel-lint/php-console-highlighter": "Highlight syntax in code snippet"
|
||||
},
|
||||
"bin": [
|
||||
"parallel-lint"
|
||||
],
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
"./src/"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"BSD-2-Clause"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Jakub Onderka",
|
||||
"email": "ahoj@jakubonderka.cz"
|
||||
}
|
||||
],
|
||||
"description": "This tool checks the syntax of PHP files about 20x faster than serial check.",
|
||||
"homepage": "https://github.com/php-parallel-lint/PHP-Parallel-Lint",
|
||||
"keywords": [
|
||||
"lint",
|
||||
"static analysis"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/php-parallel-lint/PHP-Parallel-Lint/issues",
|
||||
"source": "https://github.com/php-parallel-lint/PHP-Parallel-Lint/tree/v1.4.0"
|
||||
},
|
||||
"time": "2024-03-27T12:14:49+00:00"
|
||||
}
|
||||
],
|
||||
"aliases": [],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": {},
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": {
|
||||
"php": ">=8.3"
|
||||
},
|
||||
"platform-dev": {},
|
||||
"plugin-api-version": "2.9.0"
|
||||
}
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
namespace RockLobsterInc\FormDataTree;
|
||||
|
||||
use function RockLobsterInc\Functions\{strip_whitespaces};
|
||||
|
||||
/**
|
||||
* Class that represents a standard file data in $_FILES.
|
||||
*/
|
||||
class File implements FileInterface
|
||||
{
|
||||
private string $name;
|
||||
private int $size;
|
||||
private string $temporaryFilePath;
|
||||
private int $error;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $properties Properties of the object.
|
||||
*/
|
||||
private function __construct(array $properties = [])
|
||||
{
|
||||
$this->name = $properties["name"];
|
||||
$this->size = $properties["size"];
|
||||
$this->temporaryFilePath = $properties["temporaryFilePath"];
|
||||
$this->error = $properties["error"];
|
||||
}
|
||||
|
||||
/**
|
||||
* Walks through an array and creates File objects if there are
|
||||
* necessary properties.
|
||||
*
|
||||
* @param mixed $array Where to walk.
|
||||
*/
|
||||
private static function walkToFindSelf(mixed $array)
|
||||
{
|
||||
if (
|
||||
isset($array["name"]) and
|
||||
isset($array["size"]) and
|
||||
isset($array["tmp_name"]) and
|
||||
isset($array["error"])
|
||||
) {
|
||||
$name = strip_whitespaces((string) $array["name"]);
|
||||
$size = (int) $array["size"];
|
||||
$tmp_name = strip_whitespaces((string) $array["tmp_name"]);
|
||||
$error = (int) $array["error"];
|
||||
|
||||
if ("" !== $name and 0 !== $size) {
|
||||
return new self([
|
||||
"name" => $name,
|
||||
"size" => $size,
|
||||
"temporaryFilePath" => $tmp_name,
|
||||
"error" => $error,
|
||||
]);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_array($array)) {
|
||||
return array_map("self::walkToFindSelf", $array);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a tree structure based on the $_FILES superglobal. A terminal
|
||||
* node of the tree must be a File object.
|
||||
*
|
||||
* @return array Tree created based on $_FILES.
|
||||
*/
|
||||
public static function buildTree(): array
|
||||
{
|
||||
static $output = [];
|
||||
|
||||
if (!empty($output)) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
$original = $_FILES;
|
||||
|
||||
foreach ($original as $name => $props) {
|
||||
$in_process_array = [];
|
||||
|
||||
foreach ($props as $key => $value) {
|
||||
$in_process_array[] = scalar_to_map($key, $value);
|
||||
}
|
||||
|
||||
$in_process_array = array_replace_recursive(...$in_process_array);
|
||||
|
||||
$output[$name] = self::walkToFindSelf($in_process_array);
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the original name of the file on the client machine.
|
||||
*/
|
||||
public function name(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the size, in bytes, of the file.
|
||||
*/
|
||||
public function size(): int
|
||||
{
|
||||
return $this->size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the full path of the file in which the uploaded file was
|
||||
* stored on the server.
|
||||
*/
|
||||
public function temporaryFilePath(): string
|
||||
{
|
||||
return $this->temporaryFilePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the error code associated with this file upload.
|
||||
*/
|
||||
public function error(): int
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
}
|
||||
Vendored
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace RockLobsterInc\FormDataTree;
|
||||
|
||||
/**
|
||||
* Interface that represents an uploaded file.
|
||||
*/
|
||||
interface FileInterface
|
||||
{
|
||||
/**
|
||||
* Returns the original name of the file on the client machine.
|
||||
*/
|
||||
public function name(): string;
|
||||
|
||||
/**
|
||||
* Returns the size, in bytes, of the file.
|
||||
*/
|
||||
public function size(): int;
|
||||
|
||||
/**
|
||||
* Returns the full path of the file in which the uploaded file was
|
||||
* stored on the server.
|
||||
*/
|
||||
public function temporaryFilePath(): string;
|
||||
|
||||
/**
|
||||
* Returns the error code associated with this file upload.
|
||||
*/
|
||||
public function error(): int;
|
||||
}
|
||||
Vendored
+98
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace RockLobsterInc\FormDataTree;
|
||||
|
||||
use function RockLobsterInc\Functions\{strip_whitespaces, exclude_blank};
|
||||
|
||||
/**
|
||||
* A class that implements FormDataTreeInterface. Wraps the PHP superglobals.
|
||||
*/
|
||||
class FormDataTree implements FormDataTreeInterface
|
||||
{
|
||||
/**
|
||||
* Data origin.
|
||||
*/
|
||||
private array $origin;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $origin Optional data origin.
|
||||
*/
|
||||
public function __construct(array $origin = [])
|
||||
{
|
||||
$this->origin = [
|
||||
"post" => $origin["post"] ?? $_POST,
|
||||
"files" => $origin["files"] ?? File::buildTree(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the values associated with a given field name.
|
||||
*
|
||||
* @param string $name Field name.
|
||||
* @return iterable Iterator of the values.
|
||||
*/
|
||||
public function getAll(string $name): iterable
|
||||
{
|
||||
$name_parts = dissolve_name($name);
|
||||
|
||||
if (empty($name_parts)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$posted_value = $this->origin["post"];
|
||||
|
||||
while ($next = array_shift($name_parts)) {
|
||||
if (
|
||||
preg_match('/^[0-9]*$/', $next) or !isset($posted_value[$next])
|
||||
) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$posted_value = $posted_value[$next];
|
||||
}
|
||||
|
||||
if (!is_array($posted_value)) {
|
||||
$posted_value = [$posted_value];
|
||||
}
|
||||
|
||||
$posted_value = strip_whitespaces($posted_value);
|
||||
$posted_value = exclude_blank($posted_value);
|
||||
|
||||
return $posted_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the file objects associated with a given field name.
|
||||
*
|
||||
* @param string $name Field name.
|
||||
* @return iterable Iterator of the FileInterface objects.
|
||||
*/
|
||||
public function getAllFiles(string $name): iterable
|
||||
{
|
||||
$name_parts = dissolve_name($name);
|
||||
|
||||
if (empty($name_parts)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$files_tree = $this->origin["files"];
|
||||
|
||||
while ($next = array_shift($name_parts)) {
|
||||
if (preg_match('/^[0-9]*$/', $next) or !isset($files_tree[$next])) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$files_tree = $files_tree[$next];
|
||||
}
|
||||
|
||||
if (!is_array($files_tree)) {
|
||||
$files_tree = [$files_tree];
|
||||
}
|
||||
|
||||
$files_tree = exclude_blank($files_tree);
|
||||
|
||||
return $files_tree;
|
||||
}
|
||||
}
|
||||
wp-content/plugins/contact-form-7/vendor/rocklobsterinc/form-data-tree/src/FormDataTreeInterface.php
Vendored
+26
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace RockLobsterInc\FormDataTree;
|
||||
|
||||
/**
|
||||
* An interface that represents form submission data in the key/value pairs
|
||||
* format.
|
||||
*/
|
||||
interface FormDataTreeInterface
|
||||
{
|
||||
/**
|
||||
* Returns the values associated with a given field name.
|
||||
*
|
||||
* @param string $name Field name.
|
||||
* @return iterable Iterator of the values.
|
||||
*/
|
||||
public function getAll(string $name): iterable;
|
||||
|
||||
/**
|
||||
* Returns the file objects associated with a given field name.
|
||||
*
|
||||
* @param string $name Field name.
|
||||
* @return iterable Iterator of the file objects.
|
||||
*/
|
||||
public function getAllFiles(string $name): iterable;
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace RockLobsterInc\FormDataTree;
|
||||
|
||||
use function RockLobsterInc\Functions\{strip_whitespaces};
|
||||
|
||||
/**
|
||||
* Returns components of the given name.
|
||||
*
|
||||
* @param string $name Field name, such as 'abc' or 'abc[de]'.
|
||||
* @return array Single dimension array of name components.
|
||||
*/
|
||||
function dissolve_name(string $name): array
|
||||
{
|
||||
$name = strip_whitespaces($name);
|
||||
|
||||
$s =
|
||||
'[\x09-\x0D\x20\xA0\x{1680}\x{2000}-\x{200A}\x{2028}\x{2029}\x{202F}\x{205F}\x{3000}\x{FEFF}]*';
|
||||
|
||||
$pattern =
|
||||
"/^" .
|
||||
"([a-z][0-9a-z:_-]*)" . // Core
|
||||
"((?:\[" .
|
||||
$s .
|
||||
"(?:[a-z][0-9a-z:_-]*|[0-9]*)" .
|
||||
$s .
|
||||
"\])*)" . // Layers
|
||||
'$/iu';
|
||||
|
||||
if (!preg_match($pattern, $name, $matches)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$core = $matches[1];
|
||||
$layers = $matches[2];
|
||||
|
||||
preg_match_all("/\[(.*?)\]/u", $layers, $matches);
|
||||
|
||||
$layers = array_map(static function (string $item) {
|
||||
return strip_whitespaces($item);
|
||||
}, $matches[1]);
|
||||
|
||||
return [$core, ...$layers];
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a scalar value into a map with a specified key. The original
|
||||
* array structure will be preserved.
|
||||
*
|
||||
* @param string $key Map key.
|
||||
* @param mixed $value Original value.
|
||||
* @return array Array.
|
||||
*/
|
||||
function scalar_to_map(string $key, mixed $value): array
|
||||
{
|
||||
if (is_scalar($value)) {
|
||||
return [$key => $value];
|
||||
}
|
||||
|
||||
if (is_array($value)) {
|
||||
return array_map(static function ($item) use ($key) {
|
||||
return scalar_to_map($key, $item);
|
||||
}, $value);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
Reference in New Issue
Block a user