This repository has been archived by the owner on Jun 23, 2024. It is now read-only.
forked from navitronic/psymf
-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Fix some CS - Add types - Copy the necessary test container services from `test.xml` instead of prepending the framework bundle test config - Make `psysh.shell` private - Inject the Psysh application instead of application child class - Add a few missing `@private` tags
- Loading branch information
Showing
16 changed files
with
167 additions
and
137 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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<?php | ||
<?php declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the PsyshBundle package. | ||
|
@@ -14,53 +14,69 @@ | |
use Psy\Command\Command; | ||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; | ||
use Symfony\Component\DependencyInjection\Loader; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
use Symfony\Component\ExpressionLanguage\Expression; | ||
use Symfony\Component\HttpKernel\DependencyInjection\Extension; | ||
use Symfony\Bundle\FrameworkBundle\Test\TestContainer; | ||
use function array_merge; | ||
use function is_string; | ||
use function sprintf; | ||
use function strpos; | ||
use function substr; | ||
|
||
/** | ||
* This is the class that loads and manages your bundle configuration. | ||
* | ||
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} | ||
* | ||
* @author Théo FIDRY <[email protected]> | ||
* | ||
* @private | ||
*/ | ||
final class PsyshExtension extends Extension implements PrependExtensionInterface | ||
final class PsyshExtension extends Extension | ||
{ | ||
public function prepend(ContainerBuilder $container) | ||
{ | ||
if (class_exists(TestContainer::class)) { | ||
$container->prependExtensionConfig('framework', ['test' => true]); | ||
} | ||
} | ||
private const CONFIG_DIR = __DIR__.'/../../resources/config'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function load(array $configs, ContainerBuilder $container) | ||
public function load(array $configs, ContainerBuilder $container): void | ||
{ | ||
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../../resources/config')); | ||
$loader = new Loader\XmlFileLoader($container, new FileLocator(self::CONFIG_DIR)); | ||
$loader->load('services.xml'); | ||
|
||
$configuration = new Configuration(); | ||
$config = $this->processConfiguration($configuration, $configs); | ||
$config = $this->processConfiguration(new Configuration(), $configs); | ||
|
||
foreach ($config['variables'] as $name => &$value) { | ||
if (is_string($value) && $value[0] === '@') { | ||
if (is_string($value) && strpos($value, '@') === 0) { | ||
$value = new Reference(substr($value, 1)); | ||
} | ||
} | ||
$containerId = class_exists(TestContainer::class) ? 'test.service_container' : 'service_container'; | ||
$container->findDefinition('psysh.shell') | ||
->addMethodCall('setScopeVariables', [$config['variables'] + [ | ||
'container' => new Reference($containerId), | ||
'kernel' => new Reference('kernel'), | ||
'self' => new Reference('psysh.shell'), | ||
'parameters' => new Expression(sprintf("service('%s').getParameterBag().all()", $containerId)) | ||
]]); | ||
|
||
$container->registerForAutoconfiguration(Command::class)->addTag('psysh.command'); | ||
$containerId = 'test.service_container'; | ||
|
||
$container | ||
->findDefinition('psysh.shell') | ||
->addMethodCall( | ||
'setScopeVariables', | ||
[array_merge( | ||
$config['variables'], | ||
[ | ||
'container' => new Reference($containerId), | ||
'kernel' => new Reference('kernel'), | ||
'self' => new Reference('psysh.shell'), | ||
'parameters' => new Expression(sprintf( | ||
"service('%s').getParameterBag().all()", | ||
$containerId | ||
)) | ||
] | ||
)] | ||
) | ||
; | ||
|
||
$container | ||
->registerForAutoconfiguration(Command::class) | ||
->addTag('psysh.command') | ||
; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -12,29 +12,35 @@ | |
namespace Fidry\PsyshBundle; | ||
|
||
use Fidry\PsyshBundle\DependencyInjection\Compiler\AddPsyshCommandPass; | ||
use Psy\Command\Command; | ||
use Symfony\Component\DependencyInjection\Compiler\PassConfig; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\HttpKernel\Bundle\Bundle; | ||
|
||
/** | ||
* @author Adrian PALMER <[email protected]> | ||
* @author Théo FIDRY <[email protected]> | ||
* | ||
* @private | ||
*/ | ||
final class PsyshBundle extends Bundle | ||
{ | ||
public function boot() | ||
public function boot(): void | ||
{ | ||
parent::boot(); | ||
|
||
$this->container->get('psysh.facade'); | ||
} | ||
|
||
public function build(ContainerBuilder $container) | ||
public function build(ContainerBuilder $container): void | ||
{ | ||
parent::build($container); | ||
|
||
// Ensure that AddPsyshCommandPass runs before AddConsoleCommandPass to avoid autoconfiguration conflicts. | ||
$container->addCompilerPass(new AddPsyshCommandPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 10); | ||
// Ensures that AddPsyshCommandPass runs before AddConsoleCommandPass to avoid | ||
// autoconfiguration conflicts. | ||
$container->addCompilerPass( | ||
new AddPsyshCommandPass(), | ||
PassConfig::TYPE_BEFORE_OPTIMIZATION, | ||
10 | ||
); | ||
} | ||
} |
Oops, something went wrong.