Skip to content

Commit e4b55a7

Browse files
madwingsBrainMaestro
authored andcommitted
Pass composer.json dir (#13)
Signed-off-by: Stiliyan Ivanov <[email protected]>
1 parent b3dcff8 commit e4b55a7

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

Diff for: cghooks

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/usr/bin/env php
22
<?php
3-
3+
$dir = getcwd();
44
if (is_file($autoload = __DIR__ . '/vendor/autoload.php')) {
5-
require $autoload;
5+
require_once $autoload;
66
} elseif (is_file($autoload = __DIR__ . '/../../autoload.php')) {
7-
require $autoload;
7+
require_once $autoload;
88
} else {
99
fwrite(STDERR,
1010
'You must set up the project dependencies, run the following commands:' . PHP_EOL .
@@ -24,7 +24,7 @@ use Symfony\Component\Console\Application;
2424

2525
$application = new Application('Composer Git Hooks', 'v2.2.0');
2626

27-
$hooks = Hook::getValidHooks();
27+
$hooks = Hook::getValidHooks($dir);
2828
$application->add(new AddCommand($hooks));
2929
$application->add(new UpdateCommand($hooks));
3030
$application->add(new RemoveCommand($hooks));

Diff for: src/Hook.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ class Hook
99
/**
1010
* Get scripts section of the composer config file.
1111
*
12+
* @param $dir string dir where to look for composer.json
13+
*
1214
* @return array
1315
*/
14-
public static function getValidHooks()
16+
public static function getValidHooks($dir)
1517
{
16-
$contents = file_get_contents('composer.json');
18+
$contents = file_get_contents("{$dir}/composer.json");
1719
$json = json_decode($contents, true);
1820
$hooks = array_merge(
1921
isset($json['scripts']) ? $json['scripts'] : [],

0 commit comments

Comments
 (0)