Skip to content
This repository was archived by the owner on Jun 11, 2019. It is now read-only.

Commit 2aa6c2b

Browse files
committed
module installer
0 parents  commit 2aa6c2b

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

composer.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "hechoenlaravel/composer-plugin",
3+
"type": "composer-plugin",
4+
"require": {
5+
"composer-plugin-api": "^1.0"
6+
},
7+
"license": "MIT",
8+
"autoload": {
9+
"psr-4": {
10+
"Hechoenlaravel\\JarvisPlatformComposerPlugin\\": "src/"
11+
}
12+
},
13+
"extra": {
14+
"class": "Hechoenlaravel\\JarvisPlatformComposerPlugin\\Plugin"
15+
}
16+
}

src/ModuleInstaller.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Hechoenlaravel\JarvisPlatformComposerPlugin;
4+
5+
use Composer\Package\PackageInterface;
6+
use Composer\Installer\LibraryInstaller;
7+
8+
class ModuleInstaller extends LibraryInstaller
9+
{
10+
/**
11+
* {@inheritDoc}
12+
*/
13+
public function getPackageBasePath(PackageInterface $package)
14+
{
15+
$ex = explode('/', $package->getPrettyName());
16+
if (!isset($ex[1])) {
17+
throw new \InvalidArgumentException(
18+
'Unable to install Module. '
19+
.'it Should always start their package name with '
20+
.'"vendor/jarvis-"'
21+
);
22+
}
23+
$prefix = substr($ex[1], 0, 6);
24+
if('jarvis-' !== $prefix)
25+
{
26+
throw new \InvalidArgumentException(
27+
'Unable to install Module. '
28+
.'it Should always start their package name with '
29+
.'"vendor/jarvis-"'
30+
);
31+
}
32+
33+
return 'core/'.substr($ex[1], 6);
34+
}
35+
}

src/Plugin.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Hechoenlaravel\JarvisPlatformComposerPlugin;
4+
5+
use Composer\Composer;
6+
use Composer\IO\IOInterface;
7+
use Composer\Plugin\PluginInterface;
8+
9+
class Plugin implements PluginInterface
10+
{
11+
public function activate(Composer $composer, IOInterface $io)
12+
{
13+
$installer = new ModuleInstaller($io, $composer);
14+
$composer->getInstallationManager()->addInstaller($installer);
15+
}
16+
17+
}

0 commit comments

Comments
 (0)