Use library that is saved via composer - php

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!

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.

Google login page PHP without composer

I'm stuck with building a Google login page without composer.
What i have so far is:
require_once 'google-api-php-client-1-master/src/Google/autoload.php';
define('GOOGLE_CLIENT_ID', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
define('GOOGLE_CLIENT_SECRET', 'xxxxxxxxxxxxxxxxxxxxxxxx');
define('GOOGLE_REDIRECT_URL', 'https://url to page after login');
$gClient = new Google_Client();
$gClient->setApplicationName('Inlog PROJECTNAME');
$gClient->setClientId(GOOGLE_CLIENT_ID);
$gClient->setClientSecret(GOOGLE_CLIENT_SECRET);
$gClient->setRedirectUri(GOOGLE_REDIRECT_URL);
$google_oauthV2 = new Google_Oauth2Service($gClient);
I downloaded this library from Github and included it as above, i saw this error:
Fatal error: Uncaught Error: Class 'Google_Oauth2Service' not found in /home/xxxxxxx/domain/xxxxxxxx/public_html/includes/google-login.config.php:46 Stack trace: #0 /home/xxxxxxx/domains/xxxxxxxxxx/public_html/google-login.php(5): require_once() #1 {main} thrown in /home/xxxxxxx/domains/xxxxxxxxxxx/public_html/includes/google-login.config.php on line 46
How can i fix this without the use off composer?? Thanks in advance!!

Error in creating database in MongoDB using composer

I'm trying to create a database using composer. I've demo.php as the main file and running the code on localhost.
Error message :
Fatal error: Uncaught
MongoDB\Driver\Exception\ConnectionTimeoutException: No suitable
servers found (serverSelectionTryOnce set): [socket timeout calling
ismaster on '127.0.0.1:27017'] in
C:\xampp\htdocs\phpmongodb\vendor\mongodb\mongodb\src\Database.php:201
Stack trace: #0
C:\xampp\htdocs\phpmongodb\vendor\mongodb\mongodb\src\Database.php(201):
MongoDB\Driver\Manager->selectServer(Object(MongoDB\Driver\ReadPreference))
1 C:\xampp\htdocs\phpmongodb\demo.php(8): MongoDB\Database->createCollection('emplcollection') 2 {main} thrown
in C:\xampp\htdocs\phpmongodb\vendor\mongodb\mongodb\src\Database.php
on line 201
What could be the reason for this?
My code:
<?php
require 'vendor/autoload.php';
$client = new MongoDB\Client;
$companydb = $client->companydb;
$result1 = $companydb->createCollection('emplcollection');
var_dump(result1);
?>

PHP Fatal error: Uncaught Error: Class 'Symfony\Component\Console\Application' not found

I am trying to create a simple CLI app with PHP but I keep getting:
PHP Fatal error: Uncaught Error: Class 'Symfony\Component\Console\Application' not found in /Applications/MAMP/htdocs/newcli/dan.php:6
Stack trace:
#0 {main}
thrown in /Applications/MAMP/htdocs/newcli/dan.php on line 6
Fatal error: Uncaught Error: Class 'Symfony\Component\Console\Application' not found in /Applications/MAMP/htdocs/newcli/dan.php:6
Stack trace:
#0 {main}
thrown in /Applications/MAMP/htdocs/newcli/dan.php on line 6
What am I doing wrong? My PHP version: PHP 7.1.0RC6 (cli) (built: Nov 9 2016 04:45:59) ( NTS )
dan.php:
#! usr/bin/env php
<?php use Symfony\Component\Console\Application;
require 'vendor/autoload.php';
$app = new Application('Task App', '1.0');
$app->add(new Acme\ShowCommand());
$app->run();
The use statement must be placed after the require 'vendor/autoload.php'
#! usr/bin/env php
<?php
require 'vendor/autoload.php';
use Symfony\Component\Console\Application;
$app = new Application('Task App', '1.0');
$app->add(new Acme\ShowCommand());
$app->run();
Some classes can be absent in your vendor. So, it can be resolved by a composer install.

Composer.json Installation On AWS Elastic Beanstalk

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';

Categories