🆙 Add cms i using 🆙

This commit is contained in:
Remco
2025-11-25 22:42:56 +01:00
parent 94704e0925
commit d44196149e
35591 changed files with 3601123 additions and 0 deletions
@@ -0,0 +1 @@
.gitkeep
@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) Nuno Maduro <enunomaduro@email.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.
@@ -0,0 +1,60 @@
{
"name": "pestphp/pest-plugin",
"description": "The Pest plugin manager",
"keywords": [
"php",
"framework",
"pest",
"unit",
"test",
"testing",
"plugin",
"manager"
],
"license": "MIT",
"type": "composer-plugin",
"require": {
"php": "^8.3",
"composer-plugin-api": "^2.0.0",
"composer-runtime-api": "^2.2.2"
},
"conflict": {
"pestphp/pest": "<4.0.0"
},
"autoload": {
"psr-4": {
"Pest\\Plugin\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/",
"Pest\\Plugins\\": "tests/Stubs/PestPlugins"
}
},
"require-dev": {
"composer/composer": "^2.8.10",
"pestphp/pest-dev-tools": "^4.0.0",
"pestphp/pest": "^4.0.0"
},
"minimum-stability": "dev",
"prefer-stable": true,
"extra": {
"class": "Pest\\Plugin\\Manager"
},
"config": {
"sort-packages": true,
"preferred-install": "dist"
},
"scripts": {
"lint": "pint",
"test:lint": "pint --test",
"test:types": "phpstan analyse --ansi",
"test:unit": "pest --colors=always",
"test": [
"@test:lint",
"@test:types",
"@test:unit"
]
}
}
@@ -0,0 +1,52 @@
<?php
declare(strict_types=1);
namespace Pest\Plugin\Commands;
use Composer\Command\BaseCommand;
use Pest\Plugin\Manager;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* @internal
*/
final class DumpCommand extends BaseCommand
{
protected function configure(): void
{
$this->setName('pest:dump-plugins')
->setDescription('Dump all installed Pest plugins to the plugin cache.');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$composer = $this->getComposer();
if ($composer === null) {
throw new \RuntimeException('Could not get Composer\Composer instance.');
}
$vendorDirectory = $composer->getConfig()->get('vendor-dir');
$plugins = [];
$packages = $composer->getRepositoryManager()->getLocalRepository()->getCanonicalPackages();
$packages[] = $composer->getPackage();
/** @var \Composer\Package\PackageInterface $package */
foreach ($packages as $package) {
$extra = $package->getExtra();
// @phpstan-ignore-next-line
$plugins = array_merge($plugins, $extra['pest']['plugins'] ?? []);
}
file_put_contents(
implode(DIRECTORY_SEPARATOR, [$vendorDirectory, Manager::PLUGIN_CACHE_FILE]),
json_encode($plugins, JSON_PRETTY_PRINT)
);
return 0;
}
}
@@ -0,0 +1,110 @@
<?php
declare(strict_types=1);
namespace Pest\Plugin;
use JsonException;
use Pest\Support\Container;
/**
* @internal
*/
final class Loader
{
/**
* Determines if the plugin cache file was loaded.
*
* @var bool
*/
private static $loaded = false;
/**
* Holds the list of cached plugin instances.
*
* @var array<int, object>
*/
private static $instances = [];
/**
* returns an array of pest plugins to execute.
*
* @param string $interface the interface for the hook to execute
* @return array<int, object> list of plugins
*/
public static function getPlugins(string $interface): array
{
return array_values(
array_filter(
self::getPluginInstances(),
function ($plugin) use ($interface): bool {
return $plugin instanceof $interface;
}
)
);
}
public static function reset(): void
{
self::$loaded = false;
self::$instances = [];
}
/**
* returns the list of plugins instances.
*
* @return array<int, object>
*/
private static function getPluginInstances(): array
{
if (! self::$loaded) {
$cachedPlugins = sprintf(
'%s/../pest-plugins.json',
// @phpstan-ignore-next-line
$GLOBALS['_composer_bin_dir'] ?? getcwd().'/vendor/bin',
);
$container = Container::getInstance();
if (! file_exists($cachedPlugins)) {
return [];
}
$content = file_get_contents($cachedPlugins);
if ($content === false) {
return [];
}
try {
/** @var array<int, class-string> $pluginClasses */
$pluginClasses = json_decode($content, false, 512, JSON_THROW_ON_ERROR);
} catch (JsonException $ex) {
$pluginClasses = [];
}
usort($pluginClasses, function (string $pluginA, string $pluginB) {
$isOfficialPlugin = fn (string $plugin) => str_starts_with($plugin, 'Pest\\Plugins\\');
return match (true) {
$isOfficialPlugin($pluginA) && $isOfficialPlugin($pluginB),
! $isOfficialPlugin($pluginA) && ! $isOfficialPlugin($pluginB) => 0,
$isOfficialPlugin($pluginA) => 1,
default => -1,
};
});
self::$instances = array_map(
function ($class) use ($container) {
/** @var object $object */
$object = $container->get($class);
return $object;
},
$pluginClasses,
);
self::$loaded = true;
}
return self::$instances;
}
}
@@ -0,0 +1,81 @@
<?php
declare(strict_types=1);
namespace Pest\Plugin;
use Composer\Composer;
use Composer\EventDispatcher\EventSubscriberInterface;
use Composer\IO\IOInterface;
use Composer\Plugin\Capable;
use Composer\Plugin\PluginInterface;
use Pest\Plugin\Commands\DumpCommand;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\ConsoleOutput;
/**
* @internal
*/
final class Manager implements Capable, EventSubscriberInterface, PluginInterface
{
/**
* Holds the pest plugins file.
*/
public const PLUGIN_CACHE_FILE = 'pest-plugins.json';
/**
* @var Composer
*/
private $composer;
/**
* {@inheritdoc}
*/
public function activate(Composer $composer, IOInterface $io): void
{
$this->composer = $composer;
}
/**
* {@inheritdoc}
*/
public function uninstall(Composer $composer, IOInterface $io): void
{
/** @var string $vendorDirectory */
$vendorDirectory = $composer->getConfig()->get('vendor-dir');
$pluginFile = sprintf('%s/%s', $vendorDirectory, self::PLUGIN_CACHE_FILE);
if (file_exists($pluginFile)) {
unlink($pluginFile);
}
}
/**
* {@inheritdoc}
*
* @return array<string, string>
*/
public static function getSubscribedEvents()
{
return [
'post-autoload-dump' => 'registerPlugins',
];
}
public function getCapabilities()
{
return [
\Composer\Plugin\Capability\CommandProvider::class => PestCommandProvider::class,
];
}
public function registerPlugins(): void
{
$cmd = new DumpCommand;
$cmd->setComposer($this->composer);
$cmd->run(new ArrayInput([]), new ConsoleOutput(ConsoleOutput::VERBOSITY_NORMAL, true));
}
/** {@inheritdoc} */
public function deactivate(Composer $composer, IOInterface $io): void {}
}
@@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
namespace Pest\Plugin;
use Composer\Plugin\Capability\CommandProvider as CommandProviderCapability;
use Pest\Plugin\Commands\DumpCommand;
/**
* @internal
*/
final class PestCommandProvider implements CommandProviderCapability
{
/**
* @return array<int, DumpCommand>
*/
public function getCommands(): array
{
return [
new DumpCommand,
];
}
}