1616 */
1717class PharBuilder
1818{
19- private $ scanner ;
20-
2119 /** @var int @see \Phar::GZ, \Phar::BZ2 */
2220 private $ compressMode ;
2321
@@ -52,17 +50,17 @@ class PharBuilder
5250 'webIndex ' => null ,
5351
5452 // compress php code
55- 'compress ' => false ,
53+ // 'compress' => false,
5654
5755 'dirExclude ' => '#[\.git|tests]# ' ,
5856
5957 'fileInclude ' => [],
58+ 'fileExclude ' => [],
6059 'fileMatch ' => '#\.php# ' ,
6160 ];
6261
63- public function __construct (DirectoryScanner $ scanner , $ basedir )
62+ public function __construct ($ basedir )
6463 {
65- $ this ->scanner = $ scanner ;
6664 $ this ->basedir = $ basedir ;
6765 }
6866
@@ -89,25 +87,35 @@ public function setSignatureType($type)
8987 $ this ->signatureType = $ type ;
9088 }
9189
90+ /**
91+ * @param $key
92+ */
9293 public function setSignatureKey ($ key )
9394 {
9495 $ this ->key = $ key ;
9596 }
9697
98+ /**
99+ * @param string $directory
100+ */
97101 public function addDirectory ($ directory )
98102 {
99103 $ this ->directories [] = $ directory ;
100104 }
101105
106+ /**
107+ * @param $name
108+ */
102109 public function setAliasName ($ name )
103110 {
104111 $ this ->aliasName = $ name ;
105112 }
106113
107114 /**
108- * @param $filename
109- * @param $stub
110- * @throws \LogicException
115+ * @param string $filename
116+ * @param string $stub
117+ * @throws \RuntimeException
118+ * @throws \InvalidArgumentException
111119 * @throws \UnexpectedValueException
112120 * @throws \BadMethodCallException
113121 */
@@ -117,6 +125,14 @@ public function build($filename, $stub = null)
117125 unlink ($ filename );
118126 }
119127
128+ if (ini_get ('phar.readonly ' )) {
129+ throw new \RuntimeException ("The 'phar.readonly' is 'On', build phar must setting it 'Off' " );
130+ }
131+
132+ if (!$ this ->directories ) {
133+ throw new \RuntimeException ("Please setting the 'directories' want building directories " );
134+ }
135+
120136 $ aliasName = $ this ->aliasName ?: basename ($ filename );
121137 $ phar = new \Phar ($ filename , 0 , $ aliasName );
122138 $ phar ->startBuffering ();
@@ -140,7 +156,7 @@ public function build($filename, $stub = null)
140156 $ phar ->buildFromIterator ($ iterator , $ basedir );
141157 }
142158
143- if ($ this ->compressMode !== \Phar:: NONE ) {
159+ if ($ this ->compressMode !== null ) {
144160 $ phar ->compressFiles ($ this ->compressMode );
145161 }
146162
@@ -151,14 +167,14 @@ private function createStub($pharName)
151167 {
152168 // Stubs
153169// $phar->setStub($this->getStub());
154- $ stub = \Phar::createDefaultStub ($ this ->options ['cliIndex ' ], $ this ->options ['webIndex ' ]);
170+ return \Phar::createDefaultStub ($ this ->options ['cliIndex ' ], $ this ->options ['webIndex ' ]);
155171
156172 // 设置入口
157- return "<?php
158- Phar::mapPhar(' {$ pharName }');
159- require 'phar:// {$ pharName }/examples/app';
160- __HALT_COMPILER();
161- ?> " ;
173+ // return "<?php
174+ // Phar::mapPhar('{$pharName}');
175+ // require 'phar://{$pharName}/examples/app';
176+ // __HALT_COMPILER();
177+ /* ?>";*/
162178 }
163179
164180 /**
@@ -231,4 +247,20 @@ public function setKey($key)
231247
232248 return $ this ;
233249 }
250+
251+ /**
252+ * @return array
253+ */
254+ public function getOptions (): array
255+ {
256+ return $ this ->options ;
257+ }
258+
259+ /**
260+ * @param array $options
261+ */
262+ public function setOptions (array $ options )
263+ {
264+ $ this ->options = $ options ;
265+ }
234266}
0 commit comments