Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 59bc484

Browse files
authored
Implemented event 'drupal-paranoia-post-command-run' to fires after the command 'drupal:paranoia' is executed (#11)
1 parent 8fccb83 commit 59bc484

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,48 @@ class ScriptHandler {
9797
}
9898
```
9999

100+
#### Plugin events
101+
This plugin fires the following named event during its execution process:
102+
103+
- __drupal-paranoia-post-command-run__: Occurs after the command `drupal:paranoia` is executed.
104+
105+
##### Example of event subscriber
106+
107+
```php
108+
<?php
109+
110+
namespace MyVendor;
111+
112+
use Composer\Composer;
113+
use Composer\EventDispatcher\EventSubscriberInterface;
114+
use Composer\IO\IOInterface;
115+
use Composer\Plugin\PluginInterface;
116+
use DrupalComposer\DrupalParanoia\PluginEvents as DrupalParanoiaPluginEvents;
117+
118+
class MyClass implements PluginInterface, EventSubscriberInterface
119+
{
120+
protected $composer;
121+
protected $io;
122+
123+
public function activate(Composer $composer, IOInterface $io)
124+
{
125+
$this->composer = $composer;
126+
$this->io = $io;
127+
}
128+
129+
public static function getSubscribedEvents()
130+
{
131+
return array(
132+
DrupalParanoiaPluginEvents::POST_COMMAND_RUN => 'postDrupalParanoiaCommand',
133+
);
134+
}
135+
136+
public function postDrupalParanoiaCommand(CommandEvent $event) {
137+
// Add your custom action.
138+
}
139+
}
140+
```
141+
100142
## Folder structure
101143
Your project now is basically structured on two folders.
102144
- __app__: Contains the files and folders of the full Drupal installation.

src/DrupalParanoiaCommand.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace DrupalComposer\DrupalParanoia;
44

55
use Composer\Command\BaseCommand;
6+
use Composer\Plugin\CommandEvent;
67
use Symfony\Component\Console\Input\InputInterface;
78
use Symfony\Component\Console\Output\OutputInterface;
89

@@ -30,6 +31,10 @@ protected function configure() {
3031
protected function execute(InputInterface $input, OutputInterface $output) {
3132
$installer = new Installer($this->getComposer(), $this->getIO());
3233
$installer->install();
34+
35+
$composer = $this->getComposer();
36+
$commandEvent = new CommandEvent(PluginEvents::POST_COMMAND_RUN, 'drupal:paranoia', $input, $output);
37+
$composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
3338
}
3439

3540
}

src/PluginEvents.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace DrupalComposer\DrupalParanoia;
4+
5+
/**
6+
* The Plugin Events.
7+
*/
8+
class PluginEvents {
9+
/**
10+
* The POST_COMMAND_RUN event occurs after the command is executed.
11+
*
12+
* @var string
13+
*/
14+
const POST_COMMAND_RUN = 'drupal-paranoia-post-command-run';
15+
16+
}

0 commit comments

Comments
 (0)