-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce the new v2 extension system
- Loading branch information
Showing
11 changed files
with
269 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace GrumPHP\Configuration\Loader; | ||
|
||
use Symfony\Component\Config\Loader\LoaderInterface; | ||
use Symfony\Component\Config\Loader\LoaderResolverInterface; | ||
|
||
/** | ||
* A decorating dist loader that supports **.dist files and defers loading. | ||
*/ | ||
final class DistFileLoader implements LoaderInterface | ||
{ | ||
private LoaderInterface $loader; | ||
|
||
public function __construct(LoaderInterface $loader) | ||
{ | ||
$this->loader = $loader; | ||
} | ||
|
||
public function load(mixed $resource, string $type = null): void | ||
{ | ||
$this->loader->load($resource, $type); | ||
} | ||
|
||
public function supports(mixed $resource, string $type = null): bool | ||
{ | ||
if (!\is_string($resource)) { | ||
return false; | ||
} | ||
|
||
if ($type !== null) { | ||
return $this->loader->supports($resource, $type); | ||
} | ||
|
||
$extension = pathinfo($resource, \PATHINFO_EXTENSION); | ||
if ($extension !== 'dist') { | ||
return false; | ||
} | ||
|
||
$distForFile = pathinfo($resource, \PATHINFO_FILENAME); | ||
|
||
return $this->loader->supports($distForFile); | ||
} | ||
|
||
public function getResolver(): LoaderResolverInterface | ||
{ | ||
return $this->loader->getResolver(); | ||
} | ||
|
||
public function setResolver(LoaderResolverInterface $resolver): void | ||
{ | ||
$this->loader->setResolver($resolver); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace GrumPHP\Configuration; | ||
|
||
use GrumPHP\Configuration\Loader\DistFileLoader; | ||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\Config\Loader\DelegatingLoader; | ||
use Symfony\Component\Config\Loader\LoaderResolver; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Loader\DirectoryLoader; | ||
use Symfony\Component\DependencyInjection\Loader\GlobFileLoader; | ||
use Symfony\Component\DependencyInjection\Loader\IniFileLoader; | ||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; | ||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; | ||
|
||
final class LoaderFactory | ||
{ | ||
private const ENV = 'grumphp'; | ||
|
||
/** | ||
* @param list<string> $paths | ||
*/ | ||
public static function createLoader(ContainerBuilder $container, array $paths = []): DelegatingLoader | ||
{ | ||
$locator = new FileLocator($paths); | ||
$resolver = new LoaderResolver([ | ||
$xmlLoader = new XmlFileLoader($container, $locator, self::ENV), | ||
$yamlLoader = new YamlFileLoader($container, $locator, self::ENV), | ||
$iniLoader = new IniFileLoader($container, $locator, self::ENV), | ||
new GlobFileLoader($container, $locator, self::ENV), | ||
new DirectoryLoader($container, $locator, self::ENV), | ||
new DistFileLoader($xmlLoader), | ||
new DistFileLoader($yamlLoader), | ||
new DistFileLoader($iniLoader), | ||
]); | ||
|
||
return new DelegatingLoader($resolver); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace GrumPHPTest\E2E; | ||
|
||
class ExtensionsTest extends AbstractE2ETestCase | ||
{ | ||
/** @test */ | ||
function it_can_configure_an_extension() | ||
{ | ||
$this->initializeGitInRootDir(); | ||
$this->initializeComposer($this->rootDir); | ||
$grumphpFile = $this->initializeGrumphpConfig($this->rootDir); | ||
$this->installComposer($this->rootDir); | ||
$this->ensureHooksExist(); | ||
|
||
$this->enableCustomExtension($grumphpFile, $this->rootDir); | ||
|
||
$this->commitAll(); | ||
$this->runGrumphp($this->rootDir); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace GrumPHPE2E; | ||
|
||
use GrumPHP\Extension\ExtensionInterface; | ||
|
||
class ValidateExtension implements ExtensionInterface | ||
{ | ||
public function imports(): iterable | ||
{ | ||
yield __DIR__.DIRECTORY_SEPARATOR.'extension.yaml'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
services: | ||
GrumPHPE2E\SuccessfulTask: | ||
class: GrumPHPE2E\SuccessfulTask | ||
arguments: [] | ||
tags: | ||
- { name: grumphp.task, task: success } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
namespace GrumPHPE2E; | ||
|
||
use GrumPHP\Runner\TaskResult; | ||
use GrumPHP\Runner\TaskResultInterface; | ||
use GrumPHP\Task\Config\ConfigOptionsResolver; | ||
use GrumPHP\Task\Config\EmptyTaskConfig; | ||
use GrumPHP\Task\Config\TaskConfigInterface; | ||
use GrumPHP\Task\Context\ContextInterface; | ||
use GrumPHP\Task\TaskInterface; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
class SuccessfulTask implements TaskInterface | ||
{ | ||
/** | ||
* @var TaskConfigInterface | ||
*/ | ||
private $config; | ||
|
||
public function __construct() | ||
{ | ||
$this->config = new EmptyTaskConfig(); | ||
} | ||
|
||
public function getConfig(): TaskConfigInterface | ||
{ | ||
return $this->config; | ||
} | ||
|
||
public function withConfig(TaskConfigInterface $config): TaskInterface | ||
{ | ||
$new = clone $this; | ||
$new->config = $config; | ||
|
||
return $new; | ||
} | ||
|
||
public static function getConfigurableOptions(): ConfigOptionsResolver | ||
{ | ||
return ConfigOptionsResolver::fromOptionsResolver(new OptionsResolver()); | ||
} | ||
|
||
public function canRunInContext(ContextInterface $context): bool | ||
{ | ||
return true; | ||
} | ||
|
||
public function run(ContextInterface $context): TaskResultInterface | ||
{ | ||
return TaskResult::createPassed($this, $context); | ||
} | ||
} |