-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create XOOPS module-installer-plugin
- Loading branch information
1 parent
13e9406
commit 77730ae
Showing
4 changed files
with
121 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,33 @@ | ||
module-installer-plugin | ||
======================= | ||
|
||
module-installer-plugin | ||
*This package is in development and may be subject to change. It is published to enable testing and feedback only.* | ||
|
||
This is a plugin for [Composer](http://getcomposer.org/) that allows XOOPS 2.6 modules to be managed by composer. Managing XOOPS modules with composer enables dependency management for modules, as modules can require other libraries, or even other modules. | ||
|
||
To use this plugin, your module should include a type property of **"xoops-module"** in its `composer.json`, and it should require **"XOOPS/module-installer-plugin"** as in the following example. | ||
|
||
```JSON | ||
{ | ||
"name": "geekwright/dummy", | ||
"type": "xoops-module", | ||
"description": "XOOPS dummy module for testing", | ||
"require": { | ||
"XOOPS/module-installer-plugin": "~1.0" | ||
} | ||
} | ||
``` | ||
|
||
The package contents will be installed in the modules directory, in a subdirectory of the same name as the module package. See [geekwright/dummy](https://github.com/geekwright/dummy) for a simple example of a module enabled for composer management. | ||
|
||
The `composer.json` of the main xoops-library package needs to set the filesystem path to the XOOPS modules directory in the "extra" property as shown here: | ||
|
||
```JSON | ||
"extra": { | ||
"xoops_modules": "/home/user/htdocs/modules/" | ||
} | ||
``` | ||
|
||
Normally, the XOOPS installer will have adjusted this setting during installation. | ||
|
||
The composer install process only makes the module available to XOOPS. Traditional module installation and configuration are still accomplished in the XOOPS system adminstration area. |
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,19 @@ | ||
{ | ||
"name": "XOOPS/module-installer-plugin", | ||
"description": "Install XOOPS modules using Composer", | ||
"keywords": ["xoops", "installer"], | ||
"type": "composer-plugin", | ||
"license": "MIT", | ||
"autoload": { | ||
"psr-4": {"Xoops\\Composer\\": "src/"} | ||
}, | ||
"extra": { | ||
"class": "Xoops\\Composer\\ModuleInstallerPlugin" | ||
}, | ||
"require": { | ||
"composer-plugin-api": "1.0.0" | ||
}, | ||
"replace": { | ||
"geekwright/module-installer-plugin": "1.0.*" | ||
} | ||
} |
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,45 @@ | ||
<?php | ||
|
||
namespace Xoops\Composer; | ||
|
||
use Composer\Package\PackageInterface; | ||
use Composer\Installer\LibraryInstaller; | ||
|
||
/** | ||
* Composer installer for XOOPS modules | ||
*/ | ||
class ModuleInstaller extends LibraryInstaller | ||
{ | ||
/** | ||
* getPackageBasePath | ||
* | ||
* @param PackageInterface $package package being installed | ||
* | ||
* @return string install path relative to composer.json | ||
*/ | ||
public function getPackageBasePath(PackageInterface $package) | ||
{ | ||
$moddir = explode('/', $package->getName()); | ||
|
||
$xoops_modules = '../modules/'; | ||
|
||
$extra = $this->composer->getPackage()->getExtra(); | ||
if (isset($extra['xoops_modules_path'])) { | ||
$xoops_root = $extra['xoops_modules_path']; | ||
} | ||
|
||
return $xoops_modules . $moddir[1]; | ||
} | ||
|
||
/** | ||
* supports - determine if this supports a given package type | ||
* | ||
* @param string $packageType package type name | ||
* | ||
* @return boolean true if packageType is supported | ||
*/ | ||
public function supports($packageType) | ||
{ | ||
return 'xoops-module' === $packageType; | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
|
||
namespace Xoops\Composer; | ||
|
||
use Composer\Composer; | ||
use Composer\IO\IOInterface; | ||
use Composer\Plugin\PluginInterface; | ||
|
||
/** | ||
* Composer plugin for XOOPS module installer | ||
*/ | ||
class ModuleInstallerPlugin implements PluginInterface | ||
{ | ||
/** | ||
* activate - add our installer to composer | ||
* | ||
* @param Composer $composer composer instance | ||
* @param IOInterface $io composer i/o | ||
* | ||
* @return void | ||
*/ | ||
public function activate(Composer $composer, IOInterface $io) | ||
{ | ||
$installer = new ModuleInstaller($io, $composer); | ||
$composer->getInstallationManager()->addInstaller($installer); | ||
} | ||
} |