This repository has been archived by the owner on Dec 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Installer.php
85 lines (72 loc) · 2.33 KB
/
Installer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/**
* This file is part of Herbie.
*
* (c) Thomas Breuss <www.tebe.ch>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Herbie\Composer;
use Composer\Package\PackageInterface;
use Composer\Installer\LibraryInstaller;
use Composer\Repository\InstalledRepositoryInterface;
use Composer\Script\CommandEvent;
use Composer\Util\Filesystem;
class Installer extends LibraryInstaller
{
const EXTRA_WRITABLE = 'writable';
const EXTRA_EXECUTABLE = 'executable';
/**
* {@inheritDoc}
*/
public function getInstallPath(PackageInterface $package)
{
$prefix = substr($package->getPrettyName(), 0, 17);
if ('getherbie/plugin-' !== $prefix) {
throw new \InvalidArgumentException(
'Unable to install herbie plugin. The package name should always start with "getherbie/plugin-"'
);
}
$basePath = 'site/plugins/'.substr($package->getPrettyName(), 17);
return $basePath;
}
/**
* {@inheritDoc}
*/
public function supports($packageType)
{
return 'herbie-plugin' === $packageType;
}
/**
* Sets the correct permission for the files and directories listed in the extra section.
* @param CommandEvent $event
*/
public static function setPermission($event)
{
$options = array_merge([
self::EXTRA_WRITABLE => [],
self::EXTRA_EXECUTABLE => [],
], $event->getComposer()->getPackage()->getExtra());
foreach ((array) $options[self::EXTRA_WRITABLE] as $path) {
echo "Setting writable: $path ...";
if (is_dir($path)) {
chmod($path, 0777);
echo "done\n";
} else {
echo "The directory was not found: " . getcwd() . DIRECTORY_SEPARATOR . $path;
return;
}
}
foreach ((array) $options[self::EXTRA_EXECUTABLE] as $path) {
echo "Setting executable: $path ...";
if (is_file($path)) {
chmod($path, 0755);
echo "done\n";
} else {
echo "\n\tThe file was not found: " . getcwd() . DIRECTORY_SEPARATOR . $path . "\n";
return;
}
}
}
}