1010class PluginPackager {
1111
1212 private string $ projectRoot ;
13+ private string $ straussVersion = '' ;
1314
1415 /** @var callable */
1516 private $ logger ;
@@ -30,6 +31,7 @@ public function __construct( ?string $projectRoot = null, ?callable $logger = nu
3031 */
3132 public function package ( ?string $ outputDir = null , array $ options = [] ) :string {
3233 $ options = $ this ->resolveOptions ( $ options );
34+ $ this ->straussVersion = $ this ->resolveStraussVersion ( $ options );
3335 $ targetDir = $ this ->resolveOutputDirectory ( $ outputDir );
3436 $ this ->log ( sprintf ( 'Packaging Shield plugin to: %s ' , $ targetDir ) );
3537
@@ -46,7 +48,7 @@ public function package( ?string $outputDir = null, array $options = [] ) :strin
4648 'install ' ,
4749 '--no-interaction ' ,
4850 '--prefer-dist ' ,
49- '--optimize-autoloader '
51+ // '--optimize-autoloader'
5052 ] ),
5153 $ this ->projectRoot
5254 );
@@ -58,7 +60,7 @@ public function package( ?string $outputDir = null, array $options = [] ) :strin
5860 'install ' ,
5961 '--no-interaction ' ,
6062 '--prefer-dist ' ,
61- '--optimize-autoloader '
63+ // '--optimize-autoloader'
6264 ] ),
6365 $ this ->projectRoot .'/src/lib '
6466 );
@@ -245,7 +247,7 @@ private function log( string $message ) :void {
245247 }
246248
247249 /**
248- * @return array<string,bool >
250+ * @return array<string,mixed >
249251 */
250252 private function resolveOptions ( array $ options ) :array {
251253 $ defaults = [
@@ -255,11 +257,26 @@ private function resolveOptions( array $options ) :array {
255257 'npm_build ' => true ,
256258 'directory_clean ' => true ,
257259 'skip_copy ' => false ,
260+ 'strauss_version ' => null ,
258261 ];
259262
260263 return array_replace ( $ defaults , array_intersect_key ( $ options , $ defaults ) );
261264 }
262265
266+ private function resolveStraussVersion ( array $ options ) :string {
267+ $ fromOptions = $ options [ 'strauss_version ' ] ?? null ;
268+ if ( is_string ( $ fromOptions ) && $ fromOptions !== '' ) {
269+ return ltrim ( $ fromOptions , "v \t\n\r\0\x0B" );
270+ }
271+
272+ $ env = getenv ( 'SHIELD_STRAUSS_VERSION ' );
273+ if ( is_string ( $ env ) && $ env !== '' ) {
274+ return ltrim ( $ env , "v \t\n\r\0\x0B" );
275+ }
276+
277+ return self ::FALLBACK_STRAUSS_VERSION ;
278+ }
279+
263280 /**
264281 * Parse .gitattributes and return list of export-ignore patterns
265282 * This makes .gitattributes the single source of truth for package contents
@@ -548,7 +565,7 @@ private function installComposerDependencies( string $targetDir ) :void {
548565 '--no-dev ' ,
549566 '--no-interaction ' ,
550567 '--prefer-dist ' ,
551- '--optimize-autoloader ' ,
568+ // '--optimize-autoloader',
552569 '--quiet '
553570 ] ),
554571 $ libDir
@@ -558,18 +575,21 @@ private function installComposerDependencies( string $targetDir ) :void {
558575 $ this ->log ( '' );
559576 }
560577
561- private const STRAUSS_VERSION = '0.19.4 ' ;
562- private const STRAUSS_DOWNLOAD_URL = 'https://github.com/BrianHenryIE/strauss/releases/download/0.19.4/strauss.phar ' ;
578+ private const FALLBACK_STRAUSS_VERSION = '0.19.4 ' ;
563579
564580 /**
565581 * Download Strauss phar file for namespace prefixing
566582 * @throws RuntimeException if download fails with detailed error message
567583 */
568584 private function downloadStraussPhar ( string $ targetDir ) :void {
569- $ this ->log ( sprintf ( 'Downloading Strauss v%s... ' , self :: STRAUSS_VERSION ) );
585+ $ this ->log ( sprintf ( 'Downloading Strauss v%s... ' , $ this -> straussVersion ) );
570586
571587 $ libDir = Path::join ( $ targetDir , 'src/lib ' );
572588 $ targetPath = Path::join ( $ libDir , 'strauss.phar ' );
589+ $ downloadUrl = sprintf (
590+ 'https://github.com/BrianHenryIE/strauss/releases/download/%s/strauss.phar ' ,
591+ $ this ->straussVersion
592+ );
573593
574594 // Check if allow_url_fopen is enabled
575595 if ( !ini_get ( 'allow_url_fopen ' ) ) {
@@ -579,7 +599,7 @@ private function downloadStraussPhar( string $targetDir ) :void {
579599 'WHY: The PHP setting "allow_url_fopen" is disabled, which prevents PHP from downloading files from URLs. ' .
580600 'HOW TO FIX: Enable allow_url_fopen in your php.ini file by setting "allow_url_fopen = On", ' .
581601 'or contact your system administrator to enable this setting. ' .
582- 'Alternatively, you can manually download strauss.phar from ' .self :: STRAUSS_DOWNLOAD_URL .' ' .
602+ 'Alternatively, you can manually download strauss.phar from ' .$ downloadUrl .' ' .
583603 'and place it in the package src/lib directory. '
584604 );
585605 }
@@ -602,7 +622,7 @@ private function downloadStraussPhar( string $targetDir ) :void {
602622 error_clear_last ();
603623
604624 // Attempt to download the file
605- $ content = @file_get_contents ( self :: STRAUSS_DOWNLOAD_URL , false , $ context );
625+ $ content = @file_get_contents ( $ downloadUrl , false , $ context );
606626
607627 if ( $ content === false ) {
608628 $ lastError = error_get_last ();
@@ -617,7 +637,7 @@ private function downloadStraussPhar( string $targetDir ) :void {
617637 '(3) Firewall or proxy blocking the connection, (4) SSL certificate verification failure. ' .
618638 'HOW TO FIX: Check your internet connection and try again. If the problem persists, ' .
619639 'you can manually download strauss.phar from the URL above and place it at: %s ' ,
620- self :: STRAUSS_DOWNLOAD_URL ,
640+ $ downloadUrl ,
621641 $ errorMessage ,
622642 $ targetPath
623643 )
@@ -632,8 +652,8 @@ private function downloadStraussPhar( string $targetDir ) :void {
632652 'WHY: This usually indicates a server-side issue or the release file was not found. ' .
633653 'HOW TO FIX: Verify that Strauss version %s exists at the download URL. ' .
634654 'You can manually download strauss.phar and place it at: %s ' ,
635- self :: STRAUSS_DOWNLOAD_URL ,
636- self :: STRAUSS_VERSION ,
655+ $ downloadUrl ,
656+ $ this -> straussVersion ,
637657 $ targetPath
638658 )
639659 );
@@ -690,7 +710,7 @@ private function downloadStraussPhar( string $targetDir ) :void {
690710 'HOW TO FIX: Delete the empty file and try running the packaging again. ' .
691711 'If the problem persists, manually download from: %s ' ,
692712 $ targetPath ,
693- self :: STRAUSS_DOWNLOAD_URL
713+ $ downloadUrl
694714 )
695715 );
696716 }
0 commit comments