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.
Add extension points for custom variables and commands (#28)
- Loading branch information
1 parent
c7e9bf2
commit 6c9a09b
Showing
6 changed files
with
170 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the PsyshBundle package. | ||
* | ||
* (c) Théo FIDRY <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Fidry\PsyshBundle\DependencyInjection\Compiler; | ||
|
||
use Psy\Command\Command as PsyshCommand; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
/** | ||
* Compiler pass allowing to add Psysh commands dynamically | ||
* | ||
* @author Jérôme Vieilledent <[email protected]> | ||
* | ||
* @private | ||
*/ | ||
final class AddPsyshCommandPass implements CompilerPassInterface | ||
{ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
if (!$container->has('psysh.shell')) { | ||
return; | ||
} | ||
|
||
$commands = []; | ||
foreach ($container->findTaggedServiceIds('psysh.command') as $id => $attributes) { | ||
// Workaround to avoid Psysh commands to be registered as regular console commands | ||
// (conflict with service autoconfiguration as Psysh commands inherit from \Symfony\Component\Console\Command\Command as well | ||
// Note that this compiler pass must run with a higher priority than AddConsoleCommandPass to be efficient. | ||
$container->findDefinition($id)->clearTag('console.command'); | ||
$commands[] = new Reference($id); | ||
} | ||
|
||
$shellRef = $container->findDefinition('psysh.shell'); | ||
$shellRef->addMethodCall('addCommands', [$commands]); | ||
} | ||
} |
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,43 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the PsyshBundle package. | ||
* | ||
* (c) Théo FIDRY <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Fidry\PsyshBundle\DependencyInjection; | ||
|
||
use Symfony\Component\Config\Definition\Builder\TreeBuilder; | ||
use Symfony\Component\Config\Definition\ConfigurationInterface; | ||
|
||
/** | ||
* @private | ||
*/ | ||
final class Configuration implements ConfigurationInterface | ||
{ | ||
public function getConfigTreeBuilder() | ||
{ | ||
$treeBuilder = new TreeBuilder(); | ||
$rootNode = $treeBuilder->root('psysh'); | ||
|
||
$rootNode | ||
->children() | ||
->arrayNode('variables') | ||
->info('Define additional variables to be exposed in Psysh') | ||
->useAttributeAsKey('variable_name') | ||
->example([ | ||
'debug' => '%kernel.debug%', | ||
'my_service' => '@my.service', | ||
'os' => ['linux', 'macos', 'losedows'], | ||
]) | ||
->prototype('variable')->end() | ||
->end() | ||
->end(); | ||
|
||
return $treeBuilder; | ||
} | ||
} |
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