Skip to content

Commit 5bde2cb

Browse files
committed
Initial commit
0 parents  commit 5bde2cb

File tree

8 files changed

+616
-0
lines changed

8 files changed

+616
-0
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
### Added
11+
- Added required classes (Plugin, BaseInstaller, ModuleInstaller, SiteProfileInstaller).
12+
- Added markdown files to describe the project (LICENSE, README.md, CHANGELOG.md.)
13+
- Added the composer.json file.

LICENSE

Lines changed: 373 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# ProcessWire Composer installers
2+
3+
This project contains [Composer custom installers](https://getcomposer.org/doc/articles/custom-installers.md) for
4+
ProcessWire CMS/CMF modules and site profiles.
5+
6+
## Requirements
7+
8+
- PHP 5.5 or newer
9+
10+
## License
11+
12+
This project is licensed under the Mozilla Public License Version 2.0.

composer.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "wireframe-framework/processwire-composer-installer",
3+
"type": "composer-plugin",
4+
"description": "Custom Composer installer for the ProcessWire CMS/CMF modules and site profiles.",
5+
"keywords": [ "composer", "processwire", "installer" ],
6+
"homepage": "https://wireframe-framework.com",
7+
"license": "MPL-2.0",
8+
"authors": [
9+
{
10+
"name": "Teppo Koivula",
11+
"homepage": "https://wireframe-framework.com",
12+
"email": "teppo@wireframe-framework.com"
13+
}
14+
],
15+
"require": {
16+
"composer-plugin-api": "^1.0"
17+
},
18+
"autoload": {
19+
"psr-4": {
20+
"wireframe\\": "src/"
21+
}
22+
},
23+
"extra": {
24+
"class": "wireframe\\ComposerInstaller\\Plugin"
25+
}
26+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
3+
namespace wireframe\ComposerInstaller;
4+
5+
use Composer\Package\PackageInterface;
6+
use Composer\Installer\LibraryInstaller;
7+
8+
/**
9+
* BaseInstaller class
10+
*
11+
* This is a base class for ProcessWire CMS/CMF module and site profile
12+
* installers.
13+
*
14+
* @author Teppo Koivula <teppo@wireframe-framework.com>
15+
* @license Mozilla Public License v2.0 http://mozilla.org/MPL/2.0/
16+
*/
17+
class BaseInstaller extends LibraryInstaller
18+
{
19+
/**
20+
* {@inheritDoc}
21+
*/
22+
public function getInstallPath(PackageInterface $package)
23+
{
24+
return parent::getInstallPath($package);
25+
}
26+
27+
/**
28+
* {@inheritDoc}
29+
*/
30+
public function supports($packageType)
31+
{
32+
return parent::supports($packageType);
33+
}
34+
35+
/**
36+
* Get the base path for current installer
37+
*
38+
* Default base path is provided as an argument. This can be overridden by
39+
* specifying pw-[type]-path extra argument in composer.json, where "type"
40+
* is either "module" or "site-profile".
41+
*
42+
* @param string $defaultBasePath Default base path.
43+
* @return string Base path.
44+
*/
45+
protected function getBasePath($defaultBasePath) {
46+
// get the extra configuration of the top-level package
47+
$extra = [];
48+
if ($rootPackage = $this->composer->getPackage()) {
49+
$extra = $rootPackage->getExtra();
50+
}
51+
52+
// use base path from configuration, otherwise fall back to default
53+
$class = basename(str_replace('\\', '/', static::class));
54+
$type = strtolower(preg_replace('/(?<!^)[A-Z]/', '-$0', substr($class, 0, strrpos($class, 'Installer'))));
55+
$basePath = $extra['pw-' . $type . '-path'] ?? $defaultBasePath;
56+
57+
return $basePath;
58+
}
59+
60+
/**
61+
* Get the directory name from package name
62+
*
63+
* Default directory name can be overridden by specifying extra argument
64+
* "installer-name" in the composer.json of the package in question.
65+
*
66+
* @param PackageInterface $package
67+
* @return string Module or site profile name.
68+
*/
69+
protected function getName(PackageInterface $package) {
70+
// determine the directory name from its package name
71+
$name = explode('/', $package->getPrettyName())[1];
72+
73+
// allow overriding module directory name via composer.json
74+
$extra = $package->getExtra();
75+
if (!empty($extra['installer-name'])) {
76+
$name = $extra['installer-name'];
77+
}
78+
79+
return $name;
80+
}
81+
82+
/**
83+
* Get the full path with base part and package directory name
84+
*
85+
* @param PackageInterface $package
86+
* @param string $defaultBasePath Default base path.
87+
* @return string Path.
88+
*/
89+
protected function getFullPath(PackageInterface $package, $defaultBasePath) {
90+
$basePath = $this->getBasePath($defaultBasePath);
91+
$name = $this->getName($package);
92+
$path = trim($basePath, '/') . '/' . $name;
93+
return $path;
94+
}
95+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace wireframe\ComposerInstaller;
4+
5+
use Composer\Package\PackageInterface;
6+
7+
/**
8+
* ModuleInstaller class
9+
*
10+
* This class implements a custom Composer installer for ProcessWire CMS/CMF
11+
* modules.
12+
*
13+
* @author Teppo Koivula <teppo@wireframe-framework.com>
14+
* @license Mozilla Public License v2.0 http://mozilla.org/MPL/2.0/
15+
*/
16+
class ModuleInstaller extends BaseInstaller
17+
{
18+
/**
19+
* {@inheritDoc}
20+
*/
21+
public function getInstallPath(PackageInterface $package)
22+
{
23+
return $this->getFullPath($package, 'site/modules');)
24+
}
25+
26+
/**
27+
* {@inheritDoc}
28+
*/
29+
public function supports($packageType)
30+
{
31+
return $packageType === 'pw-module';
32+
}
33+
}

src/ComposerInstaller/Plugin.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace wireframe\ComposerInstaller;
4+
5+
use Composer\Composer;
6+
use Composer\IO\IOInterface;
7+
use Composer\Plugin\PluginInterface;
8+
9+
/**
10+
* The Plugin class
11+
*
12+
* This class registers our custom installers.
13+
*
14+
* @author Teppo Koivula <teppo@wireframe-framework.com>
15+
* @license Mozilla Public License v2.0 http://mozilla.org/MPL/2.0/
16+
*/
17+
class Plugin implements PluginInterface
18+
{
19+
/**
20+
* Register custom installers for ProcessWire modules and site profiles.
21+
*
22+
* @param Composer $composer
23+
* @param IOInterface $io
24+
*/
25+
public function activate(Composer $composer, IOInterface $io)
26+
{
27+
$installationManager = $composer->getInstallationManager();
28+
$installationManager->addInstaller(new ModuleInstaller($io, $composer));
29+
$installationManager->addInstaller(new SiteProfileInstaller($io, $composer));
30+
}
31+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace wireframe\ComposerInstaller;
4+
5+
use Composer\Package\PackageInterface;
6+
7+
/**
8+
* SiteProfileInstaller class
9+
*
10+
* This class implements a custom Composer installer for ProcessWire CMS/CMF
11+
* site profiles.
12+
*
13+
* @author Teppo Koivula <teppo@wireframe-framework.com>
14+
* @license Mozilla Public License v2.0 http://mozilla.org/MPL/2.0/
15+
*/
16+
class SiteProfileInstaller extends BaseInstaller
17+
{
18+
/**
19+
* {@inheritDoc}
20+
*/
21+
public function getInstallPath(PackageInterface $package)
22+
{
23+
return $this->getFullPath($package, '');
24+
}
25+
26+
/**
27+
* {@inheritDoc}
28+
*/
29+
public function supports($packageType)
30+
{
31+
return $packageType === 'pw-site-profile';
32+
}
33+
}

0 commit comments

Comments
 (0)