Skip to content

Commit 8ab1e99

Browse files
authored
Implement missing PluginInterface methods for v2 (#10)
1 parent 35ccbf4 commit 8ab1e99

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
"class": "Hostnet\\Component\\Path\\Plugin"
2323
},
2424
"require-dev": {
25-
"composer/composer": "^1.0",
26-
"phpunit/phpunit": "^5.2",
27-
"squizlabs/php_codesniffer": "^2.5"
25+
"composer/composer": "^2.0",
26+
"phpunit/phpunit": "^5.7",
27+
"squizlabs/php_codesniffer": "^2.9"
2828
}
2929
}

src/Plugin.php

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,35 @@ public function activate(Composer $composer, IOInterface $io)
3030
$this->io = $io;
3131
}
3232

33-
public function onPreAutoloadDump()
33+
private function getVendorDir()
3434
{
35-
$vendor_dir = str_replace('\'', '\\\'', realpath($this->composer->getConfig()->get('vendor-dir')));
36-
$base_dir = str_replace('\'', '\\\'', getcwd());
35+
return str_replace('\'', '\\\'', realpath($this->composer->getConfig()->get('vendor-dir')));
36+
}
37+
38+
private function getBaseDir()
39+
{
40+
return str_replace('\'', '\\\'', getcwd());
41+
}
42+
43+
private function getPath()
44+
{
45+
$vendor_dir = $this->getVendorDir();
3746

3847
if (0 === strpos(__DIR__, $vendor_dir) || strlen(__DIR__) - 4 === strpos(__DIR__, '/src')) {
3948
$path = __DIR__ . '/';
4049
} else {
4150
$path = $vendor_dir . '/hostnet/path-composer-plugin-lib/src/';
4251
}
4352

53+
return $path;
54+
}
55+
56+
public function onPreAutoloadDump()
57+
{
58+
$path = $this->getPath();
59+
$vendor_dir = $this->getVendorDir();
60+
$base_dir = $this->getBaseDir();
61+
4462
file_put_contents(
4563
$path . 'Path.php',
4664
<<<EOF
@@ -56,4 +74,13 @@ class Path
5674
EOF
5775
);
5876
}
77+
78+
public function deactivate(Composer $composer, IOInterface $io)
79+
{
80+
}
81+
82+
public function uninstall(Composer $composer, IOInterface $io)
83+
{
84+
unlink($this->getPath() . 'Path.php');
85+
}
5986
}

0 commit comments

Comments
 (0)