home
This commit is contained in:
+3
@@ -0,0 +1,3 @@
|
||||
# Ignore artifacts:
|
||||
build
|
||||
coverage
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["@prettier/plugin-php"]
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"name": "rocklobsterinc/functions",
|
||||
"description": "Rock Lobster's PHP function library",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Takayuki Miyoshi",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=8.3"
|
||||
},
|
||||
"archive": {
|
||||
"exclude": [
|
||||
"/.*",
|
||||
"/package-lock.json",
|
||||
"/package.json"
|
||||
]
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
"src/functions.php"
|
||||
]
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "parallel-lint src/"
|
||||
},
|
||||
"require-dev": {
|
||||
"php-parallel-lint/php-parallel-lint": "^1.4"
|
||||
}
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
{
|
||||
"_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": "0e474568fe06ec195ce4053cb1007d2d",
|
||||
"packages": [],
|
||||
"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"
|
||||
}
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace RockLobsterInc\Functions;
|
||||
|
||||
/**
|
||||
* Converts multi-dimensional array to a flat array.
|
||||
*
|
||||
* @param mixed $input Array or item of array.
|
||||
* @return array Flatten array.
|
||||
*/
|
||||
function array_flatten(mixed $input): array
|
||||
{
|
||||
if (!is_array($input)) {
|
||||
return [$input];
|
||||
}
|
||||
|
||||
return array_reduce(
|
||||
$input,
|
||||
static function ($carry, $item) {
|
||||
return array_merge($carry, array_flatten($item));
|
||||
},
|
||||
[],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Strips surrounding whitespaces.
|
||||
*
|
||||
* @param string|array $input Input text or array of text.
|
||||
* @return string|array Output text or array of text.
|
||||
*/
|
||||
function strip_whitespaces(string|array $input): string|array
|
||||
{
|
||||
if (is_array($input)) {
|
||||
return array_map(static function ($item) {
|
||||
return strip_whitespaces($item);
|
||||
}, $input);
|
||||
}
|
||||
|
||||
$whitespaces =
|
||||
'\x09-\x0D\x20\xA0\x{1680}\x{2000}-\x{200A}\x{2028}\x{2029}\x{202F}\x{205F}\x{3000}\x{FEFF}';
|
||||
|
||||
$input = preg_replace(sprintf("/^[%s]+/u", $whitespaces), "", $input);
|
||||
|
||||
$input = preg_replace(sprintf('/[%s]+$/u', $whitespaces), "", $input);
|
||||
|
||||
return $input;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts all newline characters into line feed (LF).
|
||||
*
|
||||
* @param string|array $input Input text or array of text.
|
||||
* @return string|array Output text or array of text.
|
||||
*/
|
||||
function canonicalize_newline(string|array $input): string|array
|
||||
{
|
||||
if (is_array($input)) {
|
||||
return array_map(static function ($item) {
|
||||
return canonicalize_newline($item);
|
||||
}, $input);
|
||||
}
|
||||
|
||||
return str_replace(["\r\n", "\r", "\n"], "\n", $input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Excludes unset or blank text values from the given array.
|
||||
*
|
||||
* @param array $input The array.
|
||||
* @return array Array without blank text values.
|
||||
*/
|
||||
function exclude_blank(array $input): array
|
||||
{
|
||||
$output = [];
|
||||
|
||||
foreach ($input as $key => $item) {
|
||||
if (is_array($item)) {
|
||||
$item = exclude_blank($item);
|
||||
|
||||
if (!empty($item)) {
|
||||
$output[$key] = $item;
|
||||
}
|
||||
} elseif (isset($item)) {
|
||||
if ("" !== $item) {
|
||||
$output[$key] = $item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
Reference in New Issue
Block a user