package and depencies
This commit is contained in:
1
vendor/nunomaduro/collision/.temp/.gitkeep
vendored
Normal file
1
vendor/nunomaduro/collision/.temp/.gitkeep
vendored
Normal file
@@ -0,0 +1 @@
|
||||
.gitkeep
|
13
vendor/nunomaduro/collision/README.md
vendored
13
vendor/nunomaduro/collision/README.md
vendored
@@ -1,3 +1,7 @@
|
||||
<a href="https://supportukrainenow.org/"><img src="https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner-direct.svg" width="100%"></a>
|
||||
|
||||
------
|
||||
|
||||
<p align="center">
|
||||
<img src="https://raw.githubusercontent.com/nunomaduro/collision/stable/docs/logo.png" alt="Collision logo" width="480">
|
||||
<br>
|
||||
@@ -22,7 +26,7 @@ Collision was created by, and is maintained by **[Nuno Maduro](https://github.co
|
||||
|
||||
## Installation & Usage
|
||||
|
||||
> **Requires [PHP 7.3+](https://php.net/releases/)**
|
||||
> **Requires [PHP 8.0+](https://php.net/releases/)**
|
||||
|
||||
Require Collision using [Composer](https://getcomposer.org):
|
||||
|
||||
@@ -37,6 +41,7 @@ composer require nunomaduro/collision --dev
|
||||
6.x | 3.x
|
||||
7.x | 4.x
|
||||
8.x | 5.x
|
||||
9.x | 6.x
|
||||
|
||||
As an example, here is how to require Collision on Laravel 6.x:
|
||||
|
||||
@@ -69,12 +74,6 @@ Thank you for considering to contribute to Collision. All the contribution guide
|
||||
|
||||
You can have a look at the [CHANGELOG](CHANGELOG.md) for constant updates & detailed information about the changes. You can also follow the twitter account for latest announcements or just come say hi!: [@enunomaduro](https://twitter.com/enunomaduro)
|
||||
|
||||
## Support the development
|
||||
**Do you like this project? Support it by donating**
|
||||
|
||||
- PayPal: [Donate](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=66BYDWAT92N6L)
|
||||
- Patreon: [Donate](https://www.patreon.com/nunomaduro)
|
||||
|
||||
## License
|
||||
|
||||
Collision is an open-sourced software licensed under the [MIT license](LICENSE.md).
|
||||
|
35
vendor/nunomaduro/collision/composer.json
vendored
35
vendor/nunomaduro/collision/composer.json
vendored
@@ -14,21 +14,19 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.3 || ^8.0",
|
||||
"facade/ignition-contracts": "^1.0",
|
||||
"filp/whoops": "^2.14.3",
|
||||
"symfony/console": "^5.0"
|
||||
"php": "^8.0.0",
|
||||
"filp/whoops": "^2.14.5",
|
||||
"symfony/console": "^6.0.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"brianium/paratest": "^6.1",
|
||||
"fideloper/proxy": "^4.4.1",
|
||||
"fruitcake/laravel-cors": "^2.0.3",
|
||||
"laravel/framework": "8.x-dev",
|
||||
"nunomaduro/larastan": "^0.6.2",
|
||||
"nunomaduro/mock-final-classes": "^1.0",
|
||||
"orchestra/testbench": "^6.0",
|
||||
"phpstan/phpstan": "^0.12.64",
|
||||
"phpunit/phpunit": "^9.5.0"
|
||||
"brianium/paratest": "^6.4.1",
|
||||
"laravel/framework": "^9.26.1",
|
||||
"laravel/pint": "^1.1.1",
|
||||
"nunomaduro/larastan": "^1.0.3",
|
||||
"nunomaduro/mock-final-classes": "^1.1.0",
|
||||
"orchestra/testbench": "^7.7",
|
||||
"phpunit/phpunit": "^9.5.23",
|
||||
"spatie/ignition": "^1.4.1"
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
@@ -47,9 +45,15 @@
|
||||
},
|
||||
"config": {
|
||||
"preferred-install": "dist",
|
||||
"sort-packages": true
|
||||
"sort-packages": true,
|
||||
"allow-plugins": {
|
||||
"pestphp/pest-plugin": true
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-develop": "6.x-dev"
|
||||
},
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"NunoMaduro\\Collision\\Adapters\\Laravel\\CollisionServiceProvider"
|
||||
@@ -57,9 +61,12 @@
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "pint -v",
|
||||
"test:lint": "pint --test -v",
|
||||
"test:types": "phpstan analyse --ansi",
|
||||
"test:unit": "phpunit --colors=always",
|
||||
"test": [
|
||||
"@test:lint",
|
||||
"@test:types",
|
||||
"@test:unit"
|
||||
]
|
||||
|
@@ -44,12 +44,14 @@ class CollisionServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
if ($this->app->runningInConsole() && !$this->app->runningUnitTests()) {
|
||||
if ($this->app->runningInConsole() && ! $this->app->runningUnitTests()) {
|
||||
$this->app->bind(ProviderContract::class, function () {
|
||||
if ($this->app->has(\Facade\IgnitionContracts\SolutionProviderRepository::class)) {
|
||||
$solutionsRepository = new IgnitionSolutionsRepository(
|
||||
$this->app->get(\Facade\IgnitionContracts\SolutionProviderRepository::class)
|
||||
);
|
||||
// @phpstan-ignore-next-line
|
||||
if ($this->app->has(\Spatie\Ignition\Contracts\SolutionProviderRepository::class)) {
|
||||
/** @var \Spatie\Ignition\Contracts\SolutionProviderRepository $solutionProviderRepository */
|
||||
$solutionProviderRepository = $this->app->get(\Spatie\Ignition\Contracts\SolutionProviderRepository::class);
|
||||
|
||||
$solutionsRepository = new IgnitionSolutionsRepository($solutionProviderRepository);
|
||||
} else {
|
||||
$solutionsRepository = new NullSolutionsRepository();
|
||||
}
|
||||
@@ -60,6 +62,7 @@ class CollisionServiceProvider extends ServiceProvider
|
||||
return new Provider(null, $handler);
|
||||
});
|
||||
|
||||
/** @var \Illuminate\Contracts\Debug\ExceptionHandler $appExceptionHandler */
|
||||
$appExceptionHandler = $this->app->make(ExceptionHandlerContract::class);
|
||||
|
||||
$this->app->singleton(
|
||||
|
@@ -11,6 +11,7 @@ use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Env;
|
||||
use Illuminate\Support\Str;
|
||||
use NunoMaduro\Collision\Adapters\Laravel\Exceptions\RequirementsException;
|
||||
use NunoMaduro\Collision\Coverage;
|
||||
use RuntimeException;
|
||||
use Symfony\Component\Process\Exception\ProcessSignaledException;
|
||||
use Symfony\Component\Process\Process;
|
||||
@@ -29,8 +30,11 @@ class TestCommand extends Command
|
||||
*/
|
||||
protected $signature = 'test
|
||||
{--without-tty : Disable output to TTY}
|
||||
{--coverage : Indicates whether code coverage information should be collected}
|
||||
{--min= : Indicates the minimum threshold enforcement for code coverage}
|
||||
{--p|parallel : Indicates if the tests should run in parallel}
|
||||
{--recreate-databases : Indicates if the test databases should be re-created}
|
||||
{--drop-databases : Indicates if the test databases should be dropped}
|
||||
';
|
||||
|
||||
/**
|
||||
@@ -59,17 +63,38 @@ class TestCommand extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
if ((int) \PHPUnit\Runner\Version::id()[0] < 9) {
|
||||
throw new RequirementsException('Running Collision ^5.0 artisan test command requires at least PHPUnit ^9.0.');
|
||||
$phpunitVersion = \PHPUnit\Runner\Version::id();
|
||||
|
||||
if ((int) $phpunitVersion[0] === 1) {
|
||||
throw new RequirementsException('Running PHPUnit 10.x or Pest 2.x requires Collision 7.x.');
|
||||
}
|
||||
|
||||
if ((int) $phpunitVersion[0] < 9) {
|
||||
throw new RequirementsException('Running Collision 6.x artisan test command requires at least PHPUnit 9.x.');
|
||||
}
|
||||
|
||||
$laravelVersion = (int) \Illuminate\Foundation\Application::VERSION;
|
||||
|
||||
// @phpstan-ignore-next-line
|
||||
if ((int) \Illuminate\Foundation\Application::VERSION[0] < 8) {
|
||||
throw new RequirementsException('Running Collision ^5.0 artisan test command requires at least Laravel ^8.0.');
|
||||
if ($laravelVersion < 9) {
|
||||
throw new RequirementsException('Running Collision 6.x artisan test command requires at least Laravel 9.x.');
|
||||
}
|
||||
|
||||
if ($this->option('parallel') && !$this->isParallelDependenciesInstalled()) {
|
||||
if (!$this->confirm('Running tests in parallel requires "brianium/paratest". Do you wish to install it as a dev dependency?')) {
|
||||
if ($this->option('coverage') && ! Coverage::isAvailable()) {
|
||||
$this->output->writeln(sprintf(
|
||||
"\n <fg=white;bg=red;options=bold> ERROR </> Code coverage driver not available.%s</>",
|
||||
Coverage::usingXdebug()
|
||||
? " Did you set <href=https://xdebug.org/docs/code_coverage#mode>Xdebug's coverage mode</>?"
|
||||
: ''
|
||||
));
|
||||
|
||||
$this->newLine();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ($this->option('parallel') && ! $this->isParallelDependenciesInstalled()) {
|
||||
if (! $this->confirm('Running tests in parallel requires "brianium/paratest". Do you wish to install it as a dev dependency?')) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -83,24 +108,26 @@ class TestCommand extends Command
|
||||
$parallel = $this->option('parallel');
|
||||
|
||||
$process = (new Process(array_merge(
|
||||
// Binary ...
|
||||
$this->binary(),
|
||||
// Arguments ...
|
||||
$parallel ? $this->paratestArguments($options) : $this->phpunitArguments($options)
|
||||
),
|
||||
// Binary ...
|
||||
$this->binary(),
|
||||
// Arguments ...
|
||||
$parallel ? $this->paratestArguments($options) : $this->phpunitArguments($options)
|
||||
),
|
||||
null,
|
||||
// Envs ...
|
||||
$parallel ? $this->paratestEnvironmentVariables() : $this->phpunitEnvironmentVariables(),
|
||||
))->setTimeout(null);
|
||||
|
||||
try {
|
||||
$process->setTty(!$this->option('without-tty'));
|
||||
$process->setTty(! $this->option('without-tty'));
|
||||
} catch (RuntimeException $e) {
|
||||
$this->output->writeln('Warning: ' . $e->getMessage());
|
||||
$this->output->writeln('Warning: '.$e->getMessage());
|
||||
}
|
||||
|
||||
$exitCode = 1;
|
||||
|
||||
try {
|
||||
return $process->run(function ($type, $line) {
|
||||
$exitCode = $process->run(function ($type, $line) {
|
||||
$this->output->write($line);
|
||||
});
|
||||
} catch (ProcessSignaledException $e) {
|
||||
@@ -108,6 +135,28 @@ class TestCommand extends Command
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
if ($exitCode === 0 && $this->option('coverage')) {
|
||||
if (! $this->usingPest() && $this->option('parallel')) {
|
||||
$this->newLine();
|
||||
}
|
||||
|
||||
$coverage = Coverage::report($this->output);
|
||||
|
||||
$exitCode = (int) ($coverage < $this->option('min'));
|
||||
|
||||
if ($exitCode === 1) {
|
||||
$this->output->writeln(sprintf(
|
||||
"\n <fg=white;bg=red;options=bold> FAIL </> Code coverage below expected:<fg=red;options=bold> %s %%</>. Minimum:<fg=white;options=bold> %s %%</>.",
|
||||
number_format($coverage, 1),
|
||||
number_format((float) $this->option('min'), 1)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
$this->newLine();
|
||||
|
||||
return $exitCode;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,7 +166,7 @@ class TestCommand extends Command
|
||||
*/
|
||||
protected function binary()
|
||||
{
|
||||
if (class_exists(\Pest\Laravel\PestServiceProvider::class)) {
|
||||
if ($this->usingPest()) {
|
||||
$command = $this->option('parallel') ? ['vendor/pestphp/pest/bin/pest', '--parallel'] : ['vendor/pestphp/pest/bin/pest'];
|
||||
} else {
|
||||
$command = $this->option('parallel') ? ['vendor/brianium/paratest/bin/paratest'] : ['vendor/phpunit/phpunit/phpunit'];
|
||||
@@ -130,11 +179,37 @@ class TestCommand extends Command
|
||||
return array_merge([PHP_BINARY], $command);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the common arguments of PHPUnit and Pest.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function commonArguments()
|
||||
{
|
||||
$arguments = [];
|
||||
|
||||
if ($this->option('coverage')) {
|
||||
$arguments[] = '--coverage-php';
|
||||
$arguments[] = Coverage::getPath();
|
||||
}
|
||||
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if Pest is being used.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function usingPest()
|
||||
{
|
||||
return class_exists(\Pest\Laravel\PestServiceProvider::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array of arguments for running PHPUnit.
|
||||
*
|
||||
* @param array $options
|
||||
*
|
||||
* @param array $options
|
||||
* @return array
|
||||
*/
|
||||
protected function phpunitArguments($options)
|
||||
@@ -142,37 +217,45 @@ class TestCommand extends Command
|
||||
$options = array_merge(['--printer=NunoMaduro\\Collision\\Adapters\\Phpunit\\Printer'], $options);
|
||||
|
||||
$options = array_values(array_filter($options, function ($option) {
|
||||
return !Str::startsWith($option, '--env=');
|
||||
return ! Str::startsWith($option, '--env=')
|
||||
&& $option != '-q'
|
||||
&& $option != '--quiet'
|
||||
&& $option != '--coverage'
|
||||
&& ! Str::startsWith($option, '--min');
|
||||
}));
|
||||
|
||||
if (!file_exists($file = base_path('phpunit.xml'))) {
|
||||
if (! file_exists($file = base_path('phpunit.xml'))) {
|
||||
$file = base_path('phpunit.xml.dist');
|
||||
}
|
||||
|
||||
return array_merge(["--configuration=$file"], $options);
|
||||
return array_merge($this->commonArguments(), ["--configuration=$file"], $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array of arguments for running Paratest.
|
||||
*
|
||||
* @param array $options
|
||||
*
|
||||
* @param array $options
|
||||
* @return array
|
||||
*/
|
||||
protected function paratestArguments($options)
|
||||
{
|
||||
$options = array_values(array_filter($options, function ($option) {
|
||||
return !Str::startsWith($option, '--env=')
|
||||
&& !Str::startsWith($option, '-p')
|
||||
&& !Str::startsWith($option, '--parallel')
|
||||
&& !Str::startsWith($option, '--recreate-databases');
|
||||
return ! Str::startsWith($option, '--env=')
|
||||
&& $option != '--coverage'
|
||||
&& $option != '-q'
|
||||
&& $option != '--quiet'
|
||||
&& ! Str::startsWith($option, '--min')
|
||||
&& ! Str::startsWith($option, '-p')
|
||||
&& ! Str::startsWith($option, '--parallel')
|
||||
&& ! Str::startsWith($option, '--recreate-databases')
|
||||
&& ! Str::startsWith($option, '--drop-databases');
|
||||
}));
|
||||
|
||||
if (!file_exists($file = base_path('phpunit.xml'))) {
|
||||
if (! file_exists($file = base_path('phpunit.xml'))) {
|
||||
$file = base_path('phpunit.xml.dist');
|
||||
}
|
||||
|
||||
return array_merge([
|
||||
return array_merge($this->commonArguments(), [
|
||||
"--configuration=$file",
|
||||
"--runner=\Illuminate\Testing\ParallelRunner",
|
||||
], $options);
|
||||
@@ -196,8 +279,9 @@ class TestCommand extends Command
|
||||
protected function paratestEnvironmentVariables()
|
||||
{
|
||||
return [
|
||||
'LARAVEL_PARALLEL_TESTING' => 1,
|
||||
'LARAVEL_PARALLEL_TESTING' => 1,
|
||||
'LARAVEL_PARALLEL_TESTING_RECREATE_DATABASES' => $this->option('recreate-databases'),
|
||||
'LARAVEL_PARALLEL_TESTING_DROP_DATABASES' => $this->option('drop-databases'),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -208,7 +292,7 @@ class TestCommand extends Command
|
||||
*/
|
||||
protected function clearEnv()
|
||||
{
|
||||
if (!$this->option('env')) {
|
||||
if (! $this->option('env')) {
|
||||
$vars = self::getEnvironmentVariables(
|
||||
// @phpstan-ignore-next-line
|
||||
$this->laravel->environmentPath(),
|
||||
@@ -225,9 +309,8 @@ class TestCommand extends Command
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @param string $file
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $file
|
||||
* @return array
|
||||
*/
|
||||
protected static function getEnvironmentVariables($path, $file)
|
||||
@@ -268,7 +351,7 @@ class TestCommand extends Command
|
||||
*/
|
||||
protected function installParallelDependencies()
|
||||
{
|
||||
$command = $this->findComposer() . ' require brianium/paratest --dev';
|
||||
$command = $this->findComposer().' require brianium/paratest --dev';
|
||||
|
||||
$process = Process::fromShellCommandline($command, null, null, null, null);
|
||||
|
||||
@@ -276,7 +359,7 @@ class TestCommand extends Command
|
||||
try {
|
||||
$process->setTty(true);
|
||||
} catch (RuntimeException $e) {
|
||||
$this->output->writeln('Warning: ' . $e->getMessage());
|
||||
$this->output->writeln('Warning: '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -298,10 +381,10 @@ class TestCommand extends Command
|
||||
*/
|
||||
protected function findComposer()
|
||||
{
|
||||
$composerPath = getcwd() . '/composer.phar';
|
||||
$composerPath = getcwd().'/composer.phar';
|
||||
|
||||
if (file_exists($composerPath)) {
|
||||
return '"' . PHP_BINARY . '" ' . $composerPath;
|
||||
return '"'.PHP_BINARY.'" '.$composerPath;
|
||||
}
|
||||
|
||||
return 'composer';
|
||||
|
@@ -34,7 +34,7 @@ final class ExceptionHandler implements ExceptionHandlerContract
|
||||
*/
|
||||
public function __construct(Container $container, ExceptionHandlerContract $appExceptionHandler)
|
||||
{
|
||||
$this->container = $container;
|
||||
$this->container = $container;
|
||||
$this->appExceptionHandler = $appExceptionHandler;
|
||||
}
|
||||
|
||||
@@ -62,8 +62,10 @@ final class ExceptionHandler implements ExceptionHandlerContract
|
||||
if ($e instanceof SymfonyConsoleExceptionInterface) {
|
||||
$this->appExceptionHandler->renderForConsole($output, $e);
|
||||
} else {
|
||||
$handler = $this->container->make(ProviderContract::class)
|
||||
->register()
|
||||
/** @var \NunoMaduro\Collision\Contracts\Provider $provider */
|
||||
$provider = $this->container->make(ProviderContract::class);
|
||||
|
||||
$handler = $provider->register()
|
||||
->getHandler()
|
||||
->setOutput($output);
|
||||
|
||||
|
@@ -4,8 +4,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace NunoMaduro\Collision\Adapters\Laravel;
|
||||
|
||||
use Facade\IgnitionContracts\SolutionProviderRepository;
|
||||
use NunoMaduro\Collision\Contracts\SolutionsRepository;
|
||||
use Spatie\Ignition\Contracts\SolutionProviderRepository;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
@@ -16,7 +16,7 @@ final class IgnitionSolutionsRepository implements SolutionsRepository
|
||||
/**
|
||||
* Holds an instance of ignition solutions provider repository.
|
||||
*
|
||||
* @var \Facade\IgnitionContracts\SolutionProviderRepository
|
||||
* @var \Spatie\Ignition\Contracts\SolutionProviderRepository
|
||||
*/
|
||||
protected $solutionProviderRepository;
|
||||
|
||||
|
@@ -25,15 +25,15 @@ final class ConfigureIO
|
||||
{
|
||||
/**
|
||||
* Configures both given input and output with
|
||||
* options from the enviroment.
|
||||
* options from the environment.
|
||||
*
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
public static function of(InputInterface $input, Output $output): void
|
||||
{
|
||||
$application = new Application();
|
||||
$reflector = new ReflectionObject($application);
|
||||
$method = $reflector->getMethod('configureIO');
|
||||
$reflector = new ReflectionObject($application);
|
||||
$method = $reflector->getMethod('configureIO');
|
||||
$method->setAccessible(true);
|
||||
$method->invoke($application, $input, $output);
|
||||
}
|
||||
|
@@ -54,7 +54,7 @@ final class Printer implements \PHPUnit\TextUI\ResultPrinter
|
||||
/**
|
||||
* Creates a new instance of the listener.
|
||||
*
|
||||
* @param ConsoleOutput $output
|
||||
* @param ConsoleOutput $output
|
||||
*
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
@@ -69,7 +69,8 @@ final class Printer implements \PHPUnit\TextUI\ResultPrinter
|
||||
ConfigureIO::of(new ArgvInput(), $output);
|
||||
|
||||
$this->style = new Style($output);
|
||||
$dummyTest = new class() extends TestCase {
|
||||
$dummyTest = new class() extends TestCase
|
||||
{
|
||||
};
|
||||
|
||||
$this->state = State::from($dummyTest);
|
||||
@@ -109,7 +110,7 @@ final class Printer implements \PHPUnit\TextUI\ResultPrinter
|
||||
$reflector = new ReflectionObject($error);
|
||||
|
||||
if ($reflector->hasProperty('message')) {
|
||||
$message = trim((string) preg_replace("/\r|\n/", "\n ", $error->getMessage()));
|
||||
$message = trim((string) preg_replace("/\r|\n/", "\n ", $error->getMessage()));
|
||||
$property = $reflector->getProperty('message');
|
||||
$property->setAccessible(true);
|
||||
$property->setValue($error, $message);
|
||||
@@ -188,14 +189,14 @@ final class Printer implements \PHPUnit\TextUI\ResultPrinter
|
||||
{
|
||||
$testCase = $this->testCaseFromTest($testCase);
|
||||
|
||||
if (!$this->state->existsInTestCase($testCase)) {
|
||||
if (! $this->state->existsInTestCase($testCase)) {
|
||||
$this->state->add(TestResult::fromTestCase($testCase, TestResult::PASS));
|
||||
}
|
||||
|
||||
if ($testCase instanceof TestCase
|
||||
&& $testCase->getTestResultObject() instanceof \PHPUnit\Framework\TestResult
|
||||
&& !$testCase->getTestResultObject()->isStrictAboutOutputDuringTests()
|
||||
&& !$testCase->hasExpectationOnOutput()) {
|
||||
&& ! $testCase->getTestResultObject()->isStrictAboutOutputDuringTests()
|
||||
&& ! $testCase->hasExpectationOnOutput()) {
|
||||
$this->style->write($testCase->getActualOutput());
|
||||
}
|
||||
}
|
||||
@@ -217,7 +218,7 @@ final class Printer implements \PHPUnit\TextUI\ResultPrinter
|
||||
*/
|
||||
private function testCaseFromTest(Test $test): TestCase
|
||||
{
|
||||
if (!$test instanceof TestCase) {
|
||||
if (! $test instanceof TestCase) {
|
||||
throw new ShouldNotHappen();
|
||||
}
|
||||
|
||||
|
@@ -75,7 +75,7 @@ final class State
|
||||
*/
|
||||
public function add(TestResult $test): void
|
||||
{
|
||||
$this->testCaseTests[] = $test;
|
||||
$this->testCaseTests[] = $test;
|
||||
$this->toBePrintedCaseTests[] = $test;
|
||||
|
||||
$this->suiteTests[] = $test;
|
||||
|
@@ -29,7 +29,7 @@ final class Style
|
||||
*/
|
||||
public function __construct(ConsoleOutputInterface $output)
|
||||
{
|
||||
if (!$output instanceof ConsoleOutput) {
|
||||
if (! $output instanceof ConsoleOutput) {
|
||||
throw new ShouldNotHappen();
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ final class Style
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$state->headerPrinted) {
|
||||
if (! $state->headerPrinted) {
|
||||
$this->output->writeln($this->titleLineFrom(
|
||||
$state->getTestCaseTitle() === 'FAIL' ? 'white' : 'black',
|
||||
$state->getTestCaseTitleColor(),
|
||||
@@ -92,12 +92,12 @@ final class Style
|
||||
return $testResult->type === TestResult::FAIL;
|
||||
});
|
||||
|
||||
if (!$onFailure) {
|
||||
if (! $onFailure) {
|
||||
$this->output->writeln(['', " \e[2m---\e[22m", '']);
|
||||
}
|
||||
|
||||
array_map(function (TestResult $testResult) use ($onFailure) {
|
||||
if (!$onFailure) {
|
||||
if (! $onFailure) {
|
||||
$this->output->write(sprintf(
|
||||
' <fg=red;options=bold>• %s </>> <fg=red;options=bold>%s</>',
|
||||
$testResult->testCaseName,
|
||||
@@ -105,7 +105,7 @@ final class Style
|
||||
));
|
||||
}
|
||||
|
||||
if (!$testResult->throwable instanceof Throwable) {
|
||||
if (! $testResult->throwable instanceof Throwable) {
|
||||
throw new ShouldNotHappen();
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ final class Style
|
||||
$types = [TestResult::FAIL, TestResult::WARN, TestResult::RISKY, TestResult::INCOMPLETE, TestResult::SKIPPED, TestResult::PASS];
|
||||
foreach ($types as $type) {
|
||||
if (($countTests = $state->countTestsInTestSuiteBy($type)) !== 0) {
|
||||
$color = TestResult::makeColor($type);
|
||||
$color = TestResult::makeColor($type);
|
||||
$tests[] = "<fg=$color;options=bold>$countTests $type</>";
|
||||
}
|
||||
}
|
||||
@@ -131,7 +131,7 @@ final class Style
|
||||
$tests[] = "\e[2m$pending pending\e[22m";
|
||||
}
|
||||
|
||||
if (!empty($tests)) {
|
||||
if (! empty($tests)) {
|
||||
$this->output->write([
|
||||
"\n",
|
||||
sprintf(
|
||||
@@ -144,12 +144,12 @@ final class Style
|
||||
if ($timer !== null) {
|
||||
$timeElapsed = number_format($timer->result(), 2, '.', '');
|
||||
$this->output->writeln([
|
||||
'',
|
||||
sprintf(
|
||||
' <fg=white;options=bold>Time: </><fg=default>%ss</>',
|
||||
$timeElapsed
|
||||
),
|
||||
]
|
||||
'',
|
||||
sprintf(
|
||||
' <fg=white;options=bold>Time: </><fg=default>%ss</>',
|
||||
$timeElapsed
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -178,8 +178,11 @@ final class Style
|
||||
}
|
||||
|
||||
$writer->ignoreFilesIn([
|
||||
'/vendor\/bin\/pest/',
|
||||
'/bin\/pest/',
|
||||
'/vendor\/pestphp\/pest/',
|
||||
'/vendor\/phpspec\/prophecy-phpunit/',
|
||||
'/vendor\/phpspec\/prophecy/',
|
||||
'/vendor\/phpunit\/phpunit\/src/',
|
||||
'/vendor\/mockery\/mockery/',
|
||||
'/vendor\/laravel\/dusk/',
|
||||
@@ -196,6 +199,7 @@ final class Style
|
||||
'/bin\/phpunit/',
|
||||
'/vendor\/coduo\/php-matcher\/src\/PHPUnit/',
|
||||
'/vendor\/sulu\/sulu\/src\/Sulu\/Bundle\/TestBundle\/Testing/',
|
||||
'/vendor\/webmozart\/assert/',
|
||||
]);
|
||||
|
||||
if ($throwable instanceof ExceptionWrapper && $throwable->getOriginalException() !== null) {
|
||||
@@ -207,20 +211,20 @@ final class Style
|
||||
$writer->write($inspector);
|
||||
|
||||
if ($throwable instanceof ExpectationFailedException && $comparisionFailure = $throwable->getComparisonFailure()) {
|
||||
$diff = $comparisionFailure->getDiff();
|
||||
$diff = $comparisionFailure->getDiff();
|
||||
$lines = explode(PHP_EOL, $diff);
|
||||
$diff = '';
|
||||
$diff = '';
|
||||
foreach ($lines as $line) {
|
||||
if (0 === strpos($line, '-')) {
|
||||
$line = '<fg=red>' . $line . '</>';
|
||||
$line = '<fg=red>'.$line.'</>';
|
||||
} elseif (0 === strpos($line, '+')) {
|
||||
$line = '<fg=green>' . $line . '</>';
|
||||
$line = '<fg=green>'.$line.'</>';
|
||||
}
|
||||
|
||||
$diff .= $line . PHP_EOL;
|
||||
$diff .= $line.PHP_EOL;
|
||||
}
|
||||
|
||||
$diff = trim((string) preg_replace("/\r|\n/", "\n ", $diff));
|
||||
$diff = trim((string) preg_replace("/\r|\n/", "\n ", $diff));
|
||||
|
||||
$this->output->write(" $diff");
|
||||
}
|
||||
@@ -247,7 +251,7 @@ final class Style
|
||||
*/
|
||||
private function testLineFrom(string $fg, string $icon, string $description, string $warning = null): string
|
||||
{
|
||||
if (!empty($warning)) {
|
||||
if (! empty($warning)) {
|
||||
$warning = sprintf(
|
||||
' → %s',
|
||||
$warning
|
||||
|
@@ -13,13 +13,19 @@ use Throwable;
|
||||
*/
|
||||
final class TestResult
|
||||
{
|
||||
public const FAIL = 'failed';
|
||||
public const SKIPPED = 'skipped';
|
||||
public const INCOMPLETE = 'incompleted';
|
||||
public const RISKY = 'risked';
|
||||
public const WARN = 'warnings';
|
||||
public const RUNS = 'pending';
|
||||
public const PASS = 'passed';
|
||||
public const FAIL = 'failed';
|
||||
|
||||
public const SKIPPED = 'skipped';
|
||||
|
||||
public const INCOMPLETE = 'incomplete';
|
||||
|
||||
public const RISKY = 'risky';
|
||||
|
||||
public const WARN = 'warnings';
|
||||
|
||||
public const RUNS = 'pending';
|
||||
|
||||
public const PASS = 'passed';
|
||||
|
||||
/**
|
||||
* @readonly
|
||||
@@ -76,11 +82,11 @@ final class TestResult
|
||||
private function __construct(string $testCaseName, string $description, string $type, string $icon, string $color, Throwable $throwable = null)
|
||||
{
|
||||
$this->testCaseName = $testCaseName;
|
||||
$this->description = $description;
|
||||
$this->type = $type;
|
||||
$this->icon = $icon;
|
||||
$this->color = $color;
|
||||
$this->throwable = $throwable;
|
||||
$this->description = $description;
|
||||
$this->type = $type;
|
||||
$this->icon = $icon;
|
||||
$this->color = $color;
|
||||
$this->throwable = $throwable;
|
||||
|
||||
$asWarning = $this->type === TestResult::WARN
|
||||
|| $this->type === TestResult::RISKY
|
||||
@@ -88,7 +94,7 @@ final class TestResult
|
||||
|| $this->type === TestResult::INCOMPLETE;
|
||||
|
||||
if ($throwable instanceof Throwable && $asWarning) {
|
||||
$this->warning = trim((string) preg_replace("/\r|\n/", ' ', $throwable->getMessage()));
|
||||
$this->warning = trim((string) preg_replace("/\r|\n/", ' ', $throwable->getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -25,16 +25,16 @@ final class ArgumentFormatter implements ArgumentFormatterContract
|
||||
foreach ($arguments as $argument) {
|
||||
switch (true) {
|
||||
case is_string($argument):
|
||||
$result[] = '"' . (mb_strlen($argument) > self::MAX_STRING_LENGTH ? mb_substr($argument, 0, self::MAX_STRING_LENGTH) . '...' : $argument) . '"';
|
||||
$result[] = '"'.(mb_strlen($argument) > self::MAX_STRING_LENGTH ? mb_substr($argument, 0, self::MAX_STRING_LENGTH).'...' : $argument).'"';
|
||||
break;
|
||||
case is_array($argument):
|
||||
$associative = array_keys($argument) !== range(0, count($argument) - 1);
|
||||
if ($recursive && $associative && count($argument) <= 5) {
|
||||
$result[] = '[' . $this->format($argument, false) . ']';
|
||||
$result[] = '['.$this->format($argument, false).']';
|
||||
}
|
||||
break;
|
||||
case is_object($argument):
|
||||
$class = get_class($argument);
|
||||
$class = get_class($argument);
|
||||
$result[] = "Object($class)";
|
||||
break;
|
||||
}
|
||||
|
115
vendor/nunomaduro/collision/src/ConsoleColor.php
vendored
115
vendor/nunomaduro/collision/src/ConsoleColor.php
vendored
@@ -13,6 +13,7 @@ use NunoMaduro\Collision\Exceptions\ShouldNotHappen;
|
||||
final class ConsoleColor
|
||||
{
|
||||
public const FOREGROUND = 38;
|
||||
|
||||
public const BACKGROUND = 48;
|
||||
|
||||
public const COLOR256_REGEXP = '~^(bg_)?color_(\d{1,3})$~';
|
||||
@@ -27,52 +28,52 @@ final class ConsoleColor
|
||||
|
||||
/** @var array */
|
||||
private const STYLES = [
|
||||
'none' => null,
|
||||
'bold' => '1',
|
||||
'dark' => '2',
|
||||
'italic' => '3',
|
||||
'none' => null,
|
||||
'bold' => '1',
|
||||
'dark' => '2',
|
||||
'italic' => '3',
|
||||
'underline' => '4',
|
||||
'blink' => '5',
|
||||
'reverse' => '7',
|
||||
'blink' => '5',
|
||||
'reverse' => '7',
|
||||
'concealed' => '8',
|
||||
|
||||
'default' => '39',
|
||||
'black' => '30',
|
||||
'red' => '31',
|
||||
'green' => '32',
|
||||
'yellow' => '33',
|
||||
'blue' => '34',
|
||||
'magenta' => '35',
|
||||
'cyan' => '36',
|
||||
'default' => '39',
|
||||
'black' => '30',
|
||||
'red' => '31',
|
||||
'green' => '32',
|
||||
'yellow' => '33',
|
||||
'blue' => '34',
|
||||
'magenta' => '35',
|
||||
'cyan' => '36',
|
||||
'light_gray' => '37',
|
||||
|
||||
'dark_gray' => '90',
|
||||
'light_red' => '91',
|
||||
'light_green' => '92',
|
||||
'light_yellow' => '93',
|
||||
'light_blue' => '94',
|
||||
'dark_gray' => '90',
|
||||
'light_red' => '91',
|
||||
'light_green' => '92',
|
||||
'light_yellow' => '93',
|
||||
'light_blue' => '94',
|
||||
'light_magenta' => '95',
|
||||
'light_cyan' => '96',
|
||||
'white' => '97',
|
||||
'light_cyan' => '96',
|
||||
'white' => '97',
|
||||
|
||||
'bg_default' => '49',
|
||||
'bg_black' => '40',
|
||||
'bg_red' => '41',
|
||||
'bg_green' => '42',
|
||||
'bg_yellow' => '43',
|
||||
'bg_blue' => '44',
|
||||
'bg_magenta' => '45',
|
||||
'bg_cyan' => '46',
|
||||
'bg_default' => '49',
|
||||
'bg_black' => '40',
|
||||
'bg_red' => '41',
|
||||
'bg_green' => '42',
|
||||
'bg_yellow' => '43',
|
||||
'bg_blue' => '44',
|
||||
'bg_magenta' => '45',
|
||||
'bg_cyan' => '46',
|
||||
'bg_light_gray' => '47',
|
||||
|
||||
'bg_dark_gray' => '100',
|
||||
'bg_light_red' => '101',
|
||||
'bg_light_green' => '102',
|
||||
'bg_light_yellow' => '103',
|
||||
'bg_light_blue' => '104',
|
||||
'bg_dark_gray' => '100',
|
||||
'bg_light_red' => '101',
|
||||
'bg_light_green' => '102',
|
||||
'bg_light_yellow' => '103',
|
||||
'bg_light_blue' => '104',
|
||||
'bg_light_magenta' => '105',
|
||||
'bg_light_cyan' => '106',
|
||||
'bg_white' => '107',
|
||||
'bg_light_cyan' => '106',
|
||||
'bg_white' => '107',
|
||||
];
|
||||
|
||||
/** @var array */
|
||||
@@ -84,9 +85,8 @@ final class ConsoleColor
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|array $style
|
||||
* @param string $text
|
||||
*
|
||||
* @param string|array $style
|
||||
* @param string $text
|
||||
* @return string
|
||||
*
|
||||
* @throws InvalidStyleException
|
||||
@@ -94,14 +94,14 @@ final class ConsoleColor
|
||||
*/
|
||||
public function apply($style, $text)
|
||||
{
|
||||
if (!$this->isStyleForced() && !$this->isSupported()) {
|
||||
if (! $this->isStyleForced() && ! $this->isSupported()) {
|
||||
return $text;
|
||||
}
|
||||
|
||||
if (is_string($style)) {
|
||||
$style = [$style];
|
||||
}
|
||||
if (!is_array($style)) {
|
||||
if (! is_array($style)) {
|
||||
throw new \InvalidArgumentException('Style must be string or array.');
|
||||
}
|
||||
|
||||
@@ -125,11 +125,11 @@ final class ConsoleColor
|
||||
return $text;
|
||||
}
|
||||
|
||||
return $this->escSequence(implode(';', $sequences)) . $text . $this->escSequence(self::RESET_STYLE);
|
||||
return $this->escSequence(implode(';', $sequences)).$text.$this->escSequence(self::RESET_STYLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $forceStyle
|
||||
* @param bool $forceStyle
|
||||
*/
|
||||
public function setForceStyle($forceStyle)
|
||||
{
|
||||
@@ -153,20 +153,20 @@ final class ConsoleColor
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array|string $styles
|
||||
* @param string $name
|
||||
* @param array|string $styles
|
||||
*/
|
||||
public function addTheme($name, $styles)
|
||||
{
|
||||
if (is_string($styles)) {
|
||||
$styles = [$styles];
|
||||
}
|
||||
if (!is_array($styles)) {
|
||||
if (! is_array($styles)) {
|
||||
throw new \InvalidArgumentException('Style must be string or array.');
|
||||
}
|
||||
|
||||
foreach ($styles as $style) {
|
||||
if (!$this->isValidStyle($style)) {
|
||||
if (! $this->isValidStyle($style)) {
|
||||
throw new InvalidStyleException($style);
|
||||
}
|
||||
}
|
||||
@@ -183,8 +183,7 @@ final class ConsoleColor
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @param string $name
|
||||
* @return bool
|
||||
*/
|
||||
public function hasTheme($name)
|
||||
@@ -193,7 +192,7 @@ final class ConsoleColor
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param string $name
|
||||
*/
|
||||
public function removeTheme($name)
|
||||
{
|
||||
@@ -238,8 +237,7 @@ final class ConsoleColor
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @param string $name
|
||||
* @return string[]
|
||||
*/
|
||||
private function themeSequence($name)
|
||||
@@ -253,8 +251,7 @@ final class ConsoleColor
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $style
|
||||
*
|
||||
* @param string $style
|
||||
* @return string
|
||||
*/
|
||||
private function styleSequence($style)
|
||||
@@ -263,21 +260,20 @@ final class ConsoleColor
|
||||
return self::STYLES[$style];
|
||||
}
|
||||
|
||||
if (!$this->are256ColorsSupported()) {
|
||||
if (! $this->are256ColorsSupported()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
preg_match(self::COLOR256_REGEXP, $style, $matches);
|
||||
|
||||
$type = $matches[1] === 'bg_' ? self::BACKGROUND : self::FOREGROUND;
|
||||
$type = $matches[1] === 'bg_' ? self::BACKGROUND : self::FOREGROUND;
|
||||
$value = $matches[2];
|
||||
|
||||
return "$type;5;$value";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $style
|
||||
*
|
||||
* @param string $style
|
||||
* @return bool
|
||||
*/
|
||||
private function isValidStyle($style)
|
||||
@@ -286,8 +282,7 @@ final class ConsoleColor
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|int $value
|
||||
*
|
||||
* @param string|int $value
|
||||
* @return string
|
||||
*/
|
||||
private function escSequence($value)
|
||||
|
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace NunoMaduro\Collision\Contracts;
|
||||
|
||||
use Facade\IgnitionContracts\Solution;
|
||||
use Spatie\Ignition\Contracts\Solution;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
|
@@ -25,8 +25,7 @@ interface Writer
|
||||
* Ignores traces where the file string matches one
|
||||
* of the provided regex expressions.
|
||||
*
|
||||
* @param string[] $ignore the regex expressions
|
||||
*
|
||||
* @param string[] $ignore the regex expressions
|
||||
* @return \NunoMaduro\Collision\Contracts\Writer
|
||||
*/
|
||||
public function ignoreFilesIn(array $ignore): Writer;
|
||||
|
201
vendor/nunomaduro/collision/src/Coverage.php
vendored
Normal file
201
vendor/nunomaduro/collision/src/Coverage.php
vendored
Normal file
@@ -0,0 +1,201 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace NunoMaduro\Collision;
|
||||
|
||||
use SebastianBergmann\CodeCoverage\CodeCoverage;
|
||||
use SebastianBergmann\CodeCoverage\Node\Directory;
|
||||
use SebastianBergmann\CodeCoverage\Node\File;
|
||||
use SebastianBergmann\Environment\Runtime;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Terminal;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class Coverage
|
||||
{
|
||||
/**
|
||||
* Returns the coverage path.
|
||||
*/
|
||||
public static function getPath(): string
|
||||
{
|
||||
return implode(DIRECTORY_SEPARATOR, [
|
||||
dirname(__DIR__),
|
||||
'.temp',
|
||||
'coverage',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs true there is any code coverage driver available.
|
||||
*/
|
||||
public static function isAvailable(): bool
|
||||
{
|
||||
if (! (new Runtime())->canCollectCodeCoverage()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (static::usingXdebug()) {
|
||||
$mode = getenv('XDEBUG_MODE') ?: ini_get('xdebug.mode');
|
||||
|
||||
return $mode && in_array('coverage', explode(',', $mode), true);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the user is using Xdebug.
|
||||
*/
|
||||
public static function usingXdebug(): bool
|
||||
{
|
||||
return (new Runtime())->hasXdebug();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports the code coverage report to the
|
||||
* console and returns the result in float.
|
||||
*/
|
||||
public static function report(OutputInterface $output): float
|
||||
{
|
||||
if (! file_exists($reportPath = self::getPath())) {
|
||||
if (self::usingXdebug()) {
|
||||
$output->writeln(
|
||||
" <fg=black;bg=yellow;options=bold> WARN </> Unable to get coverage using Xdebug. Did you set <href=https://xdebug.org/docs/code_coverage#mode>Xdebug's coverage mode</>?</>",
|
||||
);
|
||||
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
$output->writeln(
|
||||
' <fg=black;bg=yellow;options=bold> WARN </> No coverage driver detected.</>',
|
||||
);
|
||||
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
/** @var CodeCoverage $codeCoverage */
|
||||
$codeCoverage = require $reportPath;
|
||||
unlink($reportPath);
|
||||
|
||||
$totalCoverage = $codeCoverage->getReport()->percentageOfExecutedLines();
|
||||
|
||||
$totalWidth = (new Terminal())->getWidth();
|
||||
|
||||
$dottedLineLength = $totalWidth;
|
||||
|
||||
/** @var Directory<File|Directory> $report */
|
||||
$report = $codeCoverage->getReport();
|
||||
|
||||
foreach ($report->getIterator() as $file) {
|
||||
if (! $file instanceof File) {
|
||||
continue;
|
||||
}
|
||||
$dirname = dirname($file->id());
|
||||
$basename = basename($file->id(), '.php');
|
||||
|
||||
$name = $dirname === '.' ? $basename : implode(DIRECTORY_SEPARATOR, [
|
||||
$dirname,
|
||||
$basename,
|
||||
]);
|
||||
$rawName = $dirname === '.' ? $basename : implode(DIRECTORY_SEPARATOR, [
|
||||
$dirname,
|
||||
$basename,
|
||||
]);
|
||||
|
||||
$linesExecutedTakenSize = 0;
|
||||
|
||||
if ($file->percentageOfExecutedLines()->asString() != '0.00%') {
|
||||
$linesExecutedTakenSize = strlen($uncoveredLines = trim(implode(', ', self::getMissingCoverage($file)))) + 1;
|
||||
$name .= sprintf(' <fg=red>%s</>', $uncoveredLines);
|
||||
}
|
||||
|
||||
$percentage = $file->numberOfExecutableLines() === 0
|
||||
? '100.0'
|
||||
: number_format($file->percentageOfExecutedLines()->asFloat(), 1, '.', '');
|
||||
|
||||
$takenSize = strlen($rawName.$percentage) + 8 + $linesExecutedTakenSize; // adding 3 space and percent sign
|
||||
|
||||
$percentage = sprintf(
|
||||
'<fg=%s%s>%s</>',
|
||||
$percentage === '100.0' ? 'green' : ($percentage === '0.0' ? 'red' : 'yellow'),
|
||||
$percentage === '100.0' ? ';options=bold' : '',
|
||||
$percentage
|
||||
);
|
||||
|
||||
$output->writeln(sprintf(
|
||||
' <fg=white>%s</> <fg=#6C7280>%s</> %s <fg=#6C7280>%%</>',
|
||||
$name,
|
||||
str_repeat('.', max($dottedLineLength - $takenSize, 1)),
|
||||
$percentage
|
||||
));
|
||||
}
|
||||
|
||||
$output->writeln('');
|
||||
|
||||
$rawName = 'Total Coverage';
|
||||
|
||||
$takenSize = strlen($rawName.$totalCoverage->asString()) + 6;
|
||||
|
||||
$output->writeln(sprintf(
|
||||
' <fg=white;options=bold>%s</> <fg=#6C7280>%s</> %s <fg=#6C7280>%%</>',
|
||||
$rawName,
|
||||
str_repeat('.', max($dottedLineLength - $takenSize, 1)),
|
||||
number_format($totalCoverage->asFloat(), 1, '.', '')
|
||||
));
|
||||
|
||||
return $totalCoverage->asFloat();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an array of missing coverage on the following format:.
|
||||
*
|
||||
* ```
|
||||
* ['11', '20..25', '50', '60..80'];
|
||||
* ```
|
||||
*
|
||||
* @param File $file
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public static function getMissingCoverage($file): array
|
||||
{
|
||||
$shouldBeNewLine = true;
|
||||
|
||||
$eachLine = function (array $array, array $tests, int $line) use (&$shouldBeNewLine): array {
|
||||
if (count($tests) > 0) {
|
||||
$shouldBeNewLine = true;
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
if ($shouldBeNewLine) {
|
||||
$array[] = (string) $line;
|
||||
$shouldBeNewLine = false;
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
$lastKey = count($array) - 1;
|
||||
|
||||
if (array_key_exists($lastKey, $array) && str_contains($array[$lastKey], '..')) {
|
||||
[$from] = explode('..', $array[$lastKey]);
|
||||
$array[$lastKey] = $line > $from ? sprintf('%s..%s', $from, $line) : sprintf('%s..%s', $line, $from);
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
$array[$lastKey] = sprintf('%s..%s', $array[$lastKey], $line);
|
||||
|
||||
return $array;
|
||||
};
|
||||
|
||||
$array = [];
|
||||
foreach (array_filter($file->lineCoverageData(), 'is_array') as $line => $tests) {
|
||||
$array = $eachLine($array, $tests, $line);
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
}
|
111
vendor/nunomaduro/collision/src/Highlighter.php
vendored
111
vendor/nunomaduro/collision/src/Highlighter.php
vendored
@@ -11,58 +11,75 @@ use NunoMaduro\Collision\Contracts\Highlighter as HighlighterContract;
|
||||
*/
|
||||
final class Highlighter implements HighlighterContract
|
||||
{
|
||||
public const TOKEN_DEFAULT = 'token_default';
|
||||
public const TOKEN_COMMENT = 'token_comment';
|
||||
public const TOKEN_STRING = 'token_string';
|
||||
public const TOKEN_HTML = 'token_html';
|
||||
public const TOKEN_KEYWORD = 'token_keyword';
|
||||
public const ACTUAL_LINE_MARK = 'actual_line_mark';
|
||||
public const LINE_NUMBER = 'line_number';
|
||||
public const TOKEN_DEFAULT = 'token_default';
|
||||
|
||||
public const TOKEN_COMMENT = 'token_comment';
|
||||
|
||||
public const TOKEN_STRING = 'token_string';
|
||||
|
||||
public const TOKEN_HTML = 'token_html';
|
||||
|
||||
public const TOKEN_KEYWORD = 'token_keyword';
|
||||
|
||||
public const ACTUAL_LINE_MARK = 'actual_line_mark';
|
||||
|
||||
public const LINE_NUMBER = 'line_number';
|
||||
|
||||
private const ARROW_SYMBOL = '>';
|
||||
|
||||
private const DELIMITER = '|';
|
||||
|
||||
private const ARROW_SYMBOL_UTF8 = '➜';
|
||||
|
||||
private const DELIMITER_UTF8 = '▕'; // '▶';
|
||||
|
||||
private const ARROW_SYMBOL = '>';
|
||||
private const DELIMITER = '|';
|
||||
private const ARROW_SYMBOL_UTF8 = '➜';
|
||||
private const DELIMITER_UTF8 = '▕'; // '▶';
|
||||
private const LINE_NUMBER_DIVIDER = 'line_divider';
|
||||
private const MARKED_LINE_NUMBER = 'marked_line';
|
||||
private const WIDTH = 3;
|
||||
|
||||
private const MARKED_LINE_NUMBER = 'marked_line';
|
||||
|
||||
private const WIDTH = 3;
|
||||
|
||||
/**
|
||||
* Holds the theme.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private const THEME = [
|
||||
self::TOKEN_STRING => ['light_gray'],
|
||||
self::TOKEN_STRING => ['light_gray'],
|
||||
self::TOKEN_COMMENT => ['dark_gray', 'italic'],
|
||||
self::TOKEN_KEYWORD => ['magenta', 'bold'],
|
||||
self::TOKEN_DEFAULT => ['default', 'bold'],
|
||||
self::TOKEN_HTML => ['blue', 'bold'],
|
||||
self::TOKEN_HTML => ['blue', 'bold'],
|
||||
|
||||
self::ACTUAL_LINE_MARK => ['red', 'bold'],
|
||||
self::LINE_NUMBER => ['dark_gray'],
|
||||
self::MARKED_LINE_NUMBER => ['italic', 'bold'],
|
||||
self::ACTUAL_LINE_MARK => ['red', 'bold'],
|
||||
self::LINE_NUMBER => ['dark_gray'],
|
||||
self::MARKED_LINE_NUMBER => ['italic', 'bold'],
|
||||
self::LINE_NUMBER_DIVIDER => ['dark_gray'],
|
||||
];
|
||||
|
||||
/** @var ConsoleColor */
|
||||
private $color;
|
||||
|
||||
/** @var array */
|
||||
private const DEFAULT_THEME = [
|
||||
self::TOKEN_STRING => 'red',
|
||||
self::TOKEN_STRING => 'red',
|
||||
self::TOKEN_COMMENT => 'yellow',
|
||||
self::TOKEN_KEYWORD => 'green',
|
||||
self::TOKEN_DEFAULT => 'default',
|
||||
self::TOKEN_HTML => 'cyan',
|
||||
self::TOKEN_HTML => 'cyan',
|
||||
|
||||
self::ACTUAL_LINE_MARK => 'dark_gray',
|
||||
self::LINE_NUMBER => 'dark_gray',
|
||||
self::MARKED_LINE_NUMBER => 'dark_gray',
|
||||
self::ACTUAL_LINE_MARK => 'dark_gray',
|
||||
self::LINE_NUMBER => 'dark_gray',
|
||||
self::MARKED_LINE_NUMBER => 'dark_gray',
|
||||
self::LINE_NUMBER_DIVIDER => 'dark_gray',
|
||||
];
|
||||
|
||||
/** @var string */
|
||||
private $delimiter = self::DELIMITER_UTF8;
|
||||
|
||||
/** @var string */
|
||||
private $arrow = self::ARROW_SYMBOL_UTF8;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
@@ -76,7 +93,7 @@ final class Highlighter implements HighlighterContract
|
||||
$this->color = $color ?: new ConsoleColor();
|
||||
|
||||
foreach (self::DEFAULT_THEME as $name => $styles) {
|
||||
if (!$this->color->hasTheme($name)) {
|
||||
if (! $this->color->hasTheme($name)) {
|
||||
$this->color->addTheme($name, $styles);
|
||||
}
|
||||
}
|
||||
@@ -84,9 +101,9 @@ final class Highlighter implements HighlighterContract
|
||||
foreach (self::THEME as $name => $styles) {
|
||||
$this->color->addTheme($name, $styles);
|
||||
}
|
||||
if (!$UTF8) {
|
||||
if (! $UTF8) {
|
||||
$this->delimiter = self::DELIMITER;
|
||||
$this->arrow = self::ARROW_SYMBOL;
|
||||
$this->arrow = self::ARROW_SYMBOL;
|
||||
}
|
||||
$this->delimiter .= ' ';
|
||||
}
|
||||
@@ -100,18 +117,18 @@ final class Highlighter implements HighlighterContract
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $source
|
||||
* @param int $lineNumber
|
||||
* @param int $linesBefore
|
||||
* @param int $linesAfter
|
||||
* @param string $source
|
||||
* @param int $lineNumber
|
||||
* @param int $linesBefore
|
||||
* @param int $linesAfter
|
||||
*/
|
||||
public function getCodeSnippet($source, $lineNumber, $linesBefore = 2, $linesAfter = 2): string
|
||||
{
|
||||
$tokenLines = $this->getHighlightedLines($source);
|
||||
|
||||
$offset = $lineNumber - $linesBefore - 1;
|
||||
$offset = max($offset, 0);
|
||||
$length = $linesAfter + $linesBefore + 1;
|
||||
$offset = $lineNumber - $linesBefore - 1;
|
||||
$offset = max($offset, 0);
|
||||
$length = $linesAfter + $linesBefore + 1;
|
||||
$tokenLines = array_slice($tokenLines, $offset, $length, $preserveKeys = true);
|
||||
|
||||
$lines = $this->colorLines($tokenLines);
|
||||
@@ -120,7 +137,7 @@ final class Highlighter implements HighlighterContract
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $source
|
||||
* @param string $source
|
||||
*/
|
||||
private function getHighlightedLines($source): array
|
||||
{
|
||||
@@ -131,15 +148,15 @@ final class Highlighter implements HighlighterContract
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $source
|
||||
* @param string $source
|
||||
*/
|
||||
private function tokenize($source): array
|
||||
{
|
||||
$tokens = token_get_all($source);
|
||||
|
||||
$output = [];
|
||||
$output = [];
|
||||
$currentType = null;
|
||||
$buffer = '';
|
||||
$buffer = '';
|
||||
|
||||
foreach ($tokens as $token) {
|
||||
if (is_array($token)) {
|
||||
@@ -192,8 +209,8 @@ final class Highlighter implements HighlighterContract
|
||||
}
|
||||
|
||||
if ($currentType !== $newType) {
|
||||
$output[] = [$currentType, $buffer];
|
||||
$buffer = '';
|
||||
$output[] = [$currentType, $buffer];
|
||||
$buffer = '';
|
||||
$currentType = $newType;
|
||||
}
|
||||
|
||||
@@ -216,7 +233,7 @@ final class Highlighter implements HighlighterContract
|
||||
foreach (explode("\n", $token[1]) as $count => $tokenLine) {
|
||||
if ($count > 0) {
|
||||
$lines[] = $line;
|
||||
$line = [];
|
||||
$line = [];
|
||||
}
|
||||
|
||||
if ($tokenLine === '') {
|
||||
@@ -252,14 +269,14 @@ final class Highlighter implements HighlighterContract
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|null $markLine
|
||||
* @param int|null $markLine
|
||||
*/
|
||||
private function lineNumbers(array $lines, $markLine = null): string
|
||||
{
|
||||
$lineStrlen = strlen((string) (array_key_last($lines) + 1));
|
||||
$lineStrlen = $lineStrlen < self::WIDTH ? self::WIDTH : $lineStrlen;
|
||||
$snippet = '';
|
||||
$mark = ' ' . $this->arrow . ' ';
|
||||
$snippet = '';
|
||||
$mark = ' '.$this->arrow.' ';
|
||||
foreach ($lines as $i => $line) {
|
||||
$coloredLineNumber = $this->coloredLineNumber(self::LINE_NUMBER, $i, $lineStrlen);
|
||||
|
||||
@@ -281,16 +298,16 @@ final class Highlighter implements HighlighterContract
|
||||
$snippet .=
|
||||
$this->color->apply(self::LINE_NUMBER_DIVIDER, $this->delimiter);
|
||||
|
||||
$snippet .= $line . PHP_EOL;
|
||||
$snippet .= $line.PHP_EOL;
|
||||
}
|
||||
|
||||
return $snippet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $style
|
||||
* @param int $i
|
||||
* @param int $lineStrlen
|
||||
* @param string $style
|
||||
* @param int $i
|
||||
* @param int $lineStrlen
|
||||
*/
|
||||
private function coloredLineNumber($style, $i, $lineStrlen): string
|
||||
{
|
||||
|
2
vendor/nunomaduro/collision/src/Provider.php
vendored
2
vendor/nunomaduro/collision/src/Provider.php
vendored
@@ -35,7 +35,7 @@ final class Provider implements ProviderContract
|
||||
*/
|
||||
public function __construct(RunInterface $run = null, HandlerContract $handler = null)
|
||||
{
|
||||
$this->run = $run ?: new Run();
|
||||
$this->run = $run ?: new Run();
|
||||
$this->handler = $handler ?: new Handler();
|
||||
}
|
||||
|
||||
|
45
vendor/nunomaduro/collision/src/Writer.php
vendored
45
vendor/nunomaduro/collision/src/Writer.php
vendored
@@ -95,9 +95,9 @@ final class Writer implements WriterContract
|
||||
HighlighterContract $highlighter = null
|
||||
) {
|
||||
$this->solutionsRepository = $solutionsRepository ?: new NullSolutionsRepository();
|
||||
$this->output = $output ?: new ConsoleOutput();
|
||||
$this->argumentFormatter = $argumentFormatter ?: new ArgumentFormatter();
|
||||
$this->highlighter = $highlighter ?: new Highlighter();
|
||||
$this->output = $output ?: new ConsoleOutput();
|
||||
$this->argumentFormatter = $argumentFormatter ?: new ArgumentFormatter();
|
||||
$this->highlighter = $highlighter ?: new Highlighter();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,16 +115,16 @@ final class Writer implements WriterContract
|
||||
|
||||
if ($this->showEditor
|
||||
&& $editorFrame !== null
|
||||
&& !$exception instanceof RenderlessEditor
|
||||
&& ! $exception instanceof RenderlessEditor
|
||||
) {
|
||||
$this->renderEditor($editorFrame);
|
||||
}
|
||||
|
||||
$this->renderSolution($inspector);
|
||||
|
||||
if ($this->showTrace && !empty($frames) && !$exception instanceof RenderlessTrace) {
|
||||
if ($this->showTrace && ! empty($frames) && ! $exception instanceof RenderlessTrace) {
|
||||
$this->renderTrace($frames);
|
||||
} elseif (!$exception instanceof RenderlessEditor) {
|
||||
} elseif (! $exception instanceof RenderlessEditor) {
|
||||
$this->output->writeln('');
|
||||
}
|
||||
}
|
||||
@@ -222,8 +222,8 @@ final class Writer implements WriterContract
|
||||
protected function renderTitleAndDescription(Inspector $inspector): WriterContract
|
||||
{
|
||||
$exception = $inspector->getException();
|
||||
$message = rtrim($exception->getMessage());
|
||||
$class = $inspector->getExceptionName();
|
||||
$message = rtrim($exception->getMessage());
|
||||
$class = $inspector->getExceptionName();
|
||||
|
||||
if ($this->showTitle) {
|
||||
$this->render("<bg=red;options=bold> $class </>");
|
||||
@@ -244,19 +244,19 @@ final class Writer implements WriterContract
|
||||
$solutions = $this->solutionsRepository->getFromThrowable($throwable);
|
||||
|
||||
foreach ($solutions as $solution) {
|
||||
/** @var \Facade\IgnitionContracts\Solution $solution */
|
||||
$title = $solution->getSolutionTitle();
|
||||
/** @var \Spatie\Ignition\Contracts\Solution $solution */
|
||||
$title = $solution->getSolutionTitle();
|
||||
$description = $solution->getSolutionDescription();
|
||||
$links = $solution->getDocumentationLinks();
|
||||
$links = $solution->getDocumentationLinks();
|
||||
|
||||
$description = trim((string) preg_replace("/\n/", "\n ", $description));
|
||||
|
||||
$this->render(sprintf(
|
||||
'<fg=blue;options=bold>• </><fg=default;options=bold>%s</>: %s %s',
|
||||
'<fg=cyan;options=bold>i</> <fg=default;options=bold>%s</>: %s %s',
|
||||
rtrim($title, '.'),
|
||||
$description,
|
||||
implode(', ', array_map(function (string $link) {
|
||||
return sprintf("\n <fg=blue>%s</>", $link);
|
||||
return sprintf("\n <fg=gray>%s</>", $link);
|
||||
}, $links))
|
||||
));
|
||||
}
|
||||
@@ -275,7 +275,7 @@ final class Writer implements WriterContract
|
||||
|
||||
// getLine() might return null so cast to int to get 0 instead
|
||||
$line = (int) $frame->getLine();
|
||||
$this->render('at <fg=green>' . $file . '</>' . ':<fg=green>' . $line . '</>');
|
||||
$this->render('at <fg=green>'.$file.'</>'.':<fg=green>'.$line.'</>');
|
||||
|
||||
$content = $this->highlighter->highlight((string) $frame->getFileContents(), (int) $frame->getLine());
|
||||
|
||||
@@ -291,10 +291,11 @@ final class Writer implements WriterContract
|
||||
protected function renderTrace(array $frames): WriterContract
|
||||
{
|
||||
$vendorFrames = 0;
|
||||
$userFrames = 0;
|
||||
$userFrames = 0;
|
||||
foreach ($frames as $i => $frame) {
|
||||
if ($this->output->getVerbosity() < OutputInterface::VERBOSITY_VERBOSE && strpos($frame->getFile(), '/vendor/') !== false) {
|
||||
$vendorFrames++;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -304,12 +305,12 @@ final class Writer implements WriterContract
|
||||
|
||||
$userFrames++;
|
||||
|
||||
$file = $this->getFileRelativePath($frame->getFile());
|
||||
$line = $frame->getLine();
|
||||
$class = empty($frame->getClass()) ? '' : $frame->getClass() . '::';
|
||||
$file = $this->getFileRelativePath($frame->getFile());
|
||||
$line = $frame->getLine();
|
||||
$class = empty($frame->getClass()) ? '' : $frame->getClass().'::';
|
||||
$function = $frame->getFunction();
|
||||
$args = $this->argumentFormatter->format($frame->getArgs());
|
||||
$pos = str_pad((string) ((int) $i + 1), 4, ' ');
|
||||
$args = $this->argumentFormatter->format($frame->getArgs());
|
||||
$pos = str_pad((string) ((int) $i + 1), 4, ' ');
|
||||
|
||||
if ($vendorFrames > 0) {
|
||||
$this->output->write(
|
||||
@@ -319,7 +320,7 @@ final class Writer implements WriterContract
|
||||
}
|
||||
|
||||
$this->render("<fg=yellow>$pos</><fg=default;options=bold>$file</>:<fg=default;options=bold>$line</>");
|
||||
$this->render("<fg=white> $class$function($args)</>", false);
|
||||
$this->render("<fg=gray> $class$function($args)</>", false);
|
||||
}
|
||||
|
||||
return $this;
|
||||
@@ -348,7 +349,7 @@ final class Writer implements WriterContract
|
||||
{
|
||||
$cwd = (string) getcwd();
|
||||
|
||||
if (!empty($cwd)) {
|
||||
if (! empty($cwd)) {
|
||||
return str_replace("$cwd/", '', $filePath);
|
||||
}
|
||||
|
||||
|
21
vendor/nunomaduro/termwind/LICENSE.md
vendored
Executable file
21
vendor/nunomaduro/termwind/LICENSE.md
vendored
Executable file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) Nuno Maduro <enunomaduro@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.
|
69
vendor/nunomaduro/termwind/composer.json
vendored
Normal file
69
vendor/nunomaduro/termwind/composer.json
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
{
|
||||
"name": "nunomaduro/termwind",
|
||||
"description": "Its like Tailwind CSS, but for the console.",
|
||||
"keywords": ["php", "cli", "package", "console", "css", "style"],
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nuno Maduro",
|
||||
"email": "enunomaduro@gmail.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^8.0",
|
||||
"ext-mbstring": "*",
|
||||
"symfony/console": "^5.3.0|^6.0.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"ergebnis/phpstan-rules": "^1.0.",
|
||||
"illuminate/console": "^8.0|^9.0",
|
||||
"illuminate/support": "^8.0|^9.0",
|
||||
"laravel/pint": "^1.0.0",
|
||||
"pestphp/pest": "^1.21.0",
|
||||
"pestphp/pest-plugin-mock": "^1.0",
|
||||
"phpstan/phpstan": "^1.4.6",
|
||||
"phpstan/phpstan-strict-rules": "^1.1.0",
|
||||
"symfony/var-dumper": "^5.2.7|^6.0.0",
|
||||
"thecodingmachine/phpstan-strict-rules": "^1.0.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Termwind\\": "src/"
|
||||
},
|
||||
"files": [
|
||||
"src/Functions.php"
|
||||
]
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Tests\\": "tests/"
|
||||
}
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true,
|
||||
"config": {
|
||||
"sort-packages": true,
|
||||
"preferred-install": "dist",
|
||||
"allow-plugins": {
|
||||
"pestphp/pest-plugin": true
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "pint -v",
|
||||
"test:lint": "pint --test -v",
|
||||
"test:types": "phpstan analyse --ansi",
|
||||
"test:unit": "pest --colors=always",
|
||||
"test": [
|
||||
"@test:lint",
|
||||
"@test:types",
|
||||
"@test:unit"
|
||||
]
|
||||
},
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Termwind\\Laravel\\TermwindServiceProvider"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
14
vendor/nunomaduro/termwind/playground.php
vendored
Normal file
14
vendor/nunomaduro/termwind/playground.php
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/vendor/autoload.php';
|
||||
|
||||
use function Termwind\render;
|
||||
|
||||
render(<<<'HTML'
|
||||
<div class="mx-2 my-1">
|
||||
<div class="flex space-x-1">
|
||||
<span class="flex-1 truncate">Lorem ipsum dolor, sit amet consectetur adipisicing elit. Sunt illo et nisi omnis porro at, mollitia harum quas esse, aperiam dolorem ab recusandae fugiat nesciunt doloribus rem eaque nostrum itaque.</span>
|
||||
<span class="text-green">DONE</span>
|
||||
</div>
|
||||
</div>
|
||||
HTML);
|
154
vendor/nunomaduro/termwind/src/Actions/StyleToMethod.php
vendored
Normal file
154
vendor/nunomaduro/termwind/src/Actions/StyleToMethod.php
vendored
Normal file
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Termwind\Actions;
|
||||
|
||||
use Termwind\Exceptions\StyleNotFound;
|
||||
use Termwind\Repositories\Styles as StyleRepository;
|
||||
use Termwind\Terminal;
|
||||
use Termwind\ValueObjects\Styles;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class StyleToMethod
|
||||
{
|
||||
/**
|
||||
* Finds if there is any media query on the style class.
|
||||
*/
|
||||
private const MEDIA_QUERIES_REGEX = "/^(sm|md|lg|xl|2xl)\:(.*)/";
|
||||
|
||||
/**
|
||||
* Defines the Media Query Breakpoints.
|
||||
*/
|
||||
public const MEDIA_QUERY_BREAKPOINTS = [
|
||||
'sm' => 64,
|
||||
'md' => 76,
|
||||
'lg' => 102,
|
||||
'xl' => 128,
|
||||
'2xl' => 153,
|
||||
];
|
||||
|
||||
/**
|
||||
* Creates a new action instance.
|
||||
*/
|
||||
public function __construct(
|
||||
private Styles $styles,
|
||||
private string $style,
|
||||
) {
|
||||
// ..
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies multiple styles to the given styles.
|
||||
*/
|
||||
public static function multiple(Styles $styles, string $stylesString): Styles
|
||||
{
|
||||
$stylesString = self::sortStyles(array_merge(
|
||||
$styles->defaultStyles(),
|
||||
array_filter((array) preg_split('/(?![^\[]*\])\s/', $stylesString))
|
||||
));
|
||||
|
||||
foreach ($stylesString as $style) {
|
||||
$styles = (new self($styles, $style))->__invoke();
|
||||
}
|
||||
|
||||
return $styles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given style to a method name.
|
||||
*
|
||||
* @return Styles
|
||||
*/
|
||||
public function __invoke(string|int ...$arguments): Styles
|
||||
{
|
||||
if (StyleRepository::has($this->style)) {
|
||||
return StyleRepository::get($this->style)($this->styles, ...$arguments);
|
||||
}
|
||||
|
||||
$method = $this->applyMediaQuery($this->style);
|
||||
|
||||
if ($method === '') {
|
||||
return $this->styles;
|
||||
}
|
||||
|
||||
$method = array_filter(
|
||||
(array) preg_split('/(?![^\[]*\])-/', $method),
|
||||
fn ($item) => $item !== false
|
||||
);
|
||||
|
||||
$method = array_slice($method, 0, count($method) - count($arguments));
|
||||
|
||||
$methodName = implode(' ', $method);
|
||||
$methodName = ucwords($methodName);
|
||||
$methodName = lcfirst($methodName);
|
||||
$methodName = str_replace(' ', '', $methodName);
|
||||
|
||||
if ($methodName === '') {
|
||||
throw StyleNotFound::fromStyle($this->style);
|
||||
}
|
||||
|
||||
if (! method_exists($this->styles, $methodName)) {
|
||||
$argument = array_pop($method);
|
||||
|
||||
$arguments[] = is_numeric($argument) ? (int) $argument : (string) $argument;
|
||||
|
||||
return $this->__invoke(...$arguments);
|
||||
}
|
||||
|
||||
return $this->styles
|
||||
->setStyle($this->style)
|
||||
->$methodName(...array_reverse($arguments));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts all the styles based on the correct render order.
|
||||
*
|
||||
* @param string[] $styles
|
||||
* @return string[]
|
||||
*/
|
||||
private static function sortStyles(array $styles): array
|
||||
{
|
||||
$keys = array_keys(self::MEDIA_QUERY_BREAKPOINTS);
|
||||
|
||||
usort($styles, function ($a, $b) use ($keys) {
|
||||
$existsA = (bool) preg_match(self::MEDIA_QUERIES_REGEX, $a, $matchesA);
|
||||
$existsB = (bool) preg_match(self::MEDIA_QUERIES_REGEX, $b, $matchesB);
|
||||
|
||||
if ($existsA && ! $existsB) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ($existsA && array_search($matchesA[1], $keys, true) > array_search($matchesB[1], $keys, true)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return -1;
|
||||
});
|
||||
|
||||
return $styles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the media query if exists.
|
||||
*/
|
||||
private function applyMediaQuery(string $method): string
|
||||
{
|
||||
$matches = [];
|
||||
preg_match(self::MEDIA_QUERIES_REGEX, $method, $matches);
|
||||
|
||||
if (count($matches) < 1) {
|
||||
return $method;
|
||||
}
|
||||
|
||||
[, $size, $method] = $matches;
|
||||
|
||||
if ((new Terminal)->width() >= self::MEDIA_QUERY_BREAKPOINTS[$size]) {
|
||||
return $method;
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
9
vendor/nunomaduro/termwind/src/Components/Anchor.php
vendored
Normal file
9
vendor/nunomaduro/termwind/src/Components/Anchor.php
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Termwind\Components;
|
||||
|
||||
final class Anchor extends Element
|
||||
{
|
||||
}
|
26
vendor/nunomaduro/termwind/src/Components/BreakLine.php
vendored
Normal file
26
vendor/nunomaduro/termwind/src/Components/BreakLine.php
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Termwind\Components;
|
||||
|
||||
final class BreakLine extends Element
|
||||
{
|
||||
/**
|
||||
* Get the string representation of the element.
|
||||
*/
|
||||
public function toString(): string
|
||||
{
|
||||
$display = $this->styles->getProperties()['styles']['display'] ?? 'inline';
|
||||
|
||||
if ($display === 'hidden') {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ($display === 'block') {
|
||||
return parent::toString();
|
||||
}
|
||||
|
||||
return parent::toString()."\r";
|
||||
}
|
||||
}
|
10
vendor/nunomaduro/termwind/src/Components/Dd.php
vendored
Normal file
10
vendor/nunomaduro/termwind/src/Components/Dd.php
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Termwind\Components;
|
||||
|
||||
final class Dd extends Element
|
||||
{
|
||||
protected static array $defaultStyles = ['block', 'ml-4'];
|
||||
}
|
10
vendor/nunomaduro/termwind/src/Components/Div.php
vendored
Normal file
10
vendor/nunomaduro/termwind/src/Components/Div.php
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Termwind\Components;
|
||||
|
||||
final class Div extends Element
|
||||
{
|
||||
protected static array $defaultStyles = ['block'];
|
||||
}
|
10
vendor/nunomaduro/termwind/src/Components/Dl.php
vendored
Normal file
10
vendor/nunomaduro/termwind/src/Components/Dl.php
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Termwind\Components;
|
||||
|
||||
final class Dl extends Element
|
||||
{
|
||||
protected static array $defaultStyles = ['block'];
|
||||
}
|
10
vendor/nunomaduro/termwind/src/Components/Dt.php
vendored
Normal file
10
vendor/nunomaduro/termwind/src/Components/Dt.php
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Termwind\Components;
|
||||
|
||||
final class Dt extends Element
|
||||
{
|
||||
protected static array $defaultStyles = ['block', 'font-bold'];
|
||||
}
|
121
vendor/nunomaduro/termwind/src/Components/Element.php
vendored
Normal file
121
vendor/nunomaduro/termwind/src/Components/Element.php
vendored
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Termwind\Components;
|
||||
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Termwind\Actions\StyleToMethod;
|
||||
use Termwind\Html\InheritStyles;
|
||||
use Termwind\ValueObjects\Styles;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @method Element inheritFromStyles(Styles $styles)
|
||||
* @method Element fontBold()
|
||||
* @method Element strong()
|
||||
* @method Element italic()
|
||||
* @method Element underline()
|
||||
* @method Element lineThrough()
|
||||
* @method int getLength()
|
||||
* @method int getInnerWidth()
|
||||
* @method array getProperties()
|
||||
* @method Element href(string $href)
|
||||
* @method bool hasStyle(string $style)
|
||||
* @method Element addStyle(string $style)
|
||||
*/
|
||||
abstract class Element
|
||||
{
|
||||
/** @var string[] */
|
||||
protected static array $defaultStyles = [];
|
||||
|
||||
protected Styles $styles;
|
||||
|
||||
/**
|
||||
* Creates an element instance.
|
||||
*
|
||||
* @param array<int, Element|string>|string $content
|
||||
*/
|
||||
final public function __construct(
|
||||
protected OutputInterface $output,
|
||||
protected array|string $content,
|
||||
Styles|null $styles = null
|
||||
) {
|
||||
$this->styles = $styles ?? new Styles(defaultStyles: static::$defaultStyles);
|
||||
$this->styles->setElement($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an element instance with the given styles.
|
||||
*
|
||||
* @param array<int, Element|string>|string $content
|
||||
* @param array<string, mixed> $properties
|
||||
*/
|
||||
final public static function fromStyles(OutputInterface $output, array|string $content, string $styles = '', array $properties = []): static
|
||||
{
|
||||
$element = new static($output, $content);
|
||||
if ($properties !== []) {
|
||||
$element->styles->setProperties($properties);
|
||||
}
|
||||
|
||||
$elementStyles = StyleToMethod::multiple($element->styles, $styles);
|
||||
|
||||
return new static($output, $content, $elementStyles);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the string representation of the element.
|
||||
*/
|
||||
public function toString(): string
|
||||
{
|
||||
if (is_array($this->content)) {
|
||||
$inheritance = new InheritStyles();
|
||||
$this->content = implode('', $inheritance($this->content, $this->styles));
|
||||
}
|
||||
|
||||
return $this->styles->format($this->content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, mixed> $arguments
|
||||
*/
|
||||
public function __call(string $name, array $arguments): mixed
|
||||
{
|
||||
if (method_exists($this->styles, $name)) {
|
||||
$result = $this->styles->{$name}(...$arguments);
|
||||
|
||||
if (str_starts_with($name, 'get') || str_starts_with($name, 'has')) {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the content of the element.
|
||||
*
|
||||
* @param array<int, Element|string>|string $content
|
||||
*/
|
||||
final public function setContent(array|string $content): static
|
||||
{
|
||||
return new static($this->output, $content, $this->styles);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the string representation of the element on the output.
|
||||
*/
|
||||
final public function render(int $options): void
|
||||
{
|
||||
$this->output->writeln($this->toString(), $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the string representation of the element.
|
||||
*/
|
||||
final public function __toString(): string
|
||||
{
|
||||
return $this->toString();
|
||||
}
|
||||
}
|
10
vendor/nunomaduro/termwind/src/Components/Hr.php
vendored
Normal file
10
vendor/nunomaduro/termwind/src/Components/Hr.php
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Termwind\Components;
|
||||
|
||||
final class Hr extends Element
|
||||
{
|
||||
protected static array $defaultStyles = ['block', 'border-t'];
|
||||
}
|
10
vendor/nunomaduro/termwind/src/Components/Li.php
vendored
Normal file
10
vendor/nunomaduro/termwind/src/Components/Li.php
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Termwind\Components;
|
||||
|
||||
final class Li extends Element
|
||||
{
|
||||
protected static array $defaultStyles = ['block'];
|
||||
}
|
10
vendor/nunomaduro/termwind/src/Components/Ol.php
vendored
Normal file
10
vendor/nunomaduro/termwind/src/Components/Ol.php
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Termwind\Components;
|
||||
|
||||
final class Ol extends Element
|
||||
{
|
||||
protected static array $defaultStyles = ['block', 'list-decimal'];
|
||||
}
|
10
vendor/nunomaduro/termwind/src/Components/Paragraph.php
vendored
Normal file
10
vendor/nunomaduro/termwind/src/Components/Paragraph.php
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Termwind\Components;
|
||||
|
||||
final class Paragraph extends Element
|
||||
{
|
||||
protected static array $defaultStyles = ['block', 'my-1'];
|
||||
}
|
19
vendor/nunomaduro/termwind/src/Components/Raw.php
vendored
Normal file
19
vendor/nunomaduro/termwind/src/Components/Raw.php
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Termwind\Components;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class Raw extends Element
|
||||
{
|
||||
/**
|
||||
* Get the string representation of the element.
|
||||
*/
|
||||
public function toString(): string
|
||||
{
|
||||
return is_array($this->content) ? implode('', $this->content) : $this->content;
|
||||
}
|
||||
}
|
10
vendor/nunomaduro/termwind/src/Components/Span.php
vendored
Normal file
10
vendor/nunomaduro/termwind/src/Components/Span.php
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Termwind\Components;
|
||||
|
||||
final class Span extends Element
|
||||
{
|
||||
// ..
|
||||
}
|
10
vendor/nunomaduro/termwind/src/Components/Ul.php
vendored
Normal file
10
vendor/nunomaduro/termwind/src/Components/Ul.php
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Termwind\Components;
|
||||
|
||||
final class Ul extends Element
|
||||
{
|
||||
protected static array $defaultStyles = ['block', 'list-disc'];
|
||||
}
|
482
vendor/nunomaduro/termwind/src/Enums/Color.php
vendored
Normal file
482
vendor/nunomaduro/termwind/src/Enums/Color.php
vendored
Normal file
@@ -0,0 +1,482 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Termwind\Enums;
|
||||
|
||||
final class Color
|
||||
{
|
||||
public const BLACK = 'black';
|
||||
|
||||
public const WHITE = 'white';
|
||||
|
||||
public const BRIGHTWHITE = 'bright-white';
|
||||
|
||||
public const SLATE_50 = '#f8fafc';
|
||||
|
||||
public const SLATE_100 = '#f1f5f9';
|
||||
|
||||
public const SLATE_200 = '#e2e8f0';
|
||||
|
||||
public const SLATE_300 = '#cbd5e1';
|
||||
|
||||
public const SLATE_400 = '#94a3b8';
|
||||
|
||||
public const SLATE_500 = '#64748b';
|
||||
|
||||
public const SLATE_600 = '#475569';
|
||||
|
||||
public const SLATE_700 = '#334155';
|
||||
|
||||
public const SLATE_800 = '#1e293b';
|
||||
|
||||
public const SLATE_900 = '#0f172a';
|
||||
|
||||
public const GRAY = 'gray';
|
||||
|
||||
public const GRAY_50 = '#f9fafb';
|
||||
|
||||
public const GRAY_100 = '#f3f4f6';
|
||||
|
||||
public const GRAY_200 = '#e5e7eb';
|
||||
|
||||
public const GRAY_300 = '#d1d5db';
|
||||
|
||||
public const GRAY_400 = '#9ca3af';
|
||||
|
||||
public const GRAY_500 = '#6b7280';
|
||||
|
||||
public const GRAY_600 = '#4b5563';
|
||||
|
||||
public const GRAY_700 = '#374151';
|
||||
|
||||
public const GRAY_800 = '#1f2937';
|
||||
|
||||
public const GRAY_900 = '#111827';
|
||||
|
||||
public const ZINC_50 = '#fafafa';
|
||||
|
||||
public const ZINC_100 = '#f4f4f5';
|
||||
|
||||
public const ZINC_200 = '#e4e4e7';
|
||||
|
||||
public const ZINC_300 = '#d4d4d8';
|
||||
|
||||
public const ZINC_400 = '#a1a1aa';
|
||||
|
||||
public const ZINC_500 = '#71717a';
|
||||
|
||||
public const ZINC_600 = '#52525b';
|
||||
|
||||
public const ZINC_700 = '#3f3f46';
|
||||
|
||||
public const ZINC_800 = '#27272a';
|
||||
|
||||
public const ZINC_900 = '#18181b';
|
||||
|
||||
public const NEUTRAL_50 = '#fafafa';
|
||||
|
||||
public const NEUTRAL_100 = '#f5f5f5';
|
||||
|
||||
public const NEUTRAL_200 = '#e5e5e5';
|
||||
|
||||
public const NEUTRAL_300 = '#d4d4d4';
|
||||
|
||||
public const NEUTRAL_400 = '#a3a3a3';
|
||||
|
||||
public const NEUTRAL_500 = '#737373';
|
||||
|
||||
public const NEUTRAL_600 = '#525252';
|
||||
|
||||
public const NEUTRAL_700 = '#404040';
|
||||
|
||||
public const NEUTRAL_800 = '#262626';
|
||||
|
||||
public const NEUTRAL_900 = '#171717';
|
||||
|
||||
public const STONE_50 = '#fafaf9';
|
||||
|
||||
public const STONE_100 = '#f5f5f4';
|
||||
|
||||
public const STONE_200 = '#e7e5e4';
|
||||
|
||||
public const STONE_300 = '#d6d3d1';
|
||||
|
||||
public const STONE_400 = '#a8a29e';
|
||||
|
||||
public const STONE_500 = '#78716c';
|
||||
|
||||
public const STONE_600 = '#57534e';
|
||||
|
||||
public const STONE_700 = '#44403c';
|
||||
|
||||
public const STONE_800 = '#292524';
|
||||
|
||||
public const STONE_900 = '#1c1917';
|
||||
|
||||
public const RED = 'red';
|
||||
|
||||
public const BRIGHTRED = 'bright-red';
|
||||
|
||||
public const RED_50 = '#fef2f2';
|
||||
|
||||
public const RED_100 = '#fee2e2';
|
||||
|
||||
public const RED_200 = '#fecaca';
|
||||
|
||||
public const RED_300 = '#fca5a5';
|
||||
|
||||
public const RED_400 = '#f87171';
|
||||
|
||||
public const RED_500 = '#ef4444';
|
||||
|
||||
public const RED_600 = '#dc2626';
|
||||
|
||||
public const RED_700 = '#b91c1c';
|
||||
|
||||
public const RED_800 = '#991b1b';
|
||||
|
||||
public const RED_900 = '#7f1d1d';
|
||||
|
||||
public const ORANGE = '#f97316';
|
||||
|
||||
public const ORANGE_50 = '#fff7ed';
|
||||
|
||||
public const ORANGE_100 = '#ffedd5';
|
||||
|
||||
public const ORANGE_200 = '#fed7aa';
|
||||
|
||||
public const ORANGE_300 = '#fdba74';
|
||||
|
||||
public const ORANGE_400 = '#fb923c';
|
||||
|
||||
public const ORANGE_500 = '#f97316';
|
||||
|
||||
public const ORANGE_600 = '#ea580c';
|
||||
|
||||
public const ORANGE_700 = '#c2410c';
|
||||
|
||||
public const ORANGE_800 = '#9a3412';
|
||||
|
||||
public const ORANGE_900 = '#7c2d12';
|
||||
|
||||
public const AMBER_50 = '#fffbeb';
|
||||
|
||||
public const AMBER_100 = '#fef3c7';
|
||||
|
||||
public const AMBER_200 = '#fde68a';
|
||||
|
||||
public const AMBER_300 = '#fcd34d';
|
||||
|
||||
public const AMBER_400 = '#fbbf24';
|
||||
|
||||
public const AMBER_500 = '#f59e0b';
|
||||
|
||||
public const AMBER_600 = '#d97706';
|
||||
|
||||
public const AMBER_700 = '#b45309';
|
||||
|
||||
public const AMBER_800 = '#92400e';
|
||||
|
||||
public const AMBER_900 = '#78350f';
|
||||
|
||||
public const YELLOW = 'yellow';
|
||||
|
||||
public const BRIGHTYELLOW = 'bright-yellow';
|
||||
|
||||
public const YELLOW_50 = '#fefce8';
|
||||
|
||||
public const YELLOW_100 = '#fef9c3';
|
||||
|
||||
public const YELLOW_200 = '#fef08a';
|
||||
|
||||
public const YELLOW_300 = '#fde047';
|
||||
|
||||
public const YELLOW_400 = '#facc15';
|
||||
|
||||
public const YELLOW_500 = '#eab308';
|
||||
|
||||
public const YELLOW_600 = '#ca8a04';
|
||||
|
||||
public const YELLOW_700 = '#a16207';
|
||||
|
||||
public const YELLOW_800 = '#854d0e';
|
||||
|
||||
public const YELLOW_900 = '#713f12';
|
||||
|
||||
public const LIME_50 = '#f7fee7';
|
||||
|
||||
public const LIME_100 = '#ecfccb';
|
||||
|
||||
public const LIME_200 = '#d9f99d';
|
||||
|
||||
public const LIME_300 = '#bef264';
|
||||
|
||||
public const LIME_400 = '#a3e635';
|
||||
|
||||
public const LIME_500 = '#84cc16';
|
||||
|
||||
public const LIME_600 = '#65a30d';
|
||||
|
||||
public const LIME_700 = '#4d7c0f';
|
||||
|
||||
public const LIME_800 = '#3f6212';
|
||||
|
||||
public const LIME_900 = '#365314';
|
||||
|
||||
public const GREEN = 'green';
|
||||
|
||||
public const BRIGHTGREEN = 'bright-green';
|
||||
|
||||
public const GREEN_50 = '#f0fdf4';
|
||||
|
||||
public const GREEN_100 = '#dcfce7';
|
||||
|
||||
public const GREEN_200 = '#bbf7d0';
|
||||
|
||||
public const GREEN_300 = '#86efac';
|
||||
|
||||
public const GREEN_400 = '#4ade80';
|
||||
|
||||
public const GREEN_500 = '#22c55e';
|
||||
|
||||
public const GREEN_600 = '#16a34a';
|
||||
|
||||
public const GREEN_700 = '#15803d';
|
||||
|
||||
public const GREEN_800 = '#166534';
|
||||
|
||||
public const GREEN_900 = '#14532d';
|
||||
|
||||
public const EMERALD_50 = '#ecfdf5';
|
||||
|
||||
public const EMERALD_100 = '#d1fae5';
|
||||
|
||||
public const EMERALD_200 = '#a7f3d0';
|
||||
|
||||
public const EMERALD_300 = '#6ee7b7';
|
||||
|
||||
public const EMERALD_400 = '#34d399';
|
||||
|
||||
public const EMERALD_500 = '#10b981';
|
||||
|
||||
public const EMERALD_600 = '#059669';
|
||||
|
||||
public const EMERALD_700 = '#047857';
|
||||
|
||||
public const EMERALD_800 = '#065f46';
|
||||
|
||||
public const EMERALD_900 = '#064e3b';
|
||||
|
||||
public const TEAL_50 = '#f0fdfa';
|
||||
|
||||
public const TEAL_100 = '#ccfbf1';
|
||||
|
||||
public const TEAL_200 = '#99f6e4';
|
||||
|
||||
public const TEAL_300 = '#5eead4';
|
||||
|
||||
public const TEAL_400 = '#2dd4bf';
|
||||
|
||||
public const TEAL_500 = '#14b8a6';
|
||||
|
||||
public const TEAL_600 = '#0d9488';
|
||||
|
||||
public const TEAL_700 = '#0f766e';
|
||||
|
||||
public const TEAL_800 = '#115e59';
|
||||
|
||||
public const TEAL_900 = '#134e4a';
|
||||
|
||||
public const CYAN = 'cyan';
|
||||
|
||||
public const BRIGHTCYAN = 'bright-cyan';
|
||||
|
||||
public const CYAN_50 = '#ecfeff';
|
||||
|
||||
public const CYAN_100 = '#cffafe';
|
||||
|
||||
public const CYAN_200 = '#a5f3fc';
|
||||
|
||||
public const CYAN_300 = '#67e8f9';
|
||||
|
||||
public const CYAN_400 = '#22d3ee';
|
||||
|
||||
public const CYAN_500 = '#06b6d4';
|
||||
|
||||
public const CYAN_600 = '#0891b2';
|
||||
|
||||
public const CYAN_700 = '#0e7490';
|
||||
|
||||
public const CYAN_800 = '#155e75';
|
||||
|
||||
public const CYAN_900 = '#164e63';
|
||||
|
||||
public const SKY_50 = '#f0f9ff';
|
||||
|
||||
public const SKY_100 = '#e0f2fe';
|
||||
|
||||
public const SKY_200 = '#bae6fd';
|
||||
|
||||
public const SKY_300 = '#7dd3fc';
|
||||
|
||||
public const SKY_400 = '#38bdf8';
|
||||
|
||||
public const SKY_500 = '#0ea5e9';
|
||||
|
||||
public const SKY_600 = '#0284c7';
|
||||
|
||||
public const SKY_700 = '#0369a1';
|
||||
|
||||
public const SKY_800 = '#075985';
|
||||
|
||||
public const SKY_900 = '#0c4a6e';
|
||||
|
||||
public const BLUE = 'blue';
|
||||
|
||||
public const BRIGHTBLUE = 'bright-blue';
|
||||
|
||||
public const BLUE_50 = '#eff6ff';
|
||||
|
||||
public const BLUE_100 = '#dbeafe';
|
||||
|
||||
public const BLUE_200 = '#bfdbfe';
|
||||
|
||||
public const BLUE_300 = '#93c5fd';
|
||||
|
||||
public const BLUE_400 = '#60a5fa';
|
||||
|
||||
public const BLUE_500 = '#3b82f6';
|
||||
|
||||
public const BLUE_600 = '#2563eb';
|
||||
|
||||
public const BLUE_700 = '#1d4ed8';
|
||||
|
||||
public const BLUE_800 = '#1e40af';
|
||||
|
||||
public const BLUE_900 = '#1e3a8a';
|
||||
|
||||
public const INDIGO_50 = '#eef2ff';
|
||||
|
||||
public const INDIGO_100 = '#e0e7ff';
|
||||
|
||||
public const INDIGO_200 = '#c7d2fe';
|
||||
|
||||
public const INDIGO_300 = '#a5b4fc';
|
||||
|
||||
public const INDIGO_400 = '#818cf8';
|
||||
|
||||
public const INDIGO_500 = '#6366f1';
|
||||
|
||||
public const INDIGO_600 = '#4f46e5';
|
||||
|
||||
public const INDIGO_700 = '#4338ca';
|
||||
|
||||
public const INDIGO_800 = '#3730a3';
|
||||
|
||||
public const INDIGO_900 = '#312e81';
|
||||
|
||||
public const VIOLET_50 = '#f5f3ff';
|
||||
|
||||
public const VIOLET_100 = '#ede9fe';
|
||||
|
||||
public const VIOLET_200 = '#ddd6fe';
|
||||
|
||||
public const VIOLET_300 = '#c4b5fd';
|
||||
|
||||
public const VIOLET_400 = '#a78bfa';
|
||||
|
||||
public const VIOLET_500 = '#8b5cf6';
|
||||
|
||||
public const VIOLET_600 = '#7c3aed';
|
||||
|
||||
public const VIOLET_700 = '#6d28d9';
|
||||
|
||||
public const VIOLET_800 = '#5b21b6';
|
||||
|
||||
public const VIOLET_900 = '#4c1d95';
|
||||
|
||||
public const PURPLE_50 = '#faf5ff';
|
||||
|
||||
public const PURPLE_100 = '#f3e8ff';
|
||||
|
||||
public const PURPLE_200 = '#e9d5ff';
|
||||
|
||||
public const PURPLE_300 = '#d8b4fe';
|
||||
|
||||
public const PURPLE_400 = '#c084fc';
|
||||
|
||||
public const PURPLE_500 = '#a855f7';
|
||||
|
||||
public const PURPLE_600 = '#9333ea';
|
||||
|
||||
public const PURPLE_700 = '#7e22ce';
|
||||
|
||||
public const PURPLE_800 = '#6b21a8';
|
||||
|
||||
public const PURPLE_900 = '#581c87';
|
||||
|
||||
public const FUCHSIA_50 = '#fdf4ff';
|
||||
|
||||
public const FUCHSIA_100 = '#fae8ff';
|
||||
|
||||
public const FUCHSIA_200 = '#f5d0fe';
|
||||
|
||||
public const FUCHSIA_300 = '#f0abfc';
|
||||
|
||||
public const FUCHSIA_400 = '#e879f9';
|
||||
|
||||
public const FUCHSIA_500 = '#d946ef';
|
||||
|
||||
public const FUCHSIA_600 = '#c026d3';
|
||||
|
||||
public const FUCHSIA_700 = '#a21caf';
|
||||
|
||||
public const FUCHSIA_800 = '#86198f';
|
||||
|
||||
public const FUCHSIA_900 = '#701a75';
|
||||
|
||||
public const PINK_50 = '#fdf2f8';
|
||||
|
||||
public const PINK_100 = '#fce7f3';
|
||||
|
||||
public const PINK_200 = '#fbcfe8';
|
||||
|
||||
public const PINK_300 = '#f9a8d4';
|
||||
|
||||
public const PINK_400 = '#f472b6';
|
||||
|
||||
public const PINK_500 = '#ec4899';
|
||||
|
||||
public const PINK_600 = '#db2777';
|
||||
|
||||
public const PINK_700 = '#be185d';
|
||||
|
||||
public const PINK_800 = '#9d174d';
|
||||
|
||||
public const PINK_900 = '#831843';
|
||||
|
||||
public const ROSE_50 = '#fff1f2';
|
||||
|
||||
public const ROSE_100 = '#ffe4e6';
|
||||
|
||||
public const ROSE_200 = '#fecdd3';
|
||||
|
||||
public const ROSE_300 = '#fda4af';
|
||||
|
||||
public const ROSE_400 = '#fb7185';
|
||||
|
||||
public const ROSE_500 = '#f43f5e';
|
||||
|
||||
public const ROSE_600 = '#e11d48';
|
||||
|
||||
public const ROSE_700 = '#be123c';
|
||||
|
||||
public const ROSE_800 = '#9f1239';
|
||||
|
||||
public const ROSE_900 = '#881337';
|
||||
|
||||
public const MAGENTA = 'magenta';
|
||||
|
||||
public const BRIGHTMAGENTA = 'bright-magenta';
|
||||
}
|
14
vendor/nunomaduro/termwind/src/Exceptions/ColorNotFound.php
vendored
Normal file
14
vendor/nunomaduro/termwind/src/Exceptions/ColorNotFound.php
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Termwind\Exceptions;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class ColorNotFound extends InvalidArgumentException
|
||||
{
|
||||
}
|
14
vendor/nunomaduro/termwind/src/Exceptions/InvalidChild.php
vendored
Normal file
14
vendor/nunomaduro/termwind/src/Exceptions/InvalidChild.php
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Termwind\Exceptions;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class InvalidChild extends InvalidArgumentException
|
||||
{
|
||||
}
|
14
vendor/nunomaduro/termwind/src/Exceptions/InvalidColor.php
vendored
Normal file
14
vendor/nunomaduro/termwind/src/Exceptions/InvalidColor.php
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Termwind\Exceptions;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class InvalidColor extends InvalidArgumentException
|
||||
{
|
||||
}
|
14
vendor/nunomaduro/termwind/src/Exceptions/InvalidStyle.php
vendored
Normal file
14
vendor/nunomaduro/termwind/src/Exceptions/InvalidStyle.php
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Termwind\Exceptions;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class InvalidStyle extends InvalidArgumentException
|
||||
{
|
||||
}
|
29
vendor/nunomaduro/termwind/src/Exceptions/StyleNotFound.php
vendored
Normal file
29
vendor/nunomaduro/termwind/src/Exceptions/StyleNotFound.php
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Termwind\Exceptions;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class StyleNotFound extends InvalidArgumentException
|
||||
{
|
||||
/**
|
||||
* Creates a new style not found instance.
|
||||
*/
|
||||
private function __construct(string $message)
|
||||
{
|
||||
parent::__construct($message, 0, $this->getPrevious());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new style not found instance from the given style.
|
||||
*/
|
||||
public static function fromStyle(string $style): self
|
||||
{
|
||||
return new self(sprintf('Style [%s] not found.', $style));
|
||||
}
|
||||
}
|
65
vendor/nunomaduro/termwind/src/Functions.php
vendored
Normal file
65
vendor/nunomaduro/termwind/src/Functions.php
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Termwind;
|
||||
|
||||
use Closure;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Termwind\Repositories\Styles as StyleRepository;
|
||||
use Termwind\ValueObjects\Style;
|
||||
use Termwind\ValueObjects\Styles;
|
||||
|
||||
if (! function_exists('Termwind\renderUsing')) {
|
||||
/**
|
||||
* Sets the renderer implementation.
|
||||
*/
|
||||
function renderUsing(OutputInterface|null $renderer): void
|
||||
{
|
||||
Termwind::renderUsing($renderer);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('Termwind\style')) {
|
||||
/**
|
||||
* Creates a new style.
|
||||
*
|
||||
* @param (Closure(Styles $renderable, string|int ...$arguments): Styles)|null $callback
|
||||
*/
|
||||
function style(string $name, Closure $callback = null): Style
|
||||
{
|
||||
return StyleRepository::create($name, $callback);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('Termwind\render')) {
|
||||
/**
|
||||
* Render HTML to a string.
|
||||
*/
|
||||
function render(string $html, int $options = OutputInterface::OUTPUT_NORMAL): void
|
||||
{
|
||||
(new HtmlRenderer)->render($html, $options);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('Termwind\terminal')) {
|
||||
/**
|
||||
* Returns a Terminal instance.
|
||||
*/
|
||||
function terminal(): Terminal
|
||||
{
|
||||
return new Terminal;
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('Termwind\ask')) {
|
||||
/**
|
||||
* Renders a prompt to the user.
|
||||
*
|
||||
* @param iterable<array-key, string>|null $autocomplete
|
||||
*/
|
||||
function ask(string $question, iterable $autocomplete = null): mixed
|
||||
{
|
||||
return (new Question)->ask($question, $autocomplete);
|
||||
}
|
||||
}
|
25
vendor/nunomaduro/termwind/src/Helpers/QuestionHelper.php
vendored
Normal file
25
vendor/nunomaduro/termwind/src/Helpers/QuestionHelper.php
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Termwind\Helpers;
|
||||
|
||||
use Symfony\Component\Console\Formatter\OutputFormatter;
|
||||
use Symfony\Component\Console\Helper\SymfonyQuestionHelper;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Question\Question;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class QuestionHelper extends SymfonyQuestionHelper
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function writePrompt(OutputInterface $output, Question $question): void
|
||||
{
|
||||
$text = OutputFormatter::escapeTrailingBackslash($question->getQuestion());
|
||||
$output->write($text);
|
||||
}
|
||||
}
|
282
vendor/nunomaduro/termwind/src/Html/CodeRenderer.php
vendored
Normal file
282
vendor/nunomaduro/termwind/src/Html/CodeRenderer.php
vendored
Normal file
@@ -0,0 +1,282 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Termwind\Html;
|
||||
|
||||
use Termwind\Components\Element;
|
||||
use Termwind\Termwind;
|
||||
use Termwind\ValueObjects\Node;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class CodeRenderer
|
||||
{
|
||||
public const TOKEN_DEFAULT = 'token_default';
|
||||
|
||||
public const TOKEN_COMMENT = 'token_comment';
|
||||
|
||||
public const TOKEN_STRING = 'token_string';
|
||||
|
||||
public const TOKEN_HTML = 'token_html';
|
||||
|
||||
public const TOKEN_KEYWORD = 'token_keyword';
|
||||
|
||||
public const ACTUAL_LINE_MARK = 'actual_line_mark';
|
||||
|
||||
public const LINE_NUMBER = 'line_number';
|
||||
|
||||
private const ARROW_SYMBOL_UTF8 = '➜';
|
||||
|
||||
private const DELIMITER_UTF8 = '▕ '; // '▶';
|
||||
|
||||
private const LINE_NUMBER_DIVIDER = 'line_divider';
|
||||
|
||||
private const MARKED_LINE_NUMBER = 'marked_line';
|
||||
|
||||
private const WIDTH = 3;
|
||||
|
||||
/**
|
||||
* Holds the theme.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
private const THEME = [
|
||||
self::TOKEN_STRING => 'text-gray',
|
||||
self::TOKEN_COMMENT => 'text-gray italic',
|
||||
self::TOKEN_KEYWORD => 'text-magenta strong',
|
||||
self::TOKEN_DEFAULT => 'strong',
|
||||
self::TOKEN_HTML => 'text-blue strong',
|
||||
|
||||
self::ACTUAL_LINE_MARK => 'text-red strong',
|
||||
self::LINE_NUMBER => 'text-gray',
|
||||
self::MARKED_LINE_NUMBER => 'italic strong',
|
||||
self::LINE_NUMBER_DIVIDER => 'text-gray',
|
||||
];
|
||||
|
||||
private string $delimiter = self::DELIMITER_UTF8;
|
||||
|
||||
private string $arrow = self::ARROW_SYMBOL_UTF8;
|
||||
|
||||
private const NO_MARK = ' ';
|
||||
|
||||
/**
|
||||
* Highlights HTML content from a given node and converts to the content element.
|
||||
*/
|
||||
public function toElement(Node $node): Element
|
||||
{
|
||||
$line = max((int) $node->getAttribute('line'), 0);
|
||||
$startLine = max((int) $node->getAttribute('start-line'), 1);
|
||||
|
||||
$html = $node->getHtml();
|
||||
$lines = explode("\n", $html);
|
||||
$extraSpaces = $this->findExtraSpaces($lines);
|
||||
|
||||
if ($extraSpaces !== '') {
|
||||
$lines = array_map(static function (string $line) use ($extraSpaces): string {
|
||||
return str_starts_with($line, $extraSpaces) ? substr($line, strlen($extraSpaces)) : $line;
|
||||
}, $lines);
|
||||
$html = implode("\n", $lines);
|
||||
}
|
||||
|
||||
$tokenLines = $this->getHighlightedLines(trim($html, "\n"), $startLine);
|
||||
$lines = $this->colorLines($tokenLines);
|
||||
$lines = $this->lineNumbers($lines, $line);
|
||||
|
||||
return Termwind::div(trim($lines, "\n"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds extra spaces which should be removed from HTML.
|
||||
*
|
||||
* @param array<int, string> $lines
|
||||
*/
|
||||
private function findExtraSpaces(array $lines): string
|
||||
{
|
||||
foreach ($lines as $line) {
|
||||
if ($line === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (preg_replace('/\s+/', '', $line) === '') {
|
||||
return $line;
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns content split into lines with numbers.
|
||||
*
|
||||
* @return array<int, array<int, array{0: string, 1: non-empty-string}>>
|
||||
*/
|
||||
private function getHighlightedLines(string $source, int $startLine): array
|
||||
{
|
||||
$source = str_replace(["\r\n", "\r"], "\n", $source);
|
||||
$tokens = $this->tokenize($source);
|
||||
|
||||
return $this->splitToLines($tokens, $startLine - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits content into tokens.
|
||||
*
|
||||
* @return array<int, array{0: string, 1: string}>
|
||||
*/
|
||||
private function tokenize(string $source): array
|
||||
{
|
||||
$tokens = token_get_all($source);
|
||||
|
||||
$output = [];
|
||||
$currentType = null;
|
||||
$newType = self::TOKEN_KEYWORD;
|
||||
$buffer = '';
|
||||
|
||||
foreach ($tokens as $token) {
|
||||
if (is_array($token)) {
|
||||
if ($token[0] !== T_WHITESPACE) {
|
||||
$newType = match ($token[0]) {
|
||||
T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO, T_CLOSE_TAG, T_STRING, T_VARIABLE,
|
||||
T_DIR, T_FILE, T_METHOD_C, T_DNUMBER, T_LNUMBER, T_NS_C,
|
||||
T_LINE, T_CLASS_C, T_FUNC_C, T_TRAIT_C => self::TOKEN_DEFAULT,
|
||||
T_COMMENT, T_DOC_COMMENT => self::TOKEN_COMMENT,
|
||||
T_ENCAPSED_AND_WHITESPACE, T_CONSTANT_ENCAPSED_STRING => self::TOKEN_STRING,
|
||||
T_INLINE_HTML => self::TOKEN_HTML,
|
||||
default => self::TOKEN_KEYWORD
|
||||
};
|
||||
}
|
||||
} else {
|
||||
$newType = $token === '"' ? self::TOKEN_STRING : self::TOKEN_KEYWORD;
|
||||
}
|
||||
|
||||
if ($currentType === null) {
|
||||
$currentType = $newType;
|
||||
}
|
||||
|
||||
if ($currentType !== $newType) {
|
||||
$output[] = [$currentType, $buffer];
|
||||
$buffer = '';
|
||||
$currentType = $newType;
|
||||
}
|
||||
|
||||
$buffer .= is_array($token) ? $token[1] : $token;
|
||||
}
|
||||
|
||||
$output[] = [$newType, $buffer];
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits tokens into lines.
|
||||
*
|
||||
* @param array<int, array{0: string, 1: string}> $tokens
|
||||
* @param int $startLine
|
||||
* @return array<int, array<int, array{0: string, 1: non-empty-string}>>
|
||||
*/
|
||||
private function splitToLines(array $tokens, int $startLine): array
|
||||
{
|
||||
$lines = [];
|
||||
|
||||
$line = [];
|
||||
foreach ($tokens as $token) {
|
||||
foreach (explode("\n", $token[1]) as $count => $tokenLine) {
|
||||
if ($count > 0) {
|
||||
$lines[$startLine++] = $line;
|
||||
$line = [];
|
||||
}
|
||||
|
||||
if ($tokenLine === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$line[] = [$token[0], $tokenLine];
|
||||
}
|
||||
}
|
||||
|
||||
$lines[$startLine++] = $line;
|
||||
|
||||
return $lines;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies colors to tokens according to a color schema.
|
||||
*
|
||||
* @param array<int, array<int, array{0: string, 1: non-empty-string}>> $tokenLines
|
||||
* @return array<int, string>
|
||||
*/
|
||||
private function colorLines(array $tokenLines): array
|
||||
{
|
||||
$lines = [];
|
||||
|
||||
foreach ($tokenLines as $lineCount => $tokenLine) {
|
||||
$line = '';
|
||||
foreach ($tokenLine as $token) {
|
||||
[$tokenType, $tokenValue] = $token;
|
||||
$line .= $this->styleToken($tokenType, $tokenValue);
|
||||
}
|
||||
|
||||
$lines[$lineCount] = $line;
|
||||
}
|
||||
|
||||
return $lines;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepends line numbers into lines.
|
||||
*
|
||||
* @param array<int, string> $lines
|
||||
* @param int $markLine
|
||||
* @return string
|
||||
*/
|
||||
private function lineNumbers(array $lines, int $markLine): string
|
||||
{
|
||||
$lastLine = (int) array_key_last($lines);
|
||||
$lineLength = strlen((string) ($lastLine + 1));
|
||||
$lineLength = $lineLength < self::WIDTH ? self::WIDTH : $lineLength;
|
||||
|
||||
$snippet = '';
|
||||
$mark = ' '.$this->arrow.' ';
|
||||
foreach ($lines as $i => $line) {
|
||||
$coloredLineNumber = $this->coloredLineNumber(self::LINE_NUMBER, $i, $lineLength);
|
||||
|
||||
if (0 !== $markLine) {
|
||||
$snippet .= ($markLine === $i + 1
|
||||
? $this->styleToken(self::ACTUAL_LINE_MARK, $mark)
|
||||
: self::NO_MARK
|
||||
);
|
||||
|
||||
$coloredLineNumber = ($markLine === $i + 1 ?
|
||||
$this->coloredLineNumber(self::MARKED_LINE_NUMBER, $i, $lineLength) :
|
||||
$coloredLineNumber
|
||||
);
|
||||
}
|
||||
|
||||
$snippet .= $coloredLineNumber;
|
||||
$snippet .= $this->styleToken(self::LINE_NUMBER_DIVIDER, $this->delimiter);
|
||||
$snippet .= $line.PHP_EOL;
|
||||
}
|
||||
|
||||
return $snippet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats line number and applies color according to a color schema.
|
||||
*/
|
||||
private function coloredLineNumber(string $token, int $lineNumber, int $length): string
|
||||
{
|
||||
return $this->styleToken(
|
||||
$token, str_pad((string) ($lineNumber + 1), $length, ' ', STR_PAD_LEFT)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats string and applies color according to a color schema.
|
||||
*/
|
||||
private function styleToken(string $token, string $string): string
|
||||
{
|
||||
return (string) Termwind::span($string, self::THEME[$token]);
|
||||
}
|
||||
}
|
210
vendor/nunomaduro/termwind/src/Html/InheritStyles.php
vendored
Normal file
210
vendor/nunomaduro/termwind/src/Html/InheritStyles.php
vendored
Normal file
@@ -0,0 +1,210 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Termwind\Html;
|
||||
|
||||
use Termwind\Components\Element;
|
||||
use Termwind\Termwind;
|
||||
use Termwind\ValueObjects\Styles;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class InheritStyles
|
||||
{
|
||||
/**
|
||||
* Applies styles from parent element to child elements.
|
||||
*
|
||||
* @param array<int, Element|string> $elements
|
||||
* @return array<int, Element|string>
|
||||
*/
|
||||
public function __invoke(array $elements, Styles $styles): array
|
||||
{
|
||||
$elements = array_values($elements);
|
||||
|
||||
foreach ($elements as &$element) {
|
||||
if (is_string($element)) {
|
||||
$element = Termwind::raw($element);
|
||||
}
|
||||
|
||||
$element->inheritFromStyles($styles);
|
||||
}
|
||||
|
||||
/** @var Element[] $elements */
|
||||
if (($styles->getProperties()['styles']['display'] ?? 'inline') === 'flex') {
|
||||
$elements = $this->applyFlex($elements);
|
||||
}
|
||||
|
||||
return match ($styles->getProperties()['styles']['justifyContent'] ?? false) {
|
||||
'between' => $this->applyJustifyBetween($elements),
|
||||
'evenly' => $this->applyJustifyEvenly($elements),
|
||||
'around' => $this->applyJustifyAround($elements),
|
||||
'center' => $this->applyJustifyCenter($elements),
|
||||
default => $elements,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies flex-1 to child elements with the class.
|
||||
*
|
||||
* @param array<int, Element> $elements
|
||||
* @return array<int, Element>
|
||||
*/
|
||||
private function applyFlex(array $elements): array
|
||||
{
|
||||
[$totalWidth, $parentWidth] = $this->getWidthFromElements($elements);
|
||||
|
||||
$width = max(0, array_reduce($elements, function ($carry, $element) {
|
||||
return $carry += $element->hasStyle('flex-1') ? $element->getInnerWidth() : 0;
|
||||
}, $parentWidth - $totalWidth));
|
||||
|
||||
$flexed = array_values(array_filter(
|
||||
$elements, fn ($element) => $element->hasStyle('flex-1')
|
||||
));
|
||||
|
||||
foreach ($flexed as $index => &$element) {
|
||||
if ($width === 0 && ! ($element->getProperties()['styles']['contentRepeat'] ?? false)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$float = $width / count($flexed);
|
||||
$elementWidth = floor($float);
|
||||
|
||||
if ($index === count($flexed) - 1) {
|
||||
$elementWidth += ($float - floor($float)) * count($flexed);
|
||||
}
|
||||
|
||||
$element->addStyle("w-{$elementWidth}");
|
||||
}
|
||||
|
||||
return $elements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the space between the elements.
|
||||
*
|
||||
* @param array<int, Element> $elements
|
||||
* @return array<int, Element|string>
|
||||
*/
|
||||
private function applyJustifyBetween(array $elements): array
|
||||
{
|
||||
[$totalWidth, $parentWidth] = $this->getWidthFromElements($elements);
|
||||
$space = ($parentWidth - $totalWidth) / (count($elements) - 1);
|
||||
|
||||
if ($space < 1) {
|
||||
return $elements;
|
||||
}
|
||||
|
||||
$arr = [];
|
||||
|
||||
foreach ($elements as $index => &$element) {
|
||||
if ($index !== 0) {
|
||||
// Since there is no float pixel, on the last one it should round up...
|
||||
$length = $index === count($elements) - 1 ? ceil($space) : floor($space);
|
||||
$arr[] = str_repeat(' ', (int) $length);
|
||||
}
|
||||
|
||||
$arr[] = $element;
|
||||
}
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the space between and around the elements.
|
||||
*
|
||||
* @param array<int, Element> $elements
|
||||
* @return array<int, Element|string>
|
||||
*/
|
||||
private function applyJustifyEvenly(array $elements): array
|
||||
{
|
||||
[$totalWidth, $parentWidth] = $this->getWidthFromElements($elements);
|
||||
$space = ($parentWidth - $totalWidth) / (count($elements) + 1);
|
||||
|
||||
if ($space < 1) {
|
||||
return $elements;
|
||||
}
|
||||
|
||||
$arr = [];
|
||||
foreach ($elements as &$element) {
|
||||
$arr[] = str_repeat(' ', (int) floor($space));
|
||||
$arr[] = $element;
|
||||
}
|
||||
|
||||
$decimals = ceil(($space - floor($space)) * (count($elements) + 1));
|
||||
$arr[] = str_repeat(' ', (int) (floor($space) + $decimals));
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the space around the elements.
|
||||
*
|
||||
* @param array<int, Element> $elements
|
||||
* @return array<int, Element|string>
|
||||
*/
|
||||
private function applyJustifyAround(array $elements): array
|
||||
{
|
||||
[$totalWidth, $parentWidth] = $this->getWidthFromElements($elements);
|
||||
$space = ($parentWidth - $totalWidth) / count($elements);
|
||||
|
||||
if ($space < 1) {
|
||||
return $elements;
|
||||
}
|
||||
|
||||
$contentSize = $totalWidth;
|
||||
$arr = [];
|
||||
|
||||
foreach ($elements as $index => &$element) {
|
||||
if ($index !== 0) {
|
||||
$arr[] = str_repeat(' ', (int) ceil($space));
|
||||
$contentSize += ceil($space);
|
||||
}
|
||||
|
||||
$arr[] = $element;
|
||||
}
|
||||
|
||||
return [
|
||||
str_repeat(' ', (int) floor(($parentWidth - $contentSize) / 2)),
|
||||
...$arr,
|
||||
str_repeat(' ', (int) ceil(($parentWidth - $contentSize) / 2)),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the space on before first element and after last element.
|
||||
*
|
||||
* @param array<int, Element> $elements
|
||||
* @return array<int, Element|string>
|
||||
*/
|
||||
private function applyJustifyCenter(array $elements): array
|
||||
{
|
||||
[$totalWidth, $parentWidth] = $this->getWidthFromElements($elements);
|
||||
$space = $parentWidth - $totalWidth;
|
||||
|
||||
if ($space < 1) {
|
||||
return $elements;
|
||||
}
|
||||
|
||||
return [
|
||||
str_repeat(' ', (int) floor($space / 2)),
|
||||
...$elements,
|
||||
str_repeat(' ', (int) ceil($space / 2)),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the total width for the elements and their parent width.
|
||||
*
|
||||
* @param array<int, Element> $elements
|
||||
* @return int[]
|
||||
*/
|
||||
private function getWidthFromElements(array $elements)
|
||||
{
|
||||
$totalWidth = (int) array_reduce($elements, fn ($carry, $element) => $carry += $element->getLength(), 0);
|
||||
$parentWidth = Styles::getParentWidth($elements[0]->getProperties()['parentStyles'] ?? []);
|
||||
|
||||
return [$totalWidth, $parentWidth];
|
||||
}
|
||||
}
|
46
vendor/nunomaduro/termwind/src/Html/PreRenderer.php
vendored
Normal file
46
vendor/nunomaduro/termwind/src/Html/PreRenderer.php
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Termwind\Html;
|
||||
|
||||
use Termwind\Components\Element;
|
||||
use Termwind\Termwind;
|
||||
use Termwind\ValueObjects\Node;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class PreRenderer
|
||||
{
|
||||
/**
|
||||
* Gets HTML content from a given node and converts to the content element.
|
||||
*/
|
||||
public function toElement(Node $node): Element
|
||||
{
|
||||
$lines = explode("\n", $node->getHtml());
|
||||
if (reset($lines) === '') {
|
||||
array_shift($lines);
|
||||
}
|
||||
|
||||
if (end($lines) === '') {
|
||||
array_pop($lines);
|
||||
}
|
||||
|
||||
$maxStrLen = array_reduce(
|
||||
$lines,
|
||||
static fn (int $max, string $line) => ($max < strlen($line)) ? strlen($line) : $max,
|
||||
0
|
||||
);
|
||||
|
||||
$styles = $node->getClassAttribute();
|
||||
$html = array_map(
|
||||
static fn (string $line) => (string) Termwind::div(str_pad($line, $maxStrLen + 3), $styles),
|
||||
$lines
|
||||
);
|
||||
|
||||
return Termwind::raw(
|
||||
implode('', $html)
|
||||
);
|
||||
}
|
||||
}
|
251
vendor/nunomaduro/termwind/src/Html/TableRenderer.php
vendored
Normal file
251
vendor/nunomaduro/termwind/src/Html/TableRenderer.php
vendored
Normal file
@@ -0,0 +1,251 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Termwind\Html;
|
||||
|
||||
use Iterator;
|
||||
use Symfony\Component\Console\Helper\Table;
|
||||
use Symfony\Component\Console\Helper\TableCell;
|
||||
use Symfony\Component\Console\Helper\TableCellStyle;
|
||||
use Symfony\Component\Console\Helper\TableSeparator;
|
||||
use Symfony\Component\Console\Output\BufferedOutput;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Termwind\Components\Element;
|
||||
use Termwind\HtmlRenderer;
|
||||
use Termwind\Termwind;
|
||||
use Termwind\ValueObjects\Node;
|
||||
use Termwind\ValueObjects\Styles;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class TableRenderer
|
||||
{
|
||||
/**
|
||||
* Symfony table object uses for table generation.
|
||||
*/
|
||||
private Table $table;
|
||||
|
||||
/**
|
||||
* This object is used for accumulating output data from Symfony table object and return it as a string.
|
||||
*/
|
||||
private BufferedOutput $output;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->output = new BufferedOutput(
|
||||
// Content should output as is, without changes
|
||||
OutputInterface::VERBOSITY_NORMAL | OutputInterface::OUTPUT_RAW,
|
||||
true
|
||||
);
|
||||
|
||||
$this->table = new Table($this->output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts table output to the content element.
|
||||
*/
|
||||
public function toElement(Node $node): Element
|
||||
{
|
||||
$this->parseTable($node);
|
||||
$this->table->render();
|
||||
|
||||
$content = preg_replace('/\n$/', '', $this->output->fetch()) ?? '';
|
||||
|
||||
return Termwind::div($content, '', [
|
||||
'isFirstChild' => $node->isFirstChild(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks for thead, tfoot, tbody, tr elements in a given DOM and appends rows from them to the Symfony table object.
|
||||
*/
|
||||
private function parseTable(Node $node): void
|
||||
{
|
||||
$style = $node->getAttribute('style');
|
||||
if ($style !== '') {
|
||||
$this->table->setStyle($style);
|
||||
}
|
||||
|
||||
foreach ($node->getChildNodes() as $child) {
|
||||
match ($child->getName()) {
|
||||
'thead' => $this->parseHeader($child),
|
||||
'tfoot' => $this->parseFoot($child),
|
||||
'tbody' => $this->parseBody($child),
|
||||
default => $this->parseRows($child)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks for table header title and tr elements in a given thead DOM node and adds them to the Symfony table object.
|
||||
*/
|
||||
private function parseHeader(Node $node): void
|
||||
{
|
||||
$title = $node->getAttribute('title');
|
||||
|
||||
if ($title !== '') {
|
||||
$this->table->getStyle()->setHeaderTitleFormat(
|
||||
$this->parseTitleStyle($node)
|
||||
);
|
||||
$this->table->setHeaderTitle($title);
|
||||
}
|
||||
|
||||
foreach ($node->getChildNodes() as $child) {
|
||||
if ($child->isName('tr')) {
|
||||
foreach ($this->parseRow($child) as $row) {
|
||||
if (! is_array($row)) {
|
||||
continue;
|
||||
}
|
||||
$this->table->setHeaders($row);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks for table footer and tr elements in a given tfoot DOM node and adds them to the Symfony table object.
|
||||
*/
|
||||
private function parseFoot(Node $node): void
|
||||
{
|
||||
$title = $node->getAttribute('title');
|
||||
|
||||
if ($title !== '') {
|
||||
$this->table->getStyle()->setFooterTitleFormat(
|
||||
$this->parseTitleStyle($node)
|
||||
);
|
||||
$this->table->setFooterTitle($title);
|
||||
}
|
||||
|
||||
foreach ($node->getChildNodes() as $child) {
|
||||
if ($child->isName('tr')) {
|
||||
$rows = iterator_to_array($this->parseRow($child));
|
||||
if (count($rows) > 0) {
|
||||
$this->table->addRow(new TableSeparator());
|
||||
$this->table->addRows($rows);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks for tr elements in a given DOM node and adds them to the Symfony table object.
|
||||
*/
|
||||
private function parseBody(Node $node): void
|
||||
{
|
||||
foreach ($node->getChildNodes() as $child) {
|
||||
if ($child->isName('tr')) {
|
||||
$this->parseRows($child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses table tr elements.
|
||||
*/
|
||||
private function parseRows(Node $node): void
|
||||
{
|
||||
foreach ($this->parseRow($node) as $row) {
|
||||
$this->table->addRow($row);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks for th, td elements in a given DOM node and converts them to a table cells.
|
||||
*
|
||||
* @return Iterator<array<int, TableCell>|TableSeparator>
|
||||
*/
|
||||
private function parseRow(Node $node): Iterator
|
||||
{
|
||||
$row = [];
|
||||
|
||||
foreach ($node->getChildNodes() as $child) {
|
||||
if ($child->isName('th') || $child->isName('td')) {
|
||||
$align = $child->getAttribute('align');
|
||||
|
||||
$class = $child->getClassAttribute();
|
||||
|
||||
if ($child->isName('th')) {
|
||||
$class .= ' strong';
|
||||
}
|
||||
|
||||
$text = (string) (new HtmlRenderer)->parse(
|
||||
trim(preg_replace('/<br\s?+\/?>/', "\n", $child->getHtml()) ?? '')
|
||||
);
|
||||
|
||||
if ((bool) preg_match(Styles::STYLING_REGEX, $text)) {
|
||||
$class .= ' font-normal';
|
||||
}
|
||||
|
||||
$row[] = new TableCell(
|
||||
// I need only spaces after applying margin, padding and width except tags.
|
||||
// There is no place for tags, they broke cell formatting.
|
||||
(string) Termwind::span($text, $class),
|
||||
[
|
||||
// Gets rowspan and colspan from tr and td tag attributes
|
||||
'colspan' => max((int) $child->getAttribute('colspan'), 1),
|
||||
'rowspan' => max((int) $child->getAttribute('rowspan'), 1),
|
||||
|
||||
// There are background and foreground and options
|
||||
'style' => $this->parseCellStyle(
|
||||
$class,
|
||||
$align === '' ? TableCellStyle::DEFAULT_ALIGN : $align
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($row !== []) {
|
||||
yield $row;
|
||||
}
|
||||
|
||||
$border = (int) $node->getAttribute('border');
|
||||
for ($i = $border; $i--; $i > 0) {
|
||||
yield new TableSeparator();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses tr, td tag class attribute and passes bg, fg and options to a table cell style.
|
||||
*/
|
||||
private function parseCellStyle(string $styles, string $align = TableCellStyle::DEFAULT_ALIGN): TableCellStyle
|
||||
{
|
||||
// I use this empty span for getting styles for bg, fg and options
|
||||
// It will be a good idea to get properties without element object and then pass them to an element object
|
||||
$element = Termwind::span('%s', $styles);
|
||||
|
||||
$styles = [];
|
||||
|
||||
$colors = $element->getProperties()['colors'] ?? [];
|
||||
|
||||
foreach ($colors as $option => $content) {
|
||||
if (in_array($option, ['fg', 'bg'], true)) {
|
||||
$content = is_array($content) ? array_pop($content) : $content;
|
||||
|
||||
$styles[] = "$option=$content";
|
||||
}
|
||||
}
|
||||
|
||||
// If there are no styles we don't need extra tags
|
||||
if ($styles === []) {
|
||||
$cellFormat = '%s';
|
||||
} else {
|
||||
$cellFormat = '<'.implode(';', $styles).'>%s</>';
|
||||
}
|
||||
|
||||
return new TableCellStyle([
|
||||
'align' => $align,
|
||||
'cellFormat' => $cellFormat,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get styled representation of title.
|
||||
*/
|
||||
private function parseTitleStyle(Node $node): string
|
||||
{
|
||||
return (string) Termwind::span(' %s ', $node->getClassAttribute());
|
||||
}
|
||||
}
|
116
vendor/nunomaduro/termwind/src/HtmlRenderer.php
vendored
Normal file
116
vendor/nunomaduro/termwind/src/HtmlRenderer.php
vendored
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Termwind;
|
||||
|
||||
use DOMDocument;
|
||||
use DOMNode;
|
||||
use Termwind\Html\CodeRenderer;
|
||||
use Termwind\Html\PreRenderer;
|
||||
use Termwind\Html\TableRenderer;
|
||||
use Termwind\ValueObjects\Node;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class HtmlRenderer
|
||||
{
|
||||
/**
|
||||
* Renders the given html.
|
||||
*/
|
||||
public function render(string $html, int $options): void
|
||||
{
|
||||
$this->parse($html)->render($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the given html.
|
||||
*/
|
||||
public function parse(string $html): Components\Element
|
||||
{
|
||||
$dom = new DOMDocument();
|
||||
|
||||
if (strip_tags($html) === $html) {
|
||||
return Termwind::span($html);
|
||||
}
|
||||
|
||||
$html = '<?xml encoding="UTF-8">'.trim($html);
|
||||
$dom->loadHTML($html, LIBXML_NOERROR | LIBXML_COMPACT | LIBXML_HTML_NODEFDTD | LIBXML_NOBLANKS | LIBXML_NOXMLDECL);
|
||||
|
||||
/** @var DOMNode $body */
|
||||
$body = $dom->getElementsByTagName('body')->item(0);
|
||||
$el = $this->convert(new Node($body));
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
return is_string($el)
|
||||
? Termwind::span($el)
|
||||
: $el;
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a tree of DOM nodes to a tree of termwind elements.
|
||||
*/
|
||||
private function convert(Node $node): Components\Element|string
|
||||
{
|
||||
$children = [];
|
||||
|
||||
if ($node->isName('table')) {
|
||||
return (new TableRenderer)->toElement($node);
|
||||
} elseif ($node->isName('code')) {
|
||||
return (new CodeRenderer)->toElement($node);
|
||||
} elseif ($node->isName('pre')) {
|
||||
return (new PreRenderer)->toElement($node);
|
||||
}
|
||||
|
||||
foreach ($node->getChildNodes() as $child) {
|
||||
$children[] = $this->convert($child);
|
||||
}
|
||||
|
||||
$children = array_filter($children, fn ($child) => $child !== '');
|
||||
|
||||
return $this->toElement($node, $children);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a given DOM node to it's termwind element equivalent.
|
||||
*
|
||||
* @param array<int, Components\Element|string> $children
|
||||
*/
|
||||
private function toElement(Node $node, array $children): Components\Element|string
|
||||
{
|
||||
if ($node->isText() || $node->isComment()) {
|
||||
return (string) $node;
|
||||
}
|
||||
|
||||
/** @var array<string, mixed> $properties */
|
||||
$properties = [
|
||||
'isFirstChild' => $node->isFirstChild(),
|
||||
];
|
||||
|
||||
$styles = $node->getClassAttribute();
|
||||
|
||||
return match ($node->getName()) {
|
||||
'body' => $children[0], // Pick only the first element from the body node
|
||||
'div' => Termwind::div($children, $styles, $properties),
|
||||
'p' => Termwind::paragraph($children, $styles, $properties),
|
||||
'ul' => Termwind::ul($children, $styles, $properties),
|
||||
'ol' => Termwind::ol($children, $styles, $properties),
|
||||
'li' => Termwind::li($children, $styles, $properties),
|
||||
'dl' => Termwind::dl($children, $styles, $properties),
|
||||
'dt' => Termwind::dt($children, $styles, $properties),
|
||||
'dd' => Termwind::dd($children, $styles, $properties),
|
||||
'span' => Termwind::span($children, $styles, $properties),
|
||||
'br' => Termwind::breakLine($styles, $properties),
|
||||
'strong' => Termwind::span($children, $styles, $properties)->strong(),
|
||||
'b' => Termwind::span($children, $styles, $properties)->fontBold(),
|
||||
'em', 'i' => Termwind::span($children, $styles, $properties)->italic(),
|
||||
'u' => Termwind::span($children, $styles, $properties)->underline(),
|
||||
's' => Termwind::span($children, $styles, $properties)->lineThrough(),
|
||||
'a' => Termwind::anchor($children, $styles, $properties)->href($node->getAttribute('href')),
|
||||
'hr' => Termwind::hr($styles, $properties),
|
||||
default => Termwind::div($children, $styles, $properties),
|
||||
};
|
||||
}
|
||||
}
|
22
vendor/nunomaduro/termwind/src/Laravel/TermwindServiceProvider.php
vendored
Normal file
22
vendor/nunomaduro/termwind/src/Laravel/TermwindServiceProvider.php
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Termwind\Laravel;
|
||||
|
||||
use Illuminate\Console\OutputStyle;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Termwind\Termwind;
|
||||
|
||||
final class TermwindServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Sets the correct renderer to be used.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
$this->app->resolving(OutputStyle::class, function ($style): void {
|
||||
Termwind::renderUsing($style->getOutput());
|
||||
});
|
||||
}
|
||||
}
|
93
vendor/nunomaduro/termwind/src/Question.php
vendored
Normal file
93
vendor/nunomaduro/termwind/src/Question.php
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Termwind;
|
||||
|
||||
use ReflectionClass;
|
||||
use Symfony\Component\Console\Helper\SymfonyQuestionHelper;
|
||||
use Symfony\Component\Console\Input\ArgvInput;
|
||||
use Symfony\Component\Console\Input\StreamableInputInterface;
|
||||
use Symfony\Component\Console\Question\Question as SymfonyQuestion;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Termwind\Helpers\QuestionHelper;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class Question
|
||||
{
|
||||
/**
|
||||
* The streamable input to receive the input from the user.
|
||||
*/
|
||||
private static StreamableInputInterface|null $streamableInput;
|
||||
|
||||
/**
|
||||
* An instance of Symfony's question helper.
|
||||
*/
|
||||
private SymfonyQuestionHelper $helper;
|
||||
|
||||
public function __construct(SymfonyQuestionHelper $helper = null)
|
||||
{
|
||||
$this->helper = $helper ?? new QuestionHelper();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the streamable input implementation.
|
||||
*/
|
||||
public static function setStreamableInput(StreamableInputInterface|null $streamableInput): void
|
||||
{
|
||||
self::$streamableInput = $streamableInput ?? new ArgvInput();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the streamable input implementation.
|
||||
*/
|
||||
public static function getStreamableInput(): StreamableInputInterface
|
||||
{
|
||||
return self::$streamableInput ??= new ArgvInput();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a prompt to the user.
|
||||
*
|
||||
* @param iterable<array-key, string>|null $autocomplete
|
||||
*/
|
||||
public function ask(string $question, iterable $autocomplete = null): mixed
|
||||
{
|
||||
$html = (new HtmlRenderer)->parse($question)->toString();
|
||||
|
||||
$question = new SymfonyQuestion($html);
|
||||
|
||||
if ($autocomplete !== null) {
|
||||
$question->setAutocompleterValues($autocomplete);
|
||||
}
|
||||
|
||||
$output = Termwind::getRenderer();
|
||||
|
||||
if ($output instanceof SymfonyStyle) {
|
||||
$property = (new ReflectionClass(SymfonyStyle::class))
|
||||
->getProperty('questionHelper');
|
||||
|
||||
$property->setAccessible(true);
|
||||
|
||||
$currentHelper = $property->isInitialized($output)
|
||||
? $property->getValue($output)
|
||||
: new SymfonyQuestionHelper();
|
||||
|
||||
$property->setValue($output, new QuestionHelper);
|
||||
|
||||
try {
|
||||
return $output->askQuestion($question);
|
||||
} finally {
|
||||
$property->setValue($output, $currentHelper);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->helper->ask(
|
||||
self::getStreamableInput(),
|
||||
Termwind::getRenderer(),
|
||||
$question,
|
||||
);
|
||||
}
|
||||
}
|
59
vendor/nunomaduro/termwind/src/Repositories/Styles.php
vendored
Normal file
59
vendor/nunomaduro/termwind/src/Repositories/Styles.php
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Termwind\Repositories;
|
||||
|
||||
use Closure;
|
||||
use Termwind\ValueObjects\Style;
|
||||
use Termwind\ValueObjects\Styles as StylesValueObject;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class Styles
|
||||
{
|
||||
/**
|
||||
* @var array<string, Style>
|
||||
*/
|
||||
private static array $storage = [];
|
||||
|
||||
/**
|
||||
* Creates a new style from the given arguments.
|
||||
*
|
||||
* @param (Closure(StylesValueObject $element, string|int ...$arguments): StylesValueObject)|null $callback
|
||||
* @return Style
|
||||
*/
|
||||
public static function create(string $name, Closure $callback = null): Style
|
||||
{
|
||||
self::$storage[$name] = $style = new Style(
|
||||
$callback ?? static fn (StylesValueObject $styles) => $styles
|
||||
);
|
||||
|
||||
return $style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all existing styles.
|
||||
*/
|
||||
public static function flush(): void
|
||||
{
|
||||
self::$storage = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks a style with the given name exists.
|
||||
*/
|
||||
public static function has(string $name): bool
|
||||
{
|
||||
return array_key_exists($name, self::$storage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the style with the given name.
|
||||
*/
|
||||
public static function get(string $name): Style
|
||||
{
|
||||
return self::$storage[$name];
|
||||
}
|
||||
}
|
50
vendor/nunomaduro/termwind/src/Terminal.php
vendored
Normal file
50
vendor/nunomaduro/termwind/src/Terminal.php
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Termwind;
|
||||
|
||||
use Symfony\Component\Console\Terminal as ConsoleTerminal;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class Terminal
|
||||
{
|
||||
/**
|
||||
* An instance of Symfony's console terminal.
|
||||
*/
|
||||
private ConsoleTerminal $terminal;
|
||||
|
||||
/**
|
||||
* Creates a new terminal instance.
|
||||
*/
|
||||
public function __construct(ConsoleTerminal $terminal = null)
|
||||
{
|
||||
$this->terminal = $terminal ?? new ConsoleTerminal();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the terminal width.
|
||||
*/
|
||||
public function width(): int
|
||||
{
|
||||
return $this->terminal->getWidth();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the terminal height.
|
||||
*/
|
||||
public function height(): int
|
||||
{
|
||||
return $this->terminal->getHeight();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the terminal screen.
|
||||
*/
|
||||
public function clear(): void
|
||||
{
|
||||
Termwind::getRenderer()->write("\ec");
|
||||
}
|
||||
}
|
300
vendor/nunomaduro/termwind/src/Termwind.php
vendored
Normal file
300
vendor/nunomaduro/termwind/src/Termwind.php
vendored
Normal file
@@ -0,0 +1,300 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Termwind;
|
||||
|
||||
use Closure;
|
||||
use Symfony\Component\Console\Output\ConsoleOutput;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Termwind\Components\Element;
|
||||
use Termwind\Exceptions\InvalidChild;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class Termwind
|
||||
{
|
||||
/**
|
||||
* The implementation of the output.
|
||||
*/
|
||||
private static OutputInterface|null $renderer;
|
||||
|
||||
/**
|
||||
* Sets the renderer implementation.
|
||||
*/
|
||||
public static function renderUsing(OutputInterface|null $renderer): void
|
||||
{
|
||||
self::$renderer = $renderer ?? new ConsoleOutput();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a div element instance.
|
||||
*
|
||||
* @param array<int, Element|string>|string $content
|
||||
* @param array<string, mixed> $properties
|
||||
*/
|
||||
public static function div(array|string $content = '', string $styles = '', array $properties = []): Components\Div
|
||||
{
|
||||
$content = self::prepareElements($content, $styles);
|
||||
|
||||
return Components\Div::fromStyles(
|
||||
self::getRenderer(), $content, $styles, $properties
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a paragraph element instance.
|
||||
*
|
||||
* @param array<int, Element|string>|string $content
|
||||
* @param array<string, mixed> $properties
|
||||
*/
|
||||
public static function paragraph(array|string $content = '', string $styles = '', array $properties = []): Components\Paragraph
|
||||
{
|
||||
$content = self::prepareElements($content, $styles);
|
||||
|
||||
return Components\Paragraph::fromStyles(
|
||||
self::getRenderer(), $content, $styles, $properties
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a span element instance with the given style.
|
||||
*
|
||||
* @param array<int, Element|string>|string $content
|
||||
* @param array<string, mixed> $properties
|
||||
*/
|
||||
public static function span(array|string $content = '', string $styles = '', array $properties = []): Components\Span
|
||||
{
|
||||
$content = self::prepareElements($content, $styles);
|
||||
|
||||
return Components\Span::fromStyles(
|
||||
self::getRenderer(), $content, $styles, $properties
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an element instance with raw content.
|
||||
*
|
||||
* @param array<int, Element|string>|string $content
|
||||
*/
|
||||
public static function raw(array|string $content = ''): Components\Raw
|
||||
{
|
||||
return Components\Raw::fromStyles(
|
||||
self::getRenderer(), $content
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an anchor element instance with the given style.
|
||||
*
|
||||
* @param array<int, Element|string>|string $content
|
||||
* @param array<string, mixed> $properties
|
||||
*/
|
||||
public static function anchor(array|string $content = '', string $styles = '', array $properties = []): Components\Anchor
|
||||
{
|
||||
$content = self::prepareElements($content, $styles);
|
||||
|
||||
return Components\Anchor::fromStyles(
|
||||
self::getRenderer(), $content, $styles, $properties
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an unordered list instance.
|
||||
*
|
||||
* @param array<int, string|Element> $content
|
||||
* @param array<string, mixed> $properties
|
||||
*/
|
||||
public static function ul(array $content = [], string $styles = '', array $properties = []): Components\Ul
|
||||
{
|
||||
$ul = Components\Ul::fromStyles(
|
||||
self::getRenderer(), '', $styles, $properties
|
||||
);
|
||||
|
||||
$content = self::prepareElements(
|
||||
$content,
|
||||
$styles,
|
||||
static function ($li) use ($ul): string|Element {
|
||||
if (is_string($li)) {
|
||||
return $li;
|
||||
}
|
||||
|
||||
if (! $li instanceof Components\Li) {
|
||||
throw new InvalidChild('Unordered lists only accept `li` as child');
|
||||
}
|
||||
|
||||
return match (true) {
|
||||
$li->hasStyle('list-none') => $li,
|
||||
$ul->hasStyle('list-none') => $li->addStyle('list-none'),
|
||||
$ul->hasStyle('list-square') => $li->addStyle('list-square'),
|
||||
$ul->hasStyle('list-disc') => $li->addStyle('list-disc'),
|
||||
default => $li->addStyle('list-none'),
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
return $ul->setContent($content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an ordered list instance.
|
||||
*
|
||||
* @param array<int, string|Element> $content
|
||||
* @param array<string, mixed> $properties
|
||||
*/
|
||||
public static function ol(array $content = [], string $styles = '', array $properties = []): Components\Ol
|
||||
{
|
||||
$ol = Components\Ol::fromStyles(
|
||||
self::getRenderer(), '', $styles, $properties
|
||||
);
|
||||
|
||||
$index = 0;
|
||||
|
||||
$content = self::prepareElements(
|
||||
$content,
|
||||
$styles,
|
||||
static function ($li) use ($ol, &$index): string|Element {
|
||||
if (is_string($li)) {
|
||||
return $li;
|
||||
}
|
||||
|
||||
if (! $li instanceof Components\Li) {
|
||||
throw new InvalidChild('Ordered lists only accept `li` as child');
|
||||
}
|
||||
|
||||
return match (true) {
|
||||
$li->hasStyle('list-none') => $li->addStyle('list-none'),
|
||||
$ol->hasStyle('list-none') => $li->addStyle('list-none'),
|
||||
$ol->hasStyle('list-decimal') => $li->addStyle('list-decimal-'.(++$index)),
|
||||
default => $li->addStyle('list-none'),
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
return $ol->setContent($content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a list item instance.
|
||||
*
|
||||
* @param array<int, Element|string>|string $content
|
||||
* @param array<string, mixed> $properties
|
||||
*/
|
||||
public static function li(array|string $content = '', string $styles = '', array $properties = []): Components\Li
|
||||
{
|
||||
$content = self::prepareElements($content, $styles);
|
||||
|
||||
return Components\Li::fromStyles(
|
||||
self::getRenderer(), $content, $styles, $properties
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a description list instance.
|
||||
*
|
||||
* @param array<int, string|Element> $content
|
||||
* @param array<string, mixed> $properties
|
||||
*/
|
||||
public static function dl(array $content = [], string $styles = '', array $properties = []): Components\Dl
|
||||
{
|
||||
$content = self::prepareElements(
|
||||
$content,
|
||||
$styles,
|
||||
static function ($element): string|Element {
|
||||
if (is_string($element)) {
|
||||
return $element;
|
||||
}
|
||||
|
||||
if (! $element instanceof Components\Dt && ! $element instanceof Components\Dd) {
|
||||
throw new InvalidChild('Description lists only accept `dt` and `dd` as children');
|
||||
}
|
||||
|
||||
return $element;
|
||||
}
|
||||
);
|
||||
|
||||
return Components\Dl::fromStyles(
|
||||
self::getRenderer(), $content, $styles, $properties
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a description term instance.
|
||||
*
|
||||
* @param array<int, Element|string>|string $content
|
||||
* @param array<string, mixed> $properties
|
||||
*/
|
||||
public static function dt(array|string $content = '', string $styles = '', array $properties = []): Components\Dt
|
||||
{
|
||||
$content = self::prepareElements($content, $styles);
|
||||
|
||||
return Components\Dt::fromStyles(
|
||||
self::getRenderer(), $content, $styles, $properties
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a description details instance.
|
||||
*
|
||||
* @param array<int, Element|string>|string $content
|
||||
* @param array<string, mixed> $properties
|
||||
*/
|
||||
public static function dd(array|string $content = '', string $styles = '', array $properties = []): Components\Dd
|
||||
{
|
||||
$content = self::prepareElements($content, $styles);
|
||||
|
||||
return Components\Dd::fromStyles(
|
||||
self::getRenderer(), $content, $styles, $properties
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a horizontal rule instance.
|
||||
*
|
||||
* @param array<string, mixed> $properties
|
||||
*/
|
||||
public static function hr(string $styles = '', array $properties = []): Components\Hr
|
||||
{
|
||||
return Components\Hr::fromStyles(
|
||||
self::getRenderer(), '', $styles, $properties
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an break line element instance.
|
||||
*
|
||||
* @param array<string, mixed> $properties
|
||||
*/
|
||||
public static function breakLine(string $styles = '', array $properties = []): Components\BreakLine
|
||||
{
|
||||
return Components\BreakLine::fromStyles(
|
||||
self::getRenderer(), '', $styles, $properties
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current renderer instance.
|
||||
*/
|
||||
public static function getRenderer(): OutputInterface
|
||||
{
|
||||
return self::$renderer ??= new ConsoleOutput();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert child elements to a string.
|
||||
*
|
||||
* @param array<int, string|Element>|string $elements
|
||||
* @return array<int, string|Element>
|
||||
*/
|
||||
private static function prepareElements($elements, string $styles = '', Closure|null $callback = null): array
|
||||
{
|
||||
if ($callback === null) {
|
||||
$callback = static fn ($element): string|Element => $element;
|
||||
}
|
||||
|
||||
$elements = is_array($elements) ? $elements : [$elements];
|
||||
|
||||
return array_map($callback, $elements);
|
||||
}
|
||||
}
|
205
vendor/nunomaduro/termwind/src/ValueObjects/Node.php
vendored
Normal file
205
vendor/nunomaduro/termwind/src/ValueObjects/Node.php
vendored
Normal file
@@ -0,0 +1,205 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Termwind\ValueObjects;
|
||||
|
||||
use Generator;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class Node
|
||||
{
|
||||
/**
|
||||
* A value object with helper methods for working with DOM node.
|
||||
*/
|
||||
public function __construct(private \DOMNode $node)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the node.
|
||||
*/
|
||||
public function getValue(): string
|
||||
{
|
||||
return $this->node->nodeValue ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets child nodes of the node.
|
||||
*
|
||||
* @return Generator<Node>
|
||||
*/
|
||||
public function getChildNodes(): Generator
|
||||
{
|
||||
foreach ($this->node->childNodes as $node) {
|
||||
yield new static($node);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the node is a text.
|
||||
*/
|
||||
public function isText(): bool
|
||||
{
|
||||
return $this->node instanceof \DOMText;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the node is a comment.
|
||||
*/
|
||||
public function isComment(): bool
|
||||
{
|
||||
return $this->node instanceof \DOMComment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares the current node name with a given name.
|
||||
*/
|
||||
public function isName(string $name): bool
|
||||
{
|
||||
return $this->getName() === $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current node type name.
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->node->nodeName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns value of [class] attribute.
|
||||
*/
|
||||
public function getClassAttribute(): string
|
||||
{
|
||||
return $this->getAttribute('class');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns value of attribute with a given name.
|
||||
*/
|
||||
public function getAttribute(string $name): string
|
||||
{
|
||||
if ($this->node instanceof \DOMElement) {
|
||||
return $this->node->getAttribute($name);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the node is empty.
|
||||
*/
|
||||
public function isEmpty(): bool
|
||||
{
|
||||
return $this->isText() && preg_replace('/\s+/', '', $this->getValue()) === '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the previous sibling from the node.
|
||||
*/
|
||||
public function getPreviousSibling(): static|null
|
||||
{
|
||||
$node = $this->node;
|
||||
|
||||
while ($node = $node->previousSibling) {
|
||||
$node = new static($node);
|
||||
|
||||
if ($node->isEmpty()) {
|
||||
$node = $node->node;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! $node->isComment()) {
|
||||
return $node;
|
||||
}
|
||||
|
||||
$node = $node->node;
|
||||
}
|
||||
|
||||
return is_null($node) ? null : new static($node);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the next sibling from the node.
|
||||
*/
|
||||
public function getNextSibling(): static|null
|
||||
{
|
||||
$node = $this->node;
|
||||
|
||||
while ($node = $node->nextSibling) {
|
||||
$node = new static($node);
|
||||
|
||||
if ($node->isEmpty()) {
|
||||
$node = $node->node;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! $node->isComment()) {
|
||||
return $node;
|
||||
}
|
||||
|
||||
$node = $node->node;
|
||||
}
|
||||
|
||||
return is_null($node) ? null : new static($node);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the node is the first child.
|
||||
*/
|
||||
public function isFirstChild(): bool
|
||||
{
|
||||
return is_null($this->getPreviousSibling());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the inner HTML representation of the node including child nodes.
|
||||
*/
|
||||
public function getHtml(): string
|
||||
{
|
||||
$html = '';
|
||||
foreach ($this->node->childNodes as $child) {
|
||||
if ($child->ownerDocument instanceof \DOMDocument) {
|
||||
$html .= $child->ownerDocument->saveXML($child);
|
||||
}
|
||||
}
|
||||
|
||||
return html_entity_decode($html);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the node to a string.
|
||||
*/
|
||||
public function __toString(): string
|
||||
{
|
||||
if ($this->isComment()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ($this->getValue() === ' ') {
|
||||
return ' ';
|
||||
}
|
||||
|
||||
if ($this->isEmpty()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$text = preg_replace('/\s+/', ' ', $this->getValue()) ?? '';
|
||||
|
||||
if (is_null($this->getPreviousSibling())) {
|
||||
$text = ltrim($text);
|
||||
}
|
||||
|
||||
if (is_null($this->getNextSibling())) {
|
||||
$text = rtrim($text);
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
}
|
70
vendor/nunomaduro/termwind/src/ValueObjects/Style.php
vendored
Normal file
70
vendor/nunomaduro/termwind/src/ValueObjects/Style.php
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Termwind\ValueObjects;
|
||||
|
||||
use Closure;
|
||||
use Termwind\Actions\StyleToMethod;
|
||||
use Termwind\Exceptions\InvalidColor;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class Style
|
||||
{
|
||||
/**
|
||||
* Creates a new value object instance.
|
||||
*
|
||||
* @param Closure(Styles $styles, string|int ...$argument): Styles $callback
|
||||
*/
|
||||
public function __construct(private Closure $callback, private string $color = '')
|
||||
{
|
||||
// ..
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the given set of styles to the styles.
|
||||
*/
|
||||
public function apply(string $styles): void
|
||||
{
|
||||
$callback = clone $this->callback;
|
||||
|
||||
$this->callback = static function (
|
||||
Styles $formatter,
|
||||
string|int ...$arguments
|
||||
) use ($callback, $styles): Styles {
|
||||
$formatter = $callback($formatter, ...$arguments);
|
||||
|
||||
return StyleToMethod::multiple($formatter, $styles);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the color to the style.
|
||||
*/
|
||||
public function color(string $color): void
|
||||
{
|
||||
if (preg_match('/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/', $color) < 1) {
|
||||
throw new InvalidColor(sprintf('The color %s is invalid.', $color));
|
||||
}
|
||||
|
||||
$this->color = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the color.
|
||||
*/
|
||||
public function getColor(): string
|
||||
{
|
||||
return $this->color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Styles the given formatter with this style.
|
||||
*/
|
||||
public function __invoke(Styles $styles, string|int ...$arguments): Styles
|
||||
{
|
||||
return ($this->callback)($styles, ...$arguments);
|
||||
}
|
||||
}
|
1061
vendor/nunomaduro/termwind/src/ValueObjects/Styles.php
vendored
Normal file
1061
vendor/nunomaduro/termwind/src/ValueObjects/Styles.php
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user