Skip to content

Commit

Permalink
Create XOOPS module-installer-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
geekwright committed Jul 9, 2014
1 parent 13e9406 commit 77730ae
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 1 deletion.
31 changes: 30 additions & 1 deletion README.md
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.
19 changes: 19 additions & 0 deletions composer.json
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.*"
}
}
45 changes: 45 additions & 0 deletions src/ModuleInstaller.php
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;
}
}
27 changes: 27 additions & 0 deletions src/ModuleInstallerPlugin.php
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);
}
}

0 comments on commit 77730ae

Please sign in to comment.