Skip to content

Commit a28e453

Browse files
author
Christopher Pitt
committed
Make compatible with composer plugin 2
1 parent 374e5cc commit a28e453

File tree

3 files changed

+41
-29
lines changed

3 files changed

+41
-29
lines changed

source/Composer/Plugin.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ public function activate(Composer $composer, IOInterface $io)
3535
$this->composer = $composer;
3636
$this->io = $io;
3737

38-
$composer
39-
->getInstallationManager()
40-
->addInstaller(new Installer($io, $composer));
38+
$composer->getInstallationManager()->addInstaller(new Installer($io, $composer));
4139
}
4240

4341
/**
@@ -48,9 +46,7 @@ public function activate(Composer $composer, IOInterface $io)
4846
public static function getSubscribedEvents()
4947
{
5048
return [
51-
"pre-autoload-dump" => [
52-
"onPreAutoloadDump",
53-
],
49+
"pre-autoload-dump" => ["onPreAutoloadDump"],
5450
];
5551
}
5652

@@ -77,9 +73,7 @@ public function onPreAutoloadDump(Event $event)
7773

7874
$directory = new RecursiveDirectoryIterator($basePath);
7975

80-
$files = new RecursiveIteratorIterator(
81-
$directory, RecursiveIteratorIterator::SELF_FIRST
82-
);
76+
$files = new RecursiveIteratorIterator($directory, RecursiveIteratorIterator::SELF_FIRST);
8377

8478
foreach ($files as $file) {
8579
if (stripos($file, "{$basePath}/vendor") === 0) {
@@ -93,9 +87,7 @@ public function onPreAutoloadDump(Event $event)
9387
$pre = $file->getPathname();
9488
$php = preg_replace("/pre$/", "php", $pre);
9589

96-
compile(
97-
$pre, $php, $format = true, $comment = false
98-
);
90+
compile($pre, $php, ($format = true), ($comment = false));
9991
}
10092
} else {
10193
if (file_exists($lockPath)) {
@@ -147,4 +139,12 @@ private function shouldOptimize(Event $event)
147139

148140
return false;
149141
}
142+
143+
public function deactivate(Composer $composer, IOInterface $io)
144+
{
145+
}
146+
147+
public function uninstall(Composer $composer, IOInterface $io)
148+
{
149+
}
150150
}

source/expanders.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
use Yay\Engine;
55
use Yay\TokenStream;
66

7-
function trim(TokenStream $stream, Engine $engine): TokenStream {
7+
function trim(TokenStream $stream, Engine $engine): TokenStream
8+
{
89
return \Pre\Plugin\Expanders\trim($stream, $engine);
910
}
1011
}
@@ -13,13 +14,13 @@ function trim(TokenStream $stream, Engine $engine): TokenStream {
1314
use Yay\Engine;
1415
use Yay\TokenStream;
1516

16-
function _stream(string $source, Engine $engine): TokenStream {
17-
return TokenStream::fromSource(
18-
$engine->expand($source, "", Engine::GC_ENGINE_DISABLED)
19-
);
17+
function _stream(string $source, Engine $engine): TokenStream
18+
{
19+
return TokenStream::fromSource($engine->expand($source, "", Engine::GC_ENGINE_DISABLED));
2020
}
2121

22-
function trim(TokenStream $stream, Engine $engine): TokenStream {
22+
function trim(TokenStream $stream, Engine $engine): TokenStream
23+
{
2324
$stream = \trim($stream);
2425
return _stream($stream, $engine);
2526
}

source/functions.php

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
namespace Pre\Plugin;
44

55
if (!function_exists("\\Pre\\Plugin\\find")) {
6-
function find($file, $iterations = 10, $prefix = __DIR__) {
6+
function find($file, $iterations = 10, $prefix = __DIR__)
7+
{
78
$folder = "../";
89

910
if ($prefix) {
@@ -23,14 +24,16 @@ function find($file, $iterations = 10, $prefix = __DIR__) {
2324
}
2425

2526
if (!function_exists("\\Pre\\Plugin\\base")) {
26-
function base() {
27+
function base()
28+
{
2729
$vendor = find("vendor");
2830
return realpath("{$vendor}/../");
2931
}
3032
}
3133

3234
if (!function_exists("\\Pre\\Plugin\\instance")) {
33-
function instance() {
35+
function instance()
36+
{
3437
static $instance = null;
3538

3639
if ($instance === null) {
@@ -42,56 +45,64 @@ function instance() {
4245
}
4346

4447
if (!function_exists("\\Pre\\Plugin\\process")) {
45-
function process($from, $to = null, $format = true, $comment = true) {
48+
function process($from, $to = null, $format = true, $comment = true)
49+
{
4650
$instance = instance();
4751
return $instance->process($from, $to, $format, $comment);
4852
}
4953
}
5054

5155
if (!function_exists("\\Pre\\Plugin\\compile")) {
52-
function compile($from, $to, $format = true, $comment = true) {
56+
function compile($from, $to, $format = true, $comment = true)
57+
{
5358
$instance = instance();
5459
return $instance->compile($from, $to, $format, $comment);
5560
}
5661
}
5762

5863
if (!function_exists("\\Pre\\Plugin\\parse")) {
59-
function parse($code) {
64+
function parse($code)
65+
{
6066
$instance = instance();
6167
return $instance->parse($code);
6268
}
6369
}
6470

6571
if (!function_exists("\\Pre\\Plugin\\format")) {
66-
function format($code) {
72+
function format($code)
73+
{
6774
$instance = instance();
6875
return $instance->format($code);
6976
}
7077
}
7178

7279
if (!function_exists("\\Pre\\Plugin\\addMacro")) {
73-
function addMacro($macro) {
80+
function addMacro($macro)
81+
{
7482
$instance = instance();
7583
return $instance->addMacro($macro);
7684
}
7785
}
7886

7987
if (!function_exists("\\Pre\\Plugin\\removeMacro")) {
80-
function removeMacro($macro) {
88+
function removeMacro($macro)
89+
{
8190
$instance = instance();
8291
return $instance->removeMacro($macro);
8392
}
8493
}
8594

8695
if (!function_exists("\\Pre\\Plugin\\addCompiler")) {
87-
function addCompiler($compiler, $callable) {
96+
function addCompiler($compiler, $callable)
97+
{
8898
$instance = instance();
8999
return $instance->addCompiler($compiler, $callable);
90100
}
91101
}
92102

93103
if (!function_exists("\\Pre\\Plugin\\removeCompiler")) {
94-
function removeCompiler($compiler) {
104+
function removeCompiler($compiler)
105+
{
95106
$instance = instance();
96107
return $instance->removeCompiler($compiler);
97108
}

0 commit comments

Comments
 (0)