First commit
This commit is contained in:
commit
c6e2478c40
13918 changed files with 2303184 additions and 0 deletions
37
vendor/consolidation/annotated-command/src/Hooks/Dispatchers/CommandEventHookDispatcher.php
vendored
Normal file
37
vendor/consolidation/annotated-command/src/Hooks/Dispatchers/CommandEventHookDispatcher.php
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace Consolidation\AnnotatedCommand\Hooks\Dispatchers;
|
||||
|
||||
use Consolidation\AnnotatedCommand\Hooks\HookManager;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\ConsoleEvents;
|
||||
use Symfony\Component\Console\Event\ConsoleCommandEvent;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
|
||||
/**
|
||||
* Call hooks
|
||||
*/
|
||||
class CommandEventHookDispatcher extends HookDispatcher
|
||||
{
|
||||
/**
|
||||
* @param ConsoleCommandEvent $event
|
||||
*/
|
||||
public function callCommandEventHooks(ConsoleCommandEvent $event)
|
||||
{
|
||||
$hooks = [
|
||||
HookManager::PRE_COMMAND_EVENT,
|
||||
HookManager::COMMAND_EVENT,
|
||||
HookManager::POST_COMMAND_EVENT
|
||||
];
|
||||
$commandEventHooks = $this->getHooks($hooks);
|
||||
foreach ($commandEventHooks as $commandEvent) {
|
||||
if ($commandEvent instanceof EventDispatcherInterface) {
|
||||
$commandEvent->dispatch(ConsoleEvents::COMMAND, $event);
|
||||
}
|
||||
if (is_callable($commandEvent)) {
|
||||
$commandEvent($event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
47
vendor/consolidation/annotated-command/src/Hooks/Dispatchers/ExtracterHookDispatcher.php
vendored
Normal file
47
vendor/consolidation/annotated-command/src/Hooks/Dispatchers/ExtracterHookDispatcher.php
vendored
Normal file
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
namespace Consolidation\AnnotatedCommand\Hooks\Dispatchers;
|
||||
|
||||
use Consolidation\AnnotatedCommand\Hooks\ExtractOutputInterface;
|
||||
use Consolidation\AnnotatedCommand\Hooks\HookManager;
|
||||
use Consolidation\AnnotatedCommand\OutputDataInterface;
|
||||
|
||||
/**
|
||||
* Call hooks
|
||||
*/
|
||||
class ExtracterHookDispatcher extends HookDispatcher implements ExtractOutputInterface
|
||||
{
|
||||
/**
|
||||
* Convert the result object to printable output in
|
||||
* structured form.
|
||||
*/
|
||||
public function extractOutput($result)
|
||||
{
|
||||
if ($result instanceof OutputDataInterface) {
|
||||
return $result->getOutputData();
|
||||
}
|
||||
|
||||
$hooks = [
|
||||
HookManager::EXTRACT_OUTPUT,
|
||||
];
|
||||
$extractors = $this->getHooks($hooks);
|
||||
foreach ($extractors as $extractor) {
|
||||
$structuredOutput = $this->callExtractor($extractor, $result);
|
||||
if (isset($structuredOutput)) {
|
||||
return $structuredOutput;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function callExtractor($extractor, $result)
|
||||
{
|
||||
if ($extractor instanceof ExtractOutputInterface) {
|
||||
return $extractor->extractOutput($result);
|
||||
}
|
||||
if (is_callable($extractor)) {
|
||||
return $extractor($result);
|
||||
}
|
||||
}
|
||||
}
|
27
vendor/consolidation/annotated-command/src/Hooks/Dispatchers/HookDispatcher.php
vendored
Normal file
27
vendor/consolidation/annotated-command/src/Hooks/Dispatchers/HookDispatcher.php
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Consolidation\AnnotatedCommand\Hooks\Dispatchers;
|
||||
|
||||
use Consolidation\AnnotatedCommand\Hooks\HookManager;
|
||||
use Consolidation\AnnotatedCommand\AnnotationData;
|
||||
|
||||
/**
|
||||
* Call hooks
|
||||
*/
|
||||
class HookDispatcher
|
||||
{
|
||||
/** var HookManager */
|
||||
protected $hookManager;
|
||||
protected $names;
|
||||
|
||||
public function __construct(HookManager $hookManager, $names)
|
||||
{
|
||||
$this->hookManager = $hookManager;
|
||||
$this->names = $names;
|
||||
}
|
||||
|
||||
public function getHooks($hooks, $annotationData = null)
|
||||
{
|
||||
return $this->hookManager->getHooks($this->names, $hooks, $annotationData);
|
||||
}
|
||||
}
|
40
vendor/consolidation/annotated-command/src/Hooks/Dispatchers/InitializeHookDispatcher.php
vendored
Normal file
40
vendor/consolidation/annotated-command/src/Hooks/Dispatchers/InitializeHookDispatcher.php
vendored
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace Consolidation\AnnotatedCommand\Hooks\Dispatchers;
|
||||
|
||||
use Consolidation\AnnotatedCommand\Hooks\HookManager;
|
||||
use Consolidation\AnnotatedCommand\AnnotationData;
|
||||
use Consolidation\AnnotatedCommand\Hooks\InitializeHookInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
|
||||
/**
|
||||
* Call hooks
|
||||
*/
|
||||
class InitializeHookDispatcher extends HookDispatcher implements InitializeHookInterface
|
||||
{
|
||||
public function initialize(
|
||||
InputInterface $input,
|
||||
AnnotationData $annotationData
|
||||
) {
|
||||
$hooks = [
|
||||
HookManager::PRE_INITIALIZE,
|
||||
HookManager::INITIALIZE,
|
||||
HookManager::POST_INITIALIZE
|
||||
];
|
||||
$providers = $this->getHooks($hooks, $annotationData);
|
||||
foreach ($providers as $provider) {
|
||||
$this->callInitializeHook($provider, $input, $annotationData);
|
||||
}
|
||||
}
|
||||
|
||||
protected function callInitializeHook($provider, $input, AnnotationData $annotationData)
|
||||
{
|
||||
if ($provider instanceof InitializeHookInterface) {
|
||||
return $provider->initialize($input, $annotationData);
|
||||
}
|
||||
if (is_callable($provider)) {
|
||||
return $provider($input, $annotationData);
|
||||
}
|
||||
}
|
||||
}
|
41
vendor/consolidation/annotated-command/src/Hooks/Dispatchers/InteractHookDispatcher.php
vendored
Normal file
41
vendor/consolidation/annotated-command/src/Hooks/Dispatchers/InteractHookDispatcher.php
vendored
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace Consolidation\AnnotatedCommand\Hooks\Dispatchers;
|
||||
|
||||
use Consolidation\AnnotatedCommand\AnnotationData;
|
||||
use Consolidation\AnnotatedCommand\Hooks\HookManager;
|
||||
use Consolidation\AnnotatedCommand\Hooks\InteractorInterface;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
/**
|
||||
* Call hooks
|
||||
*/
|
||||
class InteractHookDispatcher extends HookDispatcher
|
||||
{
|
||||
public function interact(
|
||||
InputInterface $input,
|
||||
OutputInterface $output,
|
||||
AnnotationData $annotationData
|
||||
) {
|
||||
$hooks = [
|
||||
HookManager::PRE_INTERACT,
|
||||
HookManager::INTERACT,
|
||||
HookManager::POST_INTERACT
|
||||
];
|
||||
$interactors = $this->getHooks($hooks, $annotationData);
|
||||
foreach ($interactors as $interactor) {
|
||||
$this->callInteractor($interactor, $input, $output, $annotationData);
|
||||
}
|
||||
}
|
||||
|
||||
protected function callInteractor($interactor, $input, $output, AnnotationData $annotationData)
|
||||
{
|
||||
if ($interactor instanceof InteractorInterface) {
|
||||
return $interactor->interact($input, $output, $annotationData);
|
||||
}
|
||||
if (is_callable($interactor)) {
|
||||
return $interactor($input, $output, $annotationData);
|
||||
}
|
||||
}
|
||||
}
|
44
vendor/consolidation/annotated-command/src/Hooks/Dispatchers/OptionsHookDispatcher.php
vendored
Normal file
44
vendor/consolidation/annotated-command/src/Hooks/Dispatchers/OptionsHookDispatcher.php
vendored
Normal file
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace Consolidation\AnnotatedCommand\Hooks\Dispatchers;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Consolidation\AnnotatedCommand\AnnotatedCommand;
|
||||
use Consolidation\AnnotatedCommand\AnnotationData;
|
||||
use Consolidation\AnnotatedCommand\Hooks\HookManager;
|
||||
use Consolidation\AnnotatedCommand\Hooks\OptionHookInterface;
|
||||
|
||||
/**
|
||||
* Call hooks
|
||||
*/
|
||||
class OptionsHookDispatcher extends HookDispatcher implements OptionHookInterface
|
||||
{
|
||||
public function getOptions(
|
||||
Command $command,
|
||||
AnnotationData $annotationData
|
||||
) {
|
||||
$hooks = [
|
||||
HookManager::PRE_OPTION_HOOK,
|
||||
HookManager::OPTION_HOOK,
|
||||
HookManager::POST_OPTION_HOOK
|
||||
];
|
||||
$optionHooks = $this->getHooks($hooks, $annotationData);
|
||||
foreach ($optionHooks as $optionHook) {
|
||||
$this->callOptionHook($optionHook, $command, $annotationData);
|
||||
}
|
||||
$commandInfoList = $this->hookManager->getHookOptionsForCommand($command);
|
||||
if ($command instanceof AnnotatedCommand) {
|
||||
$command->optionsHookForHookAnnotations($commandInfoList);
|
||||
}
|
||||
}
|
||||
|
||||
protected function callOptionHook($optionHook, $command, AnnotationData $annotationData)
|
||||
{
|
||||
if ($optionHook instanceof OptionHookInterface) {
|
||||
return $optionHook->getOptions($command, $annotationData);
|
||||
}
|
||||
if (is_callable($optionHook)) {
|
||||
return $optionHook($command, $annotationData);
|
||||
}
|
||||
}
|
||||
}
|
53
vendor/consolidation/annotated-command/src/Hooks/Dispatchers/ProcessResultHookDispatcher.php
vendored
Normal file
53
vendor/consolidation/annotated-command/src/Hooks/Dispatchers/ProcessResultHookDispatcher.php
vendored
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
namespace Consolidation\AnnotatedCommand\Hooks\Dispatchers;
|
||||
|
||||
use Consolidation\AnnotatedCommand\AnnotationData;
|
||||
use Consolidation\AnnotatedCommand\CommandData;
|
||||
use Consolidation\AnnotatedCommand\Hooks\HookManager;
|
||||
use Consolidation\AnnotatedCommand\Hooks\ProcessResultInterface;
|
||||
|
||||
/**
|
||||
* Call hooks
|
||||
*/
|
||||
class ProcessResultHookDispatcher extends HookDispatcher implements ProcessResultInterface
|
||||
{
|
||||
/**
|
||||
* Process result and decide what to do with it.
|
||||
* Allow client to add transformation / interpretation
|
||||
* callbacks.
|
||||
*/
|
||||
public function process($result, CommandData $commandData)
|
||||
{
|
||||
$hooks = [
|
||||
HookManager::PRE_PROCESS_RESULT,
|
||||
HookManager::PROCESS_RESULT,
|
||||
HookManager::POST_PROCESS_RESULT,
|
||||
HookManager::PRE_ALTER_RESULT,
|
||||
HookManager::ALTER_RESULT,
|
||||
HookManager::POST_ALTER_RESULT,
|
||||
HookManager::POST_COMMAND_HOOK,
|
||||
];
|
||||
$processors = $this->getHooks($hooks, $commandData->annotationData());
|
||||
foreach ($processors as $processor) {
|
||||
$result = $this->callProcessor($processor, $result, $commandData);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function callProcessor($processor, $result, CommandData $commandData)
|
||||
{
|
||||
$processed = null;
|
||||
if ($processor instanceof ProcessResultInterface) {
|
||||
$processed = $processor->process($result, $commandData);
|
||||
}
|
||||
if (is_callable($processor)) {
|
||||
$processed = $processor($result, $commandData);
|
||||
}
|
||||
if (isset($processed)) {
|
||||
return $processed;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
66
vendor/consolidation/annotated-command/src/Hooks/Dispatchers/ReplaceCommandHookDispatcher.php
vendored
Normal file
66
vendor/consolidation/annotated-command/src/Hooks/Dispatchers/ReplaceCommandHookDispatcher.php
vendored
Normal file
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
namespace Consolidation\AnnotatedCommand\Hooks\Dispatchers;
|
||||
|
||||
use Consolidation\AnnotatedCommand\CommandData;
|
||||
use Consolidation\AnnotatedCommand\Hooks\HookManager;
|
||||
use Psr\Log\LoggerAwareInterface;
|
||||
use Psr\Log\LoggerAwareTrait;
|
||||
|
||||
/**
|
||||
* Call hooks.
|
||||
*/
|
||||
class ReplaceCommandHookDispatcher extends HookDispatcher implements LoggerAwareInterface
|
||||
{
|
||||
|
||||
use LoggerAwareTrait;
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function hasReplaceCommandHook()
|
||||
{
|
||||
return (bool) count($this->getReplaceCommandHooks());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \callable[]
|
||||
*/
|
||||
public function getReplaceCommandHooks()
|
||||
{
|
||||
$hooks = [
|
||||
HookManager::REPLACE_COMMAND_HOOK,
|
||||
];
|
||||
$replaceCommandHooks = $this->getHooks($hooks);
|
||||
|
||||
return $replaceCommandHooks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Consolidation\AnnotatedCommand\CommandData $commandData
|
||||
*
|
||||
* @return callable
|
||||
*/
|
||||
public function getReplacementCommand(CommandData $commandData)
|
||||
{
|
||||
$replaceCommandHooks = $this->getReplaceCommandHooks();
|
||||
|
||||
// We only take the first hook implementation of "replace-command" as the replacement. Commands shouldn't have
|
||||
// more than one replacement.
|
||||
$replacementCommand = reset($replaceCommandHooks);
|
||||
|
||||
if ($this->logger && count($replaceCommandHooks) > 1) {
|
||||
$command_name = $commandData->annotationData()->get('command', 'unknown');
|
||||
$message = "Multiple implementations of the \"replace - command\" hook exist for the \"$command_name\" command.\n";
|
||||
foreach ($replaceCommandHooks as $replaceCommandHook) {
|
||||
$class = get_class($replaceCommandHook[0]);
|
||||
$method = $replaceCommandHook[1];
|
||||
$hook_name = "$class->$method";
|
||||
$message .= " - $hook_name\n";
|
||||
}
|
||||
$this->logger->warning($message);
|
||||
}
|
||||
|
||||
return $replacementCommand;
|
||||
}
|
||||
}
|
51
vendor/consolidation/annotated-command/src/Hooks/Dispatchers/StatusDeterminerHookDispatcher.php
vendored
Normal file
51
vendor/consolidation/annotated-command/src/Hooks/Dispatchers/StatusDeterminerHookDispatcher.php
vendored
Normal file
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
namespace Consolidation\AnnotatedCommand\Hooks\Dispatchers;
|
||||
|
||||
use Consolidation\AnnotatedCommand\ExitCodeInterface;
|
||||
use Consolidation\AnnotatedCommand\Hooks\HookManager;
|
||||
use Consolidation\AnnotatedCommand\Hooks\StatusDeterminerInterface;
|
||||
|
||||
/**
|
||||
* Call hooks
|
||||
*/
|
||||
class StatusDeterminerHookDispatcher extends HookDispatcher implements StatusDeterminerInterface
|
||||
{
|
||||
/**
|
||||
* Call all status determiners, and see if any of them
|
||||
* know how to convert to a status code.
|
||||
*/
|
||||
public function determineStatusCode($result)
|
||||
{
|
||||
// If the result (post-processing) is an object that
|
||||
// implements ExitCodeInterface, then we will ask it
|
||||
// to give us the status code.
|
||||
if ($result instanceof ExitCodeInterface) {
|
||||
return $result->getExitCode();
|
||||
}
|
||||
|
||||
$hooks = [
|
||||
HookManager::STATUS_DETERMINER,
|
||||
];
|
||||
// If the result does not implement ExitCodeInterface,
|
||||
// then we'll see if there is a determiner that can
|
||||
// extract a status code from the result.
|
||||
$determiners = $this->getHooks($hooks);
|
||||
foreach ($determiners as $determiner) {
|
||||
$status = $this->callDeterminer($determiner, $result);
|
||||
if (isset($status)) {
|
||||
return $status;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function callDeterminer($determiner, $result)
|
||||
{
|
||||
if ($determiner instanceof StatusDeterminerInterface) {
|
||||
return $determiner->determineStatusCode($result);
|
||||
}
|
||||
if (is_callable($determiner)) {
|
||||
return $determiner($result);
|
||||
}
|
||||
}
|
||||
}
|
46
vendor/consolidation/annotated-command/src/Hooks/Dispatchers/ValidateHookDispatcher.php
vendored
Normal file
46
vendor/consolidation/annotated-command/src/Hooks/Dispatchers/ValidateHookDispatcher.php
vendored
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace Consolidation\AnnotatedCommand\Hooks\Dispatchers;
|
||||
|
||||
use Consolidation\AnnotatedCommand\AnnotationData;
|
||||
use Consolidation\AnnotatedCommand\CommandData;
|
||||
use Consolidation\AnnotatedCommand\CommandError;
|
||||
use Consolidation\AnnotatedCommand\Hooks\HookManager;
|
||||
use Consolidation\AnnotatedCommand\Hooks\ValidatorInterface;
|
||||
|
||||
/**
|
||||
* Call hooks
|
||||
*/
|
||||
class ValidateHookDispatcher extends HookDispatcher implements ValidatorInterface
|
||||
{
|
||||
public function validate(CommandData $commandData)
|
||||
{
|
||||
$hooks = [
|
||||
HookManager::PRE_ARGUMENT_VALIDATOR,
|
||||
HookManager::ARGUMENT_VALIDATOR,
|
||||
HookManager::POST_ARGUMENT_VALIDATOR,
|
||||
HookManager::PRE_COMMAND_HOOK,
|
||||
HookManager::COMMAND_HOOK,
|
||||
];
|
||||
$validators = $this->getHooks($hooks, $commandData->annotationData());
|
||||
foreach ($validators as $validator) {
|
||||
$validated = $this->callValidator($validator, $commandData);
|
||||
if ($validated === false) {
|
||||
return new CommandError();
|
||||
}
|
||||
if (is_object($validated)) {
|
||||
return $validated;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function callValidator($validator, CommandData $commandData)
|
||||
{
|
||||
if ($validator instanceof ValidatorInterface) {
|
||||
return $validator->validate($commandData);
|
||||
}
|
||||
if (is_callable($validator)) {
|
||||
return $validator($commandData);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue