1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Composer plugin for config assembling |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/hiqdev/composer-config-plugin |
6
|
|
|
* @package composer-config-plugin |
7
|
|
|
* @license BSD-3-Clause |
8
|
|
|
* @copyright Copyright (c) 2016-2018, HiQDev (http://hiqdev.com/) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace hiqdev\composer\config; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Output Dir class. |
15
|
|
|
* |
16
|
|
|
* @author Andrii Vasyliev <[email protected]> |
17
|
|
|
*/ |
18
|
|
|
class OutputDir |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var string path to output assembled configs |
22
|
|
|
*/ |
23
|
|
|
protected $dir; |
24
|
|
|
|
25
|
|
|
public function __construct($outputDir = null) |
26
|
|
|
{ |
27
|
|
|
$this->setOutputDir($outputDir); |
28
|
|
|
|
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function setOutputDir($outputDir) |
32
|
|
|
{ |
33
|
|
|
var_dump(__METHOD__, $outputDir);die; |
|
|
|
|
34
|
|
|
$this->outputDir = $outputDir ?: static::findOutputDir(); |
|
|
|
|
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function getOutputDir(): string |
38
|
|
|
{ |
39
|
|
|
return $this->outputDir; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Returns default output dir. |
44
|
|
|
* @param string $vendor path to vendor dir |
45
|
|
|
* @return string |
46
|
|
|
*/ |
47
|
|
|
public static function findOutputDir($vendor = null) |
48
|
|
|
{ |
49
|
|
|
if ($vendor) { |
50
|
|
|
$dir = $vendor . '/hiqdev/' . basename(dirname(__DIR__)); |
51
|
|
|
} else { |
52
|
|
|
$dir = \dirname(__DIR__); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
return $dir . static::OUTPUT_DIR_SUFFIX; |
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Returns full path to assembled config file. |
60
|
|
|
* @param string $filename name of config |
61
|
|
|
* @param string $vendor path to vendor dir |
62
|
|
|
* @return string absolute path |
63
|
|
|
*/ |
64
|
|
|
public static function path($filename, $vendor = null) |
65
|
|
|
{ |
66
|
|
|
return static::findOutputDir($vendor) . DIRECTORY_SEPARATOR . $filename . '.php'; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function getOutputPath($name) |
70
|
|
|
{ |
71
|
|
|
return $this->outputDir . DIRECTORY_SEPARATOR . $name . '.php'; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.