Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 4eede41

Browse files
committed
Init commit
0 parents  commit 4eede41

File tree

9 files changed

+317
-0
lines changed

9 files changed

+317
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
vendor/
2+
composer.lock
3+
.idea/

LICENSE.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License
2+
===============
3+
4+
Copyright (c) 2014 Jesse G. Donat
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
THE SOFTWARE.

LICENSES/ComposerInstaller/LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2012 Kyle Robinson Young
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# The Quorum Installer
2+
3+
Based on [composer/instalers](https://github.com/composer/installers).

composer.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "quorum/installer",
3+
"type": "composer-installer",
4+
"license": "MIT",
5+
"description": "The Quorum Installer",
6+
"autoload": {
7+
"psr-0": { "Quorum\\Installer\\": "src/" }
8+
},
9+
"extra": {
10+
"class": "Quorum\\Installer\\Installer",
11+
"branch-alias": {
12+
"dev-master": "1.0-dev"
13+
}
14+
},
15+
"replace": {
16+
"shama/baton": "*"
17+
},
18+
"require-dev": {
19+
"composer/composer": "1.0.*@dev",
20+
"phpunit/phpunit": "3.7.*"
21+
}
22+
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<?php
2+
namespace Quorum\Installer;
3+
4+
use Composer\Composer;
5+
use Composer\Package\PackageInterface;
6+
7+
abstract class BaseInstaller {
8+
protected $locations = array();
9+
protected $composer;
10+
protected $package;
11+
12+
/**
13+
* Initializes base installer.
14+
*
15+
* @param PackageInterface $package
16+
* @param Composer $composer
17+
*/
18+
public function __construct( PackageInterface $package = null, Composer $composer = null ) {
19+
$this->composer = $composer;
20+
$this->package = $package;
21+
}
22+
23+
/**
24+
* Return the install path based on package type.
25+
*
26+
* @param PackageInterface $package
27+
* @param string $frameworkType
28+
* @return string
29+
*/
30+
public function getInstallPath( PackageInterface $package, $frameworkType = '' ) {
31+
$type = $this->package->getType();
32+
33+
$prettyName = $this->package->getPrettyName();
34+
if( strpos($prettyName, '/') !== false ) {
35+
list($vendor, $name) = explode('/', $prettyName);
36+
} else {
37+
$vendor = '';
38+
$name = $prettyName;
39+
}
40+
41+
$availableVars = $this->inflectPackageVars(compact('name', 'vendor', 'type'));
42+
43+
$extra = $package->getExtra();
44+
if( !empty($extra['installer-name']) ) {
45+
$availableVars['name'] = $extra['installer-name'];
46+
}
47+
48+
if( $this->composer->getPackage() ) {
49+
$extra = $this->composer->getPackage()->getExtra();
50+
if( !empty($extra['installer-paths']) ) {
51+
$customPath = $this->mapCustomInstallPaths($extra['installer-paths'], $prettyName, $type);
52+
if( $customPath !== false ) {
53+
return $this->templatePath($customPath, $availableVars);
54+
}
55+
}
56+
}
57+
58+
$packageType = substr($type, strlen($frameworkType) + 1);
59+
if( !isset($this->locations[$packageType]) ) {
60+
throw new \InvalidArgumentException(sprintf('Package type "%s" is not supported', $type));
61+
}
62+
63+
return $this->templatePath($this->locations[$packageType], $availableVars);
64+
}
65+
66+
/**
67+
* For an installer to override to modify the vars per installer.
68+
*
69+
* @param array $vars
70+
* @return array
71+
*/
72+
public function inflectPackageVars( $vars ) {
73+
return $vars;
74+
}
75+
76+
/**
77+
* Gets the installer's locations
78+
*
79+
* @return array
80+
*/
81+
public function getLocations() {
82+
return $this->locations;
83+
}
84+
85+
/**
86+
* Replace vars in a path
87+
*
88+
* @param string $path
89+
* @param array $vars
90+
* @return string
91+
*/
92+
protected function templatePath( $path, array $vars = array() ) {
93+
if( strpos($path, '{') !== false ) {
94+
extract($vars);
95+
preg_match_all('@\{\$([A-Za-z0-9_]*)\}@i', $path, $matches);
96+
if( !empty($matches[1]) ) {
97+
foreach( $matches[1] as $var ) {
98+
$path = str_replace('{$' . $var . '}', $$var, $path);
99+
}
100+
}
101+
}
102+
103+
return $path;
104+
}
105+
106+
/**
107+
* Search through a passed paths array for a custom install path.
108+
*
109+
* @param array $paths
110+
* @param string $name
111+
* @param string $type
112+
* @return string
113+
*/
114+
protected function mapCustomInstallPaths( array $paths, $name, $type ) {
115+
foreach( $paths as $path => $names ) {
116+
if( in_array($name, $names) || in_array('type:' . $type, $names) ) {
117+
return $path;
118+
}
119+
}
120+
121+
return false;
122+
}
123+
}

src/Quorum/Installer/Installer.php

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
namespace Quorum\Installer;
3+
4+
use Composer\Installer\LibraryInstaller;
5+
use Composer\Package\PackageInterface;
6+
use Composer\Repository\InstalledRepositoryInterface;
7+
8+
class Installer extends LibraryInstaller {
9+
/**
10+
* Package types to installer class map
11+
*
12+
* @var array
13+
*/
14+
private $supportedTypes = array(
15+
'capstone' => 'QuorumInstaller',
16+
);
17+
18+
/**
19+
* {@inheritDoc}
20+
*/
21+
public function getInstallPath( PackageInterface $package ) {
22+
$type = $package->getType();
23+
$frameworkType = $this->findFrameworkType($type);
24+
25+
if( $frameworkType === false ) {
26+
throw new \InvalidArgumentException(
27+
'Sorry the package type of this package is not yet supported.'
28+
);
29+
}
30+
31+
$class = 'Composer\\Installers\\' . $this->supportedTypes[$frameworkType];
32+
$installer = new $class($package, $this->composer);
33+
34+
return $installer->getInstallPath($package, $frameworkType);
35+
}
36+
37+
public function uninstall( InstalledRepositoryInterface $repo, PackageInterface $package ) {
38+
if( !$repo->hasPackage($package) ) {
39+
throw new \InvalidArgumentException('Package is not installed: ' . $package);
40+
}
41+
42+
$repo->removePackage($package);
43+
44+
$installPath = $this->getInstallPath($package);
45+
$this->io->write(sprintf('Deleting %s - %s', $installPath, $this->filesystem->removeDirectory($installPath) ? '<comment>deleted</comment>' : '<error>not deleted</error>'));
46+
}
47+
48+
/**
49+
* {@inheritDoc}
50+
*/
51+
public function supports( $packageType ) {
52+
$frameworkType = $this->findFrameworkType($packageType);
53+
54+
if( $frameworkType === false ) {
55+
return false;
56+
}
57+
58+
$locationPattern = $this->getLocationPattern($frameworkType);
59+
60+
return preg_match('#' . $frameworkType . '-' . $locationPattern . '#', $packageType, $matches) === 1;
61+
}
62+
63+
/**
64+
* Finds a supported framework type if it exists and returns it
65+
*
66+
* @param string $type
67+
* @return string
68+
*/
69+
protected function findFrameworkType( $type ) {
70+
$frameworkType = false;
71+
72+
foreach( $this->supportedTypes as $key => $val ) {
73+
if( $key === substr($type, 0, strlen($key)) ) {
74+
$frameworkType = substr($type, 0, strlen($key));
75+
break;
76+
}
77+
}
78+
79+
return $frameworkType;
80+
}
81+
82+
/**
83+
* Get the second part of the regular expression to check for support of a
84+
* package type
85+
*
86+
* @param string $frameworkType
87+
* @return string
88+
*/
89+
protected function getLocationPattern( $frameworkType ) {
90+
$pattern = false;
91+
if( !empty($this->supportedTypes[$frameworkType]) ) {
92+
$frameworkClass = 'Composer\\Installers\\' . $this->supportedTypes[$frameworkType];
93+
/** @var BaseInstaller $framework */
94+
$framework = new $frameworkClass;
95+
$locations = array_keys($framework->getLocations());
96+
$pattern = $locations ? '(' . implode('|', $locations) . ')' : false;
97+
}
98+
99+
return $pattern ? : '(\w+)';
100+
}
101+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Quorum\Installer;
4+
5+
class QuorumInstaller extends BaseInstaller {
6+
7+
protected $locations = array(
8+
'js' => 'public/js/vendor/{$vendor}/{$name}/',
9+
);
10+
11+
}

src/bootstrap.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
function includeIfExists($file)
3+
{
4+
if (file_exists($file)) {
5+
return include $file;
6+
}
7+
}
8+
if ((!$loader = includeIfExists(__DIR__ . '/../vendor/autoload.php')) && (!$loader = includeIfExists(__DIR__ . '/../../../autoload.php'))) {
9+
die('You must set up the project dependencies, run the following commands:'.PHP_EOL.
10+
'curl -s http://getcomposer.org/installer | php'.PHP_EOL.
11+
'php composer.phar install'.PHP_EOL);
12+
}
13+
return $loader;

0 commit comments

Comments
 (0)