sistemazione composer install

This commit is contained in:
mariano
2026-05-22 14:13:33 +02:00
parent ad42773519
commit ed29fbc62d
252 changed files with 52727 additions and 13 deletions
+75
View File
@@ -0,0 +1,75 @@
<?php
$config = (new PhpCsFixer\Config())
->setIndent(" ")
->setLineEnding("\n")
->setCacheFile(__DIR__ . '/.php-cs-fixer.cache')
->setRiskyAllowed(true)
->setRules([
'@PHP71Migration' => true,
'@PHP73Migration' => false,
'@PhpCsFixer' => true,
'@PhpCsFixer:risky' => true,
'@PSR12' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
'align_multiline_comment' => true,
'array_indentation' => true,
'array_syntax' => ['syntax' => 'short'],
'combine_consecutive_issets' => true,
'combine_consecutive_unsets' => true,
'combine_nested_dirname' => true,
'comment_to_phpdoc' => true,
'compact_nullable_typehint' => true,
'concat_space' => ['spacing' => 'one'],
'escape_implicit_backslashes' => false,
'fully_qualified_strict_types' => true,
'linebreak_after_opening_tag' => true,
'list_syntax' => ['syntax' => 'short'],
'method_argument_space' => ['ensure_fully_multiline' => true],
'native_constant_invocation' => true,
'native_function_invocation' => true,
'native_function_type_declaration_casing' => true,
'no_alternative_syntax' => true,
'no_multiline_whitespace_before_semicolons' => true,
'no_null_property_initialization' => true,
'no_short_echo_tag' => true,
'no_superfluous_elseif' => true,
'no_unneeded_control_parentheses' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'not_operator_with_space' => false,
'not_operator_with_successor_space' => false,
'ordered_class_elements' => true,
'ordered_imports' => ['sort_algorithm' => 'alpha', 'imports_order' => ['class', 'const', 'function']],
'ordered_interfaces' => true,
'php_unit_ordered_covers' => true,
'php_unit_set_up_tear_down_visibility' => true,
'php_unit_strict' => true,
'php_unit_test_class_requires_covers' => true,
'phpdoc_add_missing_param_annotation' => true,
'phpdoc_order' => true,
'phpdoc_to_comment' => false,
'phpdoc_types_order' => true,
'pow_to_exponentiation' => true,
'random_api_migration' => true,
'return_assignment' => false,
'simple_to_complex_string_variable' => true,
'single_line_comment_style' => true,
'single_trait_insert_per_statement' => true,
'strict_comparison' => false,
'strict_param' => false,
'string_line_ending' => true,
'yoda_style' => false,
])
->setFinder(
PhpCsFixer\Finder::create()
->exclude('libs')
->exclude('tests/Fixtures')
->exclude('var')
->exclude('vendor')
->in(__DIR__)
)
;
return $config;
+65
View File
@@ -0,0 +1,65 @@
## VERSION 3 REMOVE GLOBAL FUNCTIONS
* Version **3.0** - Remove global functions
* 2021-05-27 10:44 **3.0.0** initial release
* fd33968 chore(ci): no need for hirak/prestissimo as of Composer 2
* bbdd9d8 chore(ci): also test against PHP 8.0
* 069f3b6 chore: add "liip/rmt" as a dev dep
* 4cb784c chore: update php-cs-fixer config
* 1de05ac docs: update license year
* fcd87d8 chore: update deps
* 9587412 feat: remove helper.php
* 088ade8 chore(ci): migrate CI from Travis to GitHub Actions
* b06f614 chore: update license year
## VERSION 2 NAMESPACE CHANGE
* Version **2.0** - namespace change
* 2020-05-28 03:24 **2.0.2** allow PHP 8
* 1ef5198 chore: update deps
* 3c6ba82 chore: Composer PHP constrain >=7.1.3
* 5035eba chore: update deps
* c19946b docs: update readme
* 2020-04-06 15:51 **2.0.1** fix demo.php
* 245aa2f chore: allow PHPUnit ^9
* f139892 chore: update deps
* a09f00f fix: fix demo.php
* 8384498 Update deps
* 40e0d43 Update .travis.yml to PHP 7.4 stable
* 2746bcf Add php_codesniffer
* 6f96961 Update readme to use badges from shields.io
* 2019-07-13 17:50 **2.0.0** initial release
* d522a7d Add UPGRADING_v2.md
* 33fc823 Rename/modify CHANGELOG -> CHANGELOG.md
* 056f68a Renamed namespace and functions
* e036a8d Update deps
* 2a0b002 Update deps
* f51db25 Add .gitattributes
* 2e644d4 $ composer fix
* d9df730 Update deps
* 6556ba0 Update .travis.yml for 7.4snapshot
* e6b57cd Add .editorconfig
* 8b93884 Update deps
* e7be444 Temporary fix for CI
* 434fff4 year++
* 2c4077f Add tests for PHP 7.3
## VERSION 1 INIT
* Version **1.0** - init
* 2018-11-27 21:25 **1.0.8** nits
* 61d365e Update codes
* b6e69f0 Update README
* 69d84bf Update deps
* 2018-09-04 18:56 **1.0.7** php-cs-fixer
* 7dd1322 php-cs-fixer: enable native_constant_invocation and native_function_invocation
* 1a1d921 Update deps
* 1af0ae3 Rename CHANGELOG.md -> CHANGELOG
* 47776c4 Update deps
* 2de4f26 Update .travis.yml
* 2018-07-18 08:47 **1.0.6** Add composer.lock
* 0281a77 Add composer.lock
* 2018-07-04 15:33 **1.0.5** nits
* fcecbfb Update .rmt.yml
* 2018-07-04 15:06 **1.0.4** initial release
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2018-2021 Jack Cherng <jfcherng@gmail.com>
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.
+95
View File
@@ -0,0 +1,95 @@
# php-color-output
[![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/jfcherng/php-color-output/Main/master?style=flat-square)](https://github.com/jfcherng/php-color-output/actions)
[![Packagist](https://img.shields.io/packagist/dt/jfcherng/php-color-output?style=flat-square)](https://packagist.org/packages/jfcherng/php-color-output)
[![Packagist Version](https://img.shields.io/packagist/v/jfcherng/php-color-output?style=flat-square)](https://packagist.org/packages/jfcherng/php-color-output)
[![Project license](https://img.shields.io/github/license/jfcherng/php-color-output?style=flat-square)](https://github.com/jfcherng/php-color-output/blob/master/LICENSE)
[![GitHub stars](https://img.shields.io/github/stars/jfcherng/php-color-output?style=flat-square&logo=github)](https://github.com/jfcherng/php-color-output/stargazers)
[![Donate to this project using Paypal](https://img.shields.io/badge/paypal-donate-blue.svg?style=flat-square&logo=paypal)](https://www.paypal.me/jfcherng/5usd)
![demo.gif](https://github.com/jfcherng/php-color-output/blob/gh-pages/images/demo.gif?raw=true)
The above screenshot is the output of `demo.php`. See the [Example](#example) section.
## Installation
```text
composer require jfcherng/php-color-output
```
## Available Styles
| Background | Foreground | Compound | Special | Alias |
| --- | --- | --- | --- | --- |
| b_black | f_black | f_dark_gray | blink | b (bold) |
| b_blue | f_blue | f_light_blue | bold | blk (blink) |
| b_cyan | f_brown | f_light_cyan | dim | h (hidden) |
| b_green | f_cyan | f_light_green | hidden | rev (reverse) |
| b_light_gray | f_green | f_light_purple | reset | rst (reset) |
| b_magenta | f_light_gray | f_light_red | reverse | u (underline) |
| b_red | f_normal | f_white | underline | - |
| b_yellow | f_purple | f_yellow | - | - |
| - | f_red | - | - | - |
## Functions and Methods
```php
<?php
/**
* Make a string colorful.
*
* @param string $str the string
* @param string|string[] $colors the colors
* @param bool $reset reset color at the end of the string?
*
* @return string the colored string
*/
\Jfcherng\Utility\CliColor::color(string $str, $colors = [], bool $reset = true): string
/**
* Remove all colors from a string.
*
* @param string $str the string
*
* @return string the string without colors
*/
\Jfcherng\Utility\CliColor::noColor(string $str): string
```
## Example
```php
<?php
include __DIR__ . '/vendor/autoload.php';
use \Jfcherng\Utility\CliColor;
// colors in a string using a comma as the delimiter
echo CliColor::color('foo', 'f_light_cyan, b_yellow'); // "\033[1;36;43mfoo\033[0m"
echo PHP_EOL;
// colors in an array
echo CliColor::color('foo', ['f_white', 'b_magenta']); // "\033[1;37;45mfoo\033[0m"
echo PHP_EOL;
// do not auto reset color at the end of string
echo CliColor::color('foo', ['f_red', 'b_green', 'b', 'blk'], false); // "\033[31;42;1;5mfoo"
// manually add color reset
echo CliColor::color('', 'reset'); // "\033[0m"
echo PHP_EOL;
// remove all color codes from a string
echo CliColor::noColor("\033[31;42;5mfoo\033[0mbar"); // "foobar"
echo PHP_EOL;
```
+4
View File
@@ -0,0 +1,4 @@
#!/usr/bin/env php
<?php
define('RMT_ROOT_DIR', __DIR__);
require 'vendor\liip\rmt\command.php';
+4
View File
@@ -0,0 +1,4 @@
## Upgrading to v2
- The class name/namespace has been changed from `Jfcherng\Color\Colorful` to `Jfcherng\Utility\CliColor`.
- The names of helper functions have been changed from `str_color/str_nocolor` to `str_cli_color/str_cli_nocolor`.
+58
View File
@@ -0,0 +1,58 @@
{
"name": "jfcherng/php-color-output",
"description": "Make your PHP command-line application colorful.",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Jack Cherng",
"email": "jfcherng@gmail.com"
}
],
"keywords": [
"command-line",
"color",
"ansi-colors",
"str-color"
],
"minimum-stability": "beta",
"prefer-stable": true,
"autoload": {
"psr-4": {
"Jfcherng\\Utility\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Jfcherng\\Utility\\Test\\": "tests/"
}
},
"require": {
"php": ">=7.1.3"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.19",
"liip/rmt": "^1.6",
"phan/phan": "^2 || ^3 || ^4",
"phpunit/phpunit": ">=7 <10",
"squizlabs/php_codesniffer": "^3.5"
},
"config": {
"platform": {
"php": "7.1.3"
},
"sort-packages": true
},
"scripts": {
"analyze": [
"phan --color",
"phpcs --colors -n"
],
"fix": [
"php-cs-fixer fix --verbose"
],
"test": [
"phpunit --verbose"
]
}
}
+3864
View File
File diff suppressed because it is too large Load Diff
+28
View File
@@ -0,0 +1,28 @@
<?php
include __DIR__ . '/vendor/autoload.php';
use Jfcherng\Utility\CliColor;
// colors in a string using a comma as the delimiter
echo CliColor::color('foo', 'f_light_cyan, b_yellow'); // "\033[1;36;43mfoo\033[0m"
echo \PHP_EOL;
// colors in an array
echo CliColor::color('foo', ['f_white', 'b_magenta']); // "\033[1;37;45mfoo\033[0m"
echo \PHP_EOL;
// do not auto reset color at the end of string
echo CliColor::color('foo', ['f_red', 'b_green', 'b', 'blk'], false); // "\033[31;42;1;5mfoo"
// manually add color reset
echo CliColor::color('', 'reset'); // "\033[0m"
echo \PHP_EOL;
// remove all color codes from a string
echo CliColor::noColor("\033[31;42;5mfoo\033[0mbar"); // "foobar"
echo \PHP_EOL;
+224
View File
@@ -0,0 +1,224 @@
<?php
declare(strict_types=1);
namespace Jfcherng\Utility;
/**
* Make your PHP command-line application colorful.
*
* @see https://en.wikipedia.org/wiki/ANSI_escape_code
*
* @author Jack Cherng <jfcherng@gmail.com>
*/
final class CliColor
{
const COLOR_BEGIN = "\033[";
const COLOR_END = 'm';
const COLOR_BEGIN_REGEX = "\033\\[";
const COLOR_END_REGEX = 'm';
/**
* @var array the color map
*/
private static $colorMap = [
// background
'b_black' => '40',
'b_blue' => '44',
'b_cyan' => '46',
'b_green' => '42',
'b_light_gray' => '47',
'b_magenta' => '45',
'b_red' => '41',
'b_yellow' => '43',
// foreground
'f_black' => '30',
'f_blue' => '34',
'f_brown' => '33',
'f_cyan' => '36',
'f_green' => '32',
'f_light_gray' => '37',
'f_normal' => '39',
'f_purple' => '35',
'f_red' => '31',
// compound
'f_dark_gray' => '1;30',
'f_light_blue' => '1;34',
'f_light_cyan' => '1;36',
'f_light_green' => '1;32',
'f_light_purple' => '1;35',
'f_light_red' => '1;31',
'f_white' => '1;37',
'f_yellow' => '1;33',
// special
'blink' => '5',
'bold' => '1',
'dim' => '2',
'hidden' => '8',
'reset' => '0',
'reverse' => '7',
'underline' => '4',
// alias
'b' => 'bold',
'blk' => 'blink',
'h' => 'hidden',
'rev' => 'reverse',
'rst' => 'reset',
'u' => 'underline',
// regex for color codes
'regex_any' => '(?:[0-9]++;?)++',
];
/**
* Get the color map.
*
* @return array the color map
*/
public static function getColorMap(): array
{
return self::$colorMap;
}
/**
* Make a string colorful.
*
* @param string $str the string
* @param string|string[] $colors the colors
* @param bool $reset reset color at the end of the string?
*
* @return string the colored string
*/
public static function color(string $str, $colors = [], bool $reset = true): string
{
// always convert $colors into an array
if (\is_string($colors)) {
$colors = \explode(',', $colors);
}
$colored = self::getColorCode($colors) . $str;
if ($reset) {
$colored .= self::getColorCode(['reset']);
}
return self::simplifyColoredString($colored);
}
/**
* Remove all colors from a string.
*
* @param string $str the string
*
* @return string the string without colors
*/
public static function noColor(string $str): string
{
return \preg_replace(
'~' . self::getColorCode(['regex_any'], true) . '~uS',
'',
$str
);
}
/**
* Get the color code from given colors.
*
* @param array $colors the colors
* @param bool $returnRegex return as an regex segment
*
* @return string the color code
*/
private static function getColorCode(array $colors, bool $returnRegex = false): string
{
$colors = self::sanitizeColors($colors);
if (empty($colors)) {
return '';
}
// convert color into color code
$colorCodes = \array_map(
function (string $color): string {
// resolve color alias
while (isset(self::$colorMap[$color])) {
$color = self::$colorMap[$color];
}
return $color;
},
$colors
);
$closures = $returnRegex
? [self::COLOR_BEGIN_REGEX, self::COLOR_END_REGEX]
: [self::COLOR_BEGIN, self::COLOR_END];
return $closures[0] . \implode(';', $colorCodes) . $closures[1];
}
/**
* Sanitize colors.
*
* @param array $colors the colors
*
* @return array the sanitized colors
*/
private static function sanitizeColors(array $colors): array
{
return self::listUnique(\array_filter(
\array_map('trim', $colors),
function (string $color): bool {
return isset(self::$colorMap[$color]);
}
));
}
/**
* Simplify the colored string.
*
* @param string $str the colored string
*
* @return string the simplified colored string
*/
private static function simplifyColoredString(string $str): string
{
// replace multiple consecutive resets with a single reset
$str = \preg_replace(
'~(' . self::getColorCode(['reset'], true) . '){2,}~uS',
'$1',
$str
);
// remove colors for an emtpy string
$str = \preg_replace(
(
'~' .
'(' . self::getColorCode(['regex_any'], true) . ')' .
'(' . self::getColorCode(['reset'], true) . ')' .
'~uS'
),
'$2',
$str
);
return $str;
}
/**
* The fastest array_unique() implementation for a non-associative array AFAIK.
*
* @see https://stackoverflow.com/questions/8321620/array-unique-vs-array-flip
*
* @param array $array the array
*/
private static function listUnique(array $array): array
{
return \array_keys(\array_count_values($array));
}
}