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

Skip to content

Commit ae245b9

Browse files
authored
Merge pull request #3 from drupal-composer/issue#2
[#2] Exposed the plugin as custom command
2 parents b14ec13 + 92fc3d0 commit ae245b9

File tree

4 files changed

+70
-19
lines changed

4 files changed

+70
-19
lines changed

README.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@ mv web app
2020

2121
Update the `composer.json` of your root package with the following changes:
2222
```json
23-
"scripts": {
24-
"drupal-paranoia": "DrupalComposer\\DrupalParanoia\\Plugin::install",
25-
"..."
26-
}
27-
```
28-
```json
2923
"extra": {
3024
"installer-paths": {
3125
"app/core": ["type:drupal-core"],
@@ -57,7 +51,7 @@ Every time that you install or update a Drupal package via Composer, the `web` f
5751

5852
If necessary, you can rebuild it manually, running the command
5953
```
60-
composer run-script drupal-paranoia
54+
composer drupal:paranoia
6155
```
6256

6357
This could be necessary when updating themes images, CSS and JS files.

src/CommandProvider.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace DrupalComposer\DrupalParanoia;
4+
5+
use Composer\Plugin\Capability\CommandProvider as CommandProviderCapability;
6+
7+
/**
8+
* Class CommandProvider.
9+
*
10+
* @package DrupalComposer\DrupalParanoia
11+
*/
12+
class CommandProvider implements CommandProviderCapability {
13+
14+
/**
15+
* {@inheritdoc}
16+
*/
17+
public function getCommands() {
18+
return array(
19+
new DrupalParanoiaCommand(),
20+
);
21+
}
22+
23+
}

src/DrupalParanoiaCommand.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace DrupalComposer\DrupalParanoia;
4+
5+
use Composer\Command\BaseCommand;
6+
use Symfony\Component\Console\Input\InputInterface;
7+
use Symfony\Component\Console\Output\OutputInterface;
8+
9+
/**
10+
* Class DrupalParanoiaCommand.
11+
*
12+
* @package DrupalComposer\DrupalParanoia
13+
*/
14+
class DrupalParanoiaCommand extends BaseCommand {
15+
16+
/**
17+
* {@inheritdoc}
18+
*/
19+
protected function configure() {
20+
parent::configure();
21+
$this
22+
->setName('drupal:paranoia')
23+
->setAliases(['drupal-paranoia'])
24+
->setDescription('Execute the installation of the paranoia mode.');
25+
}
26+
27+
/**
28+
* {@inheritdoc}
29+
*/
30+
protected function execute(InputInterface $input, OutputInterface $output) {
31+
$installer = new Installer($this->getComposer(), $this->getIO());
32+
$installer->install();
33+
}
34+
35+
}

src/Plugin.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
use Composer\Installer\PackageEvent;
88
use Composer\Installer\PackageEvents;
99
use Composer\IO\IOInterface;
10+
use Composer\Plugin\Capable;
1011
use Composer\Plugin\PluginInterface;
1112
use Composer\Script\Event;
1213
use Composer\Script\ScriptEvents;
1314

1415
/**
1516
* Composer plugin to move all PHP files out of the docroot.
1617
*/
17-
class Plugin implements PluginInterface, EventSubscriberInterface {
18+
class Plugin implements PluginInterface, EventSubscriberInterface, Capable {
1819

1920
/**
2021
* The installer object.
@@ -30,6 +31,15 @@ public function activate(Composer $composer, IOInterface $io) {
3031
$this->installer = new Installer($composer, $io);
3132
}
3233

34+
/**
35+
* {@inheritdoc}
36+
*/
37+
public function getCapabilities() {
38+
return array(
39+
'Composer\Plugin\Capability\CommandProvider' => 'DrupalComposer\DrupalParanoia\CommandProvider',
40+
);
41+
}
42+
3343
/**
3444
* {@inheritdoc}
3545
*/
@@ -63,15 +73,4 @@ public function postCmd(Event $event) {
6373
$this->installer->onPostCmdEvent();
6474
}
6575

66-
/**
67-
* Script callback for installing the paranoia mode.
68-
*
69-
* @param \Composer\Script\Event $event
70-
* Event object.
71-
*/
72-
public static function install(Event $event) {
73-
$installer = new Installer($event->getComposer(), $event->getIO());
74-
$installer->install();
75-
}
76-
7776
}

0 commit comments

Comments
 (0)