@@ -15,18 +15,18 @@ class DefaultDumpWriter implements DumpWriterInterface
1515 protected $ filename ;
1616
1717 /**
18- * Generated source
18+ * Command classes
1919 *
20- * @var string
20+ * @var string[]
2121 */
22- protected $ source ;
22+ protected $ commands = [] ;
2323
2424 /**
25- * Command classes
25+ * Boot scripts
2626 *
2727 * @var string[]
2828 */
29- protected $ commands = [];
29+ protected $ boot = [];
3030
3131 /**
3232 * Constructor
@@ -36,10 +36,6 @@ class DefaultDumpWriter implements DumpWriterInterface
3636 public function __construct (string $ filename )
3737 {
3838 $ this ->filename = $ filename ;
39- $ this ->source = sprintf (
40- '<?php%1$suse Imponeer \\ComposerCustomCommands \\ProxyCommand;%1$s%1$srequire_once(dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . "autoload.php");%1$s ' ,
41- PHP_EOL
42- );
4339 }
4440
4541 /**
@@ -50,11 +46,7 @@ public function __construct(string $filename)
5046 public function writeToFile (): bool
5147 {
5248 $ ret = $ this ->source . PHP_EOL ;
53- $ ret .= 'return [ ' . PHP_EOL ;
54- foreach ($ this ->commands as $ command ) {
55- $ ret .= str_repeat (' ' , 4 ) . 'class_exists( ' . json_encode ($ command ) . ') ? ' . ' new ProxyCommand( ' . $ command . '::class) : null, ' . PHP_EOL ;
56- }
57- $ ret .= ']; ' . PHP_EOL ;
49+ $ ret .= '<?php return ' . var_export (['commands ' => $ this ->commands , 'boot ' => $ this ->boot ], true ) . '; ' ;
5850
5951 return (bool )file_put_contents ($ this ->filename , $ ret , LOCK_EX );
6052 }
@@ -76,10 +68,6 @@ public function addCommands(array $commands): void
7668 */
7769 public function addBootScript (string $ bootScript ): void
7870 {
79- $ this ->source .= sprintf (
80- 'try {%2$s file_exists(%1$s) && include_once(%1$s);%2$s} catch ( \\Exception $ex) {%2$s}%2$s ' ,
81- json_encode ($ bootScript ),
82- PHP_EOL
83- );
71+ $ this ->boot [] = $ bootScript ;
8472 }
8573}
0 commit comments