Composer.json Installation On AWS Elastic Beanstalk - php

I read in the AWS Elastic Beanstalk documentation that you can simply include the composer.json file in the root of your package and it will install an application and it's dependencies:
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_PHP.container.html#php-configuration-composer
{
"require": {
"coinbase/coinbase": "~2.0"
}
}
Then I created a PHP file with the following to test if it worked:
error_reporting(E_ALL);
ini_set('display_errors', 1);
$apiKey = 'workingkey';
$apiSecret = 'workingkey';
use Coinbase\Wallet\Client;
use Coinbase\Wallet\Configuration;
$configuration = Configuration::apiKey($apiKey, $apiSecret);
$client = Client::create($configuration);
$buyPrice = $client->getBuyPrice('BTC-USD');
echo $buyPrice;
Unfortunately it gives the following error:
Fatal error: Uncaught Error: Class 'Coinbase\Wallet\Configuration' not found in /var/app/current/test.php:20 Stack trace: #0 {main} thrown in /var/app/current/test.php on line 20
I've tried everything I can think of to get this to work. What am I missing here?

You missed to include the autoloader of composer.
Add this at the beginning of your file and it should work:
require __DIR__.'/vendor/autoload.php';

Related

PHP Fatal error: Uncaught Error: Class 'Adldap\Adldap\Configuration\DomainConfiguration'

