2020-08-03 21:31:32 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Phabel;
|
|
|
|
|
2020-08-09 16:23:01 +02:00
|
|
|
use Phabel\PluginGraph\PackageContext;
|
|
|
|
|
2020-08-13 18:30:12 +02:00
|
|
|
/**
|
2020-09-05 20:52:54 +02:00
|
|
|
* Plugin interface
|
|
|
|
*
|
2020-08-13 18:30:12 +02:00
|
|
|
* @author Daniil Gentili <daniil@daniil.it>
|
|
|
|
*/
|
2020-08-03 21:31:32 +02:00
|
|
|
interface PluginInterface
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Specify which plugins does this plugin require.
|
|
|
|
*
|
|
|
|
* At each level, the traverser will execute the enter and leave methods of the specified plugins, completing a full AST traversal before starting a new AST traversal for the current plugin.
|
|
|
|
* Of course, this increases complexity as it forces an additional traversal of the AST.
|
|
|
|
*
|
|
|
|
* When possible, use the extends method to reduce complexity.
|
|
|
|
*
|
2020-08-05 14:52:49 +02:00
|
|
|
* @return array Plugin name(s)
|
2020-08-03 21:31:32 +02:00
|
|
|
*
|
2020-08-05 14:52:49 +02:00
|
|
|
* @psalm-return class-string<PluginInterface>[]|array<class-string<PluginInterface>, array>
|
2020-08-03 21:31:32 +02:00
|
|
|
*/
|
2020-08-09 13:49:19 +02:00
|
|
|
public static function runAfter(): array;
|
|
|
|
/**
|
|
|
|
* Specify which plugins should run before this plugin.
|
|
|
|
*
|
|
|
|
* @return array Plugin name(s)
|
|
|
|
*
|
|
|
|
* @psalm-return class-string<PluginInterface>[]|array<class-string<PluginInterface>, array>
|
|
|
|
*/
|
|
|
|
public static function runBefore(): array;
|
2020-08-03 21:31:32 +02:00
|
|
|
/**
|
2020-08-05 14:52:49 +02:00
|
|
|
* Specify which plugins does this plugin extend.
|
2020-08-03 21:31:32 +02:00
|
|
|
*
|
|
|
|
* At each depth level, the traverser will first execute the enter|leave methods of the specified plugins, then immediately execute the enter|leave methods of the current plugin.
|
|
|
|
*
|
|
|
|
* This is preferred, and allows only a single traversal of the AST.
|
|
|
|
*
|
2020-08-05 14:52:49 +02:00
|
|
|
* @return array Plugin name(s)
|
2020-08-03 21:31:32 +02:00
|
|
|
*
|
2020-08-05 14:52:49 +02:00
|
|
|
* @psalm-return class-string<PluginInterface>[]|array<class-string<PluginInterface>, array>
|
2020-08-03 21:31:32 +02:00
|
|
|
*/
|
2020-08-09 13:49:19 +02:00
|
|
|
public static function runWithBefore(): array;
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @return array Plugin name(s)
|
|
|
|
*
|
|
|
|
* @psalm-return class-string<PluginInterface>[]|array<class-string<PluginInterface>, array>
|
|
|
|
*/
|
|
|
|
public static function runWithAfter(): array;
|
2020-08-03 21:31:32 +02:00
|
|
|
|
|
|
|
/**
|
2020-08-05 14:52:49 +02:00
|
|
|
* Specify a list of composer dependencies.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public static function composerRequires(): array;
|
2020-08-09 13:49:19 +02:00
|
|
|
/**
|
|
|
|
* Set configuration array.
|
|
|
|
*
|
|
|
|
* @param array $config
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function setConfigArray(array $config): void;
|
2020-08-09 16:23:01 +02:00
|
|
|
/**
|
2020-08-13 21:34:59 +02:00
|
|
|
* Set package context.
|
2020-08-09 16:23:01 +02:00
|
|
|
*
|
|
|
|
* @param PackageContext $ctx Ctx
|
2020-08-13 21:34:59 +02:00
|
|
|
*
|
2020-08-09 16:23:01 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function setPackageContext(PackageContext $ctx): void;
|
|
|
|
/**
|
2020-08-13 21:34:59 +02:00
|
|
|
* Get package context.
|
2020-08-09 16:23:01 +02:00
|
|
|
*
|
|
|
|
* @return PackageContext
|
|
|
|
*/
|
|
|
|
public function getPackageContext(): PackageContext;
|
|
|
|
/**
|
2020-08-13 21:34:59 +02:00
|
|
|
* Check if plugin should run.
|
2020-08-09 16:23:01 +02:00
|
|
|
*
|
|
|
|
* @param string $package Package name
|
2020-08-13 21:34:59 +02:00
|
|
|
*
|
2020-08-09 16:23:01 +02:00
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function shouldRun(string $package): bool;
|
|
|
|
/**
|
2020-08-13 21:34:59 +02:00
|
|
|
* Check if plugin should run.
|
2020-08-09 16:23:01 +02:00
|
|
|
*
|
|
|
|
* @param string $file File name
|
2020-08-13 21:34:59 +02:00
|
|
|
*
|
2020-08-09 16:23:01 +02:00
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function shouldRunFile(string $file): bool;
|
2020-08-05 14:52:49 +02:00
|
|
|
/**
|
|
|
|
* Get configuration key.
|
|
|
|
*
|
|
|
|
* @param string $key Key
|
|
|
|
* @param mixed $default Default value, if key is not present
|
2020-08-03 21:31:32 +02:00
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2020-08-05 14:52:49 +02:00
|
|
|
public function getConfig(string $key, $default);
|
2020-08-03 21:31:32 +02:00
|
|
|
|
|
|
|
/**
|
2020-08-05 14:52:49 +02:00
|
|
|
* Set configuration key.
|
2020-08-03 21:31:32 +02:00
|
|
|
*
|
|
|
|
* @param string $key Key
|
|
|
|
* @param mixed $value Value
|
2020-08-05 14:52:49 +02:00
|
|
|
*
|
2020-08-03 21:31:32 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function setConfig(string $key, $value): void;
|
2020-08-05 14:52:49 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Merge multiple configurations into one (or more).
|
|
|
|
*
|
|
|
|
* @param array ...$configs Configurations
|
|
|
|
*
|
|
|
|
* @return array[]
|
|
|
|
*/
|
|
|
|
public static function mergeConfigs(array ...$configs): array;
|
|
|
|
/**
|
|
|
|
* Split configuration.
|
2020-08-09 13:49:19 +02:00
|
|
|
*
|
2020-08-05 14:52:49 +02:00
|
|
|
* For example, if you have a configuration that enables feature A, B and C, return three configuration arrays each enabling ONLY A, only B and only C.
|
|
|
|
* This is used for optimizing the AST traversing process during resolution of the plugin graph.
|
|
|
|
*
|
|
|
|
* @param array $config Configuration
|
|
|
|
*
|
|
|
|
* @return array[]
|
|
|
|
*/
|
|
|
|
public static function splitConfig(array $config): array;
|
2020-08-03 21:31:32 +02:00
|
|
|
}
|