@@ -56,12 +56,17 @@ function note(string $message): never
5656 note ('SECRETSPEC_FFI_LIB is set; skipping download. ' );
5757}
5858
59- // Map the running platform to the release target triple + library file name.
60- [$ target , $ libName ] = secretspec_target ();
59+ // Map the running platform to the release target triple; the library file name
60+ // comes from Native so the download target and the loader agree on one name.
61+ $ target = secretspec_target ();
6162if ($ target === null ) {
6263 note ('no prebuilt secretspec-ffi library for this platform; set '
6364 . 'SECRETSPEC_FFI_LIB or install the secretspec extension. ' );
6465}
66+ if (!class_exists (\Secretspec \Native::class)) {
67+ note ('the Secretspec classes are not autoloadable; run `composer install` first. ' );
68+ }
69+ $ libName = \Secretspec \Native::libraryFileName ();
6570
6671$ libDir = dirname (__DIR__ ) . '/lib ' ;
6772$ dest = $ libDir . '/ ' . $ libName ;
@@ -106,10 +111,10 @@ function note(string $message): never
106111exit (0 );
107112
108113/**
109- * @return array{0: ?string, 1: string} the release target triple ( or null if
110- * unsupported) and the platform library file name
114+ * The release target triple for the running platform, or null if no prebuilt
115+ * secretspec-ffi library is published for it.
111116 */
112- function secretspec_target (): array
117+ function secretspec_target (): ? string
113118{
114119 $ machine = strtolower (php_uname ('m ' ));
115120 $ isArm = in_array ($ machine , ['arm64 ' , 'aarch64 ' ], true );
@@ -118,25 +123,25 @@ function secretspec_target(): array
118123 switch (PHP_OS_FAMILY ) {
119124 case 'Linux ' :
120125 if ($ isX64 ) {
121- return [ 'x86_64-unknown-linux-gnu ' , ' libsecretspec_ffi.so ' ] ;
126+ return 'x86_64-unknown-linux-gnu ' ;
122127 }
123128 if ($ isArm ) {
124- return [ 'aarch64-unknown-linux-gnu ' , ' libsecretspec_ffi.so ' ] ;
129+ return 'aarch64-unknown-linux-gnu ' ;
125130 }
126131 break ;
127132 case 'Darwin ' :
128133 if ($ isArm ) {
129- return [ 'aarch64-apple-darwin ' , ' libsecretspec_ffi.dylib ' ] ;
134+ return 'aarch64-apple-darwin ' ;
130135 }
131136 break ;
132137 case 'Windows ' :
133138 if ($ isX64 ) {
134- return [ 'x86_64-pc-windows-msvc ' , ' secretspec_ffi.dll ' ] ;
139+ return 'x86_64-pc-windows-msvc ' ;
135140 }
136141 break ;
137142 }
138143
139- return [ null , '' ] ;
144+ return null ;
140145}
141146
142147/** The installed version of this package, or null in a dev/path checkout. */
@@ -163,11 +168,11 @@ function secretspec_installed_version(): ?string
163168/** GET a URL, returning the body or null on any failure. */
164169function secretspec_fetch (string $ url ): ?string
165170{
171+ // PHP's HTTP stream wrapper reads its options from the 'http' key for both
172+ // http:// and https:// URLs, so a single entry covers both.
166173 $ context = stream_context_create ([
167174 'http ' => ['method ' => 'GET ' , 'follow_location ' => 1 , 'timeout ' => 30 ,
168175 'header ' => 'User-Agent: secretspec-php-installer ' ],
169- 'https ' => ['method ' => 'GET ' , 'follow_location ' => 1 , 'timeout ' => 30 ,
170- 'header ' => 'User-Agent: secretspec-php-installer ' ],
171176 ]);
172177 $ body = @file_get_contents ($ url , false , $ context );
173178
0 commit comments