I am attempting to use https://github.com/amzn/amazon-instant-access-sdk-php for amazon instant access via php. I am not super familiar with phar files; but am starting to figure it out.
I included https://github.com/amzn/amazon-instant-access-sdk-php/blob/master/phar-stub.php in a file as shown below. (Modified a bit as I renamed phar file)
Phar::mapPhar('amazon-instant-access-sdk-php.phar');
require_once 'phar://amazon-instant-access-sdk-php.phar/vendor/symfony/class-loader/Symfony/Component/ClassLoader/UniversalClassLoader.php';
$classLoader = new Symfony\Component\ClassLoader\UniversalClassLoader();
$classLoader->registerNamespaces(array(
'Amazon' => 'phar://amazon-instant-access-sdk-php.phar/src',
'Psr' => 'phar://amazon-instant-access-sdk-php.phar/vendor/psr/log',
'Monolog' => 'phar://amazon-instant-access-sdk-php.phar/vendor/monolog/monolog/src'
));
$classLoader->register();
return $classLoader;
__HALT_COMPILER();
Then when I do in another file:
require_once('amazon-instant-access-phar-stub.php');
I get error:
Fatal error: Uncaught exception 'PharException' with message 'internal corruption of phar "/Applications/MAMP/htdocs/phppos/amazon-instant-access-phar-stub.php" (truncated manifest at stub end)' in /Applications/MAMP/htdocs/phppos/amazon-instant-access-phar-stub.php:17 Stack trace: #0 /Applications/MAMP/htdocs/phppos/amazon-instant-access-phar-stub.php(17): Phar::mapPhar('amazon-instant-...') #1 /Applications/MAMP/htdocs/phppos/amazon_link_account.php(3): require_once('/Applications/M...') #2 {main} thrown in /Applications/MAMP/htdocs/phppos/amazon-instant-access-phar-stub.php on line 17
I have tried re-downloading phar file and running different versions of php (5.3, 5.6)
I am not sure what is causing this error.
You could directly download the .phar file from the release.
If you have the .phar file, you don't need the source code from github. The source code on github is used to compile the .phar file.
In your php code, you could do something like this:
<?php
//import the phar file directly like you did
require_once('amazon-instant-access-sdk-php.phar’);
//before you initiate the class, you need to use the right name space:
use Amazon\InstantAccess\Signature as signature;
$credentialStore = new signature\CredentialStore();
?>
This one will work.
If you want to check exactly what's in the .phar file, you could extract it:
php -r '$phar = new Phar("amazon-instant-access-sdk-php.phar"); $phar->extractTo("/tmp/phar/");'
then you could browse the /tmp/phar/ for all the files in the .phar.