Initial commit: WordPress wp-content (themes, plugins, languages)
- Theme: momentry (custom theme with REST API routes) - Plugins: code-snippets (contains all API proxies) - Languages: zh_TW translations - Excludes: cache, backups, uploads, logs
This commit is contained in:
40
plugins/code-snippets/vendor/typisttech/imposter-plugin/src/AutoloadMerger.php
vendored
Normal file
40
plugins/code-snippets/vendor/typisttech/imposter-plugin/src/AutoloadMerger.php
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace TypistTech\Imposter\Plugin;
|
||||
|
||||
use Composer\Package\RootPackageInterface;
|
||||
use RuntimeException;
|
||||
use TypistTech\Imposter\ImposterFactory;
|
||||
|
||||
class AutoloadMerger
|
||||
{
|
||||
public static function run(RootPackageInterface $package): void
|
||||
{
|
||||
$autoload = $package->getAutoload();
|
||||
$autoload = array_merge_recursive($autoload, [
|
||||
'classmap' => static::getImposterAutoloads(),
|
||||
]);
|
||||
|
||||
$package->setAutoload($autoload);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
* @todo [Help Wanted] Think of a better way to handle file not found during installation
|
||||
*/
|
||||
protected static function getImposterAutoloads(): array
|
||||
{
|
||||
try {
|
||||
$cwd = getcwd();
|
||||
$imposter = ImposterFactory::forProject($cwd, ['typisttech/imposter-plugin']);
|
||||
|
||||
return array_map(function ($path) use ($cwd): string {
|
||||
return str_replace($cwd . '/', '', $path);
|
||||
}, $imposter->getAutoloads());
|
||||
} catch (RuntimeException $exception) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
70
plugins/code-snippets/vendor/typisttech/imposter-plugin/src/ImposterPlugin.php
vendored
Normal file
70
plugins/code-snippets/vendor/typisttech/imposter-plugin/src/ImposterPlugin.php
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace TypistTech\Imposter\Plugin;
|
||||
|
||||
use Composer\Composer;
|
||||
use Composer\EventDispatcher\EventSubscriberInterface;
|
||||
use Composer\IO\IOInterface;
|
||||
use Composer\Package\CompletePackage;
|
||||
use Composer\Package\RootPackageInterface;
|
||||
use Composer\Plugin\PluginInterface;
|
||||
use Composer\Script\Event;
|
||||
use Composer\Script\ScriptEvents;
|
||||
|
||||
class ImposterPlugin implements PluginInterface, EventSubscriberInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function activate(Composer $composer, IOInterface $io)
|
||||
{
|
||||
$package = $composer->getPackage();
|
||||
if ($package instanceof RootPackageInterface) {
|
||||
AutoloadMerger::run($package);
|
||||
}
|
||||
|
||||
if ($package instanceof CompletePackage) {
|
||||
$scripts = array_merge_recursive([
|
||||
ScriptEvents::POST_INSTALL_CMD => [
|
||||
'@composer dump-autoload --optimize',
|
||||
],
|
||||
ScriptEvents::POST_UPDATE_CMD => [
|
||||
'@composer dump-autoload --optimize',
|
||||
],
|
||||
], $package->getScripts());
|
||||
|
||||
$package->setScripts($scripts);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return [
|
||||
ScriptEvents::PRE_AUTOLOAD_DUMP => [
|
||||
['transform', PHP_INT_MAX - 1000],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function transform(Event $event): void
|
||||
{
|
||||
Transformer::run(
|
||||
$event->getIO()
|
||||
);
|
||||
}
|
||||
|
||||
public function deactivate(Composer $composer, IOInterface $io)
|
||||
{
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
public function uninstall(Composer $composer, IOInterface $io)
|
||||
{
|
||||
// Do nothing.
|
||||
}
|
||||
}
|
||||
53
plugins/code-snippets/vendor/typisttech/imposter-plugin/src/Transformer.php
vendored
Normal file
53
plugins/code-snippets/vendor/typisttech/imposter-plugin/src/Transformer.php
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace TypistTech\Imposter\Plugin;
|
||||
|
||||
use Composer\IO\IOInterface;
|
||||
use TypistTech\Imposter\ImposterFactory;
|
||||
|
||||
class Transformer
|
||||
{
|
||||
public static function run(IOInterface $io): void
|
||||
{
|
||||
// Print an empty line to separate imposter outputs.
|
||||
$io->write('', true);
|
||||
$io->write('', true);
|
||||
$io->write('<info>Running Imposter...</info>', true);
|
||||
$io->write('<info>======================</info>', true);
|
||||
$io->write('Loading package information from <comment>' . getcwd() . '/composer.json</comment>', true);
|
||||
|
||||
$imposter = ImposterFactory::forProject(getcwd(), ['typisttech/imposter-plugin']);
|
||||
|
||||
$autoloads = $imposter->getAutoloads();
|
||||
$count = count($autoloads);
|
||||
$index = 1;
|
||||
foreach ($autoloads as $autoload) {
|
||||
$io->write(" - <comment>$index/$count</comment>: Transforming $autoload", true);
|
||||
$imposter->transform($autoload);
|
||||
$index++;
|
||||
}
|
||||
|
||||
$io->write('<info>Success: Imposter transformed vendor files.</info>', true);
|
||||
|
||||
$invalidAutoloads = $imposter->getInvalidAutoloads();
|
||||
if (! empty($invalidAutoloads)) {
|
||||
$invalidAutoloadsCount = count($invalidAutoloads);
|
||||
$io->writeError('', true);
|
||||
$io->writeError(
|
||||
// phpcs:ignore Generic.Files.LineLength.TooLong
|
||||
"<warning>Warning: Imposter failed to transformed $invalidAutoloadsCount of the autoload path(s).</warning>",
|
||||
true
|
||||
);
|
||||
|
||||
foreach ($invalidAutoloads as $invalidAutoload) {
|
||||
$io->writeError(" - $invalidAutoload", true);
|
||||
}
|
||||
}
|
||||
|
||||
// Print empty lines to separate imposter outputs.
|
||||
$io->write('', true);
|
||||
$io->write('', true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user