Fatal error: Uncaught Error: Class 'Adldap\Adldap\Configuration\DomainConfiguration' not found in /var/www/html/accounts/ad/accounts.php:6 Stack trace: #0 /var/www/html/accounts/ad.php(15): include() #1 /var/www/html/accounts/index.php(72): include('/var/www/html/a...') #2 {main} thrown in /var/www/html/accounts/ad/accounts.php on line 6
accounts.php =
<?php
require_once __DIR__.'/../../vendor/autoload.php';
use Adldap\Adldap;
use Adldap\Utilities;
$config = new Adlap\Configuration\DomainConfiguration([
'hosts' => [
'XXXXXXXXXX',
],
]);
$ad = new \Adldap\Adldap();
$ad->addProvider($config);
try {
$provider = $ad->connect();
Make sure is exits Adldap\Adldap php package also for this you need install composer tool. . If it doesn't exits then add name of package to composer.json like this:
composer require vendor/package
For show installed packages enter:
composer show -i
After it you can use package easly.

Composer install error - jms-security-extra-bundle

I'm in the process of trying to upgrade a PHP application from Symfony 2.x to 3.x. I've managed to resolve dependency issues for the various packages we're using and all the packages download and install. However when the composer install triggers a cache clear it errors out with the following:
[RuntimeException]
An error occurred when executing the "'cache:clear --no-warmup'" command:
Warning: Uncaught Symfony\Component\Debug\Exception\ContextErrorException: Warning: require_once(/home/vagrant/code/symfony/vendor/jms/security-extr
a-bundle/Tests/Functional/../../vendor/autoload.php): failed to open stream: No such file or directory in /home/vagrant/code/symfony/vendor/jms/secu
rity-extra-bundle/Tests/Functional/AppKernel.php:5
Stack trace:
#0 /home/vagrant/code/symfony/vendor/jms/security-extra-bundle/Tests/Functional/AppKernel.php(5): require_once()
#1 /home/vagrant/code/symfony/vendor/symfony/symfony/src/Symfony/Component/Debug/FatalErrorHandler/ClassNotFoundFatalErrorHandler.php(191): require_
once('/home/vagrant/c...')
#2 /home/vagrant/code/symfony/vendor/symfony/symfony/src/Symfony/Component/Debug/FatalErrorHandler/ClassNotFoundFatalErrorHandler.php(145): Symfony\
Component\Debug\FatalErrorHandler\ClassNotFoundFatalErrorHandler->convertFileToClass('/home/vagrant/c...', '/home/vagrant/c...', 'JMS\\SecurityExt..
.')
#3 /home/vagrant/code/symfony/vendor/symfony/symfony/src/Symfony/Component/Debug/Fata in /home/vagrant/code/symfony/vendor/jms/security-extra-bundle
/Tests/Functional/AppKernel.php on line 5
Fatal error: Symfony\Component\Debug\FatalErrorHandler\ClassNotFoundFatalErrorHandler::main(): Failed opening required '/home/vagrant/code/symfony/v
endor/jms/security-extra-bundle/Tests/Functional/../../vendor/autoload.php' (include_path='.:/usr/share/php') in /home/vagrant/code/symfony/vendor/j
ms/security-extra-bundle/Tests/Functional/AppKernel.php on line 5
The file it's referring to has these lines at the top:
<?php
namespace JMS\SecurityExtraBundle\Tests\Functional;
require_once __DIR__.'/../../vendor/autoload.php';
There is no autoload.php at that path. I suspect that this file is being autoloaded when it shouldn't be but I'm not sure how to resolve this.
I have compared the contents of the /vendor/jms/security-extra-bundle/Tests/Functional/AppKernel.php file to another Symfony 3 project that we have and it's exactly the same so this leads me to think it's even more likely that this file is being autoloaded when it shouldn't be.
What can I do to resolve this and get past the cache:clear --no-warmup command?
I have now resolved this. I had originally copied bin/console from another Symfony 3 project. It seems however that the correct approach was to move the existing app/console to the bin/console path and update the include paths to correctly reference the bootstrap.php.cache file in ../var/ and the autoload.php and AppKernel.php in ../app. The whole bin/console file now looks like this:
#!/usr/bin/env php
<?php
// if you don't want to setup permissions the proper way, just uncomment the following PHP line
// read http://symfony.com/doc/current/book/installation.html#configuration-and-setup for more information
//umask(0000);
set_time_limit(0);
require_once __DIR__.'/../var/bootstrap.php.cache';
require_once __DIR__.'/../app/autoload.php';
require_once __DIR__.'/../app/AppKernel.php';
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Debug\Debug;
$input = new ArgvInput();
$env = $input->getParameterOption(array('--env', '-e'), getenv('SYMFONY_ENV') ?: 'dev');
$debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(array('--no-debug', '')) && $env !== 'prod';
if ($debug) {
Debug::enable();
}
$kernel = new AppKernel($env, $debug);
$application = new Application($kernel);
$application->run($input);

composer can not find classes and load them

I am using a Dropbox api package and installed it with Composer.When I try to use classes that gives me a fatal error that can not find classes.
This is my composer.json
{
"require": {
"kunalvarma05/dropbox-php-sdk": "^0.2.1"
}
}
This is my php file
use Kunnu\Dropbox\Dropbox;
use Kunnu\Dropbox\DropboxApp;
$app = new DropboxApp("client_id", "client_", 'access_token');
//Configure Dropbox service
$dropbox = new Dropbox($app);
//Get File Metadata
$fileMetadata = $dropbox->getMetadata("/helloworld.txt");
//File Name
// $fileMetadata->getName();
printf($fileMetadata->getName());
My php version is 7.2.4 and the error is:
Fatal error: Uncaught Error: Class 'Kunnu\Dropbox\DropboxApp' not found in D:\MeHDi\Projects\DropBox Api\Upload.php:6
Stack trace:
#0 {main}
thrown in D:\MeHDi\Projects\DropBox Api\Upload.php on line 6
Have you remembered to import composers autoload file using require "path/to/vendor/autoload.php";
This is required in order to initialize and use the different composer libraries. Remember to change the filepath to where your vendor/autoload.php file is located.

Use library that is saved via composer

I am trying to run the following script:
<?php
use Goutte\Client;
$client = new Client();
$crawler = $client->request('GET', 'https://www.symfony.com/blog/');
print($crawler);
My composer.json file looks like the following:
{
"require": {
"fabpot/goutte": "^3.2"
}
}
However, I get the following error:
Fatal error: Uncaught Error: Class 'Goutte\Client' not found in /home/ubuntu/workspace/src/t01-makeRequests.php:5
Stack trace:
#0 {main}
thrown in /home/ubuntu/workspace/src/t01-makeRequests.php on line 5
Any suggestions, how to load the library correctly in my script?
I appreciate your replies!

Setting up php selenium test

i am trying to open firefox as the example explains herehttps://github.com/facebook/php-webdriver/blob/community/example.php with the following code:
<?php
namespace Facebook\WebDriver;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
require_once 'C:\Users\alex\vendor\autoload.php';
$host = 'http://localhost:44441/wd/hub'; // i am running on 44441
$capabilities = DesiredCapabilities::firefox();
$driver = RemoteWebDriver::create($host, $capabilities, 5000);
?>
my composer composer.json at \alex\vendor\ looks like this:
// autoload.php #generated by Composer
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit95fa64adf2a94f75qbb05d3ee5a8af4e::getLoader();
my composer.json looks like this:
{
"require": {
"facebook/graph-sdk": "^5.6"
}
}
and my error is:
PHP Fatal error: Uncaught Error: Class
'Facebook\WebDriver\Remote\DesiredCapabilities' not found in
C:\Users\alex\Desktop\php-webdriver-community\hello.php:11
Stack trace:
#0 {main}
thrown in C:\Users\akal\Desktop\php-webdriver-community\hello.php on line 11
[Finished in 0.0s]
can anyone help?
To use the Facebook web driver, you need to install it using something like...
php composer.phar require facebook/webdriver
(From https://github.com/facebook/php-webdriver#installation )
In the project I use it, this includes a line in the composer.json...
"facebook/webdriver" : "^1.4"
and not the line you have with the graph-sdk

Categories