Installing Composer with autoload.php and use Aws\* says Class not found - php

I'm running my php in cli under my user.
I have installed composer and autoloader.php does exist. Under vendor folders and file have been downloaded (autoload.php aws, bin, composer, guzzlehttp, mtdowling and psr)
Now in my php code I do:
// Include the SDK using the Composer autoloader
require 'vendor/autoload.php';
use Aws\Route53\Route53Client;
use Aws\Common\Credentials\Credentials;
$credentials = new Credentials('KEY', 'SECRETKEY');
$client = Route53Client::factory(array(
'credentials' => $credentials
));
When I run the script I get: PHP Fatal error: Class 'Credentials' not found in /home/user/updatedns.php on line 15
I tried running it a sudo also (in case it needs to write to the directory) and still get this error.

Just found out that use Aws\Common\Credentials\Credentials; is now under use Aws\Credentials\Credentials;

Related

Class not found exception in PHP from composer

I am trying to include a package from composer, but I am receiving a class not found error.
I have tried the below possibilities.
$supermeteor = new \Supermeteor\Supermeteor('XXXXXXXX');
and
use Supermeteor\Supermeteor;
$supermeteor = new Supermeteor('xxxxxxxx');
Packages composer.json:
"psr-4": {
"Supermeteor\\": ""
}
Packages namespace :
namespace Supermeteor;
Packages class name :
class Supermeteor() {}
Error message
Uncaught Error: Class 'Supermeteor\Supermeteor' not found in
C:\path\to\my\file.php:16
I just tested your package locally, and it seems to work fine for me using the same code as you provided in your question. This is how I tested it.
1. Create a new project
Create a new directory on your computer.
2. Add the package to a new project using Composer
Locate your new directory on the command line and add the package to your projects autoloader by running the below composer command.
composer require supermeteor/sdk-php
3. Use the package
Create an index.php file in the same directory as your composer.json and add the below code.
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Supermeteor\Supermeteor;
$supermeteor = new Supermeteor("xxx");
4. Test the results
In the terminal window start a new php server to serve your project.
php -S localhost:8089
Now access the site via your browser at http://localhost:8089.

Calling Flysystem, why do I get PHP Fatal error: Class 'League\Flysystem\Adapter\Local' not found?

I try to run Flysystem's basic example code for the Local adapter and get a Class 'League\Flysystem\Adapter\Local' not found error. This is my process:
version check:
php -v
PHP 5.5.9-1ubuntu4.23 (cli) (built: Feb 8 2018 21:59:47)
install Flysystem:
composer require league/flysystem
output shows I'm up-to-date (this is my 2nd time running it):
Using version ^1.0 for league/flysystem
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files
now there's a vendor folder in web root. And within ./web/vendor/league/flysystem/src/Adapter$ are these files:
AbstractAdapter.php
AbstractFtpAdapter.php
CanOverwriteFiles.php
Ftpd.php
Ftp.php
Local.php
NullAdapter.php
Polyfill/
SynologyFtp.php
...just showing that it seems to be installed correctly(?) I create one test file and one test directory in my web root:
fly-local.php
myfiles/
Into fly-local.php I paste the text from their docs (https://flysystem.thephpleague.com/docs/adapter/local/):
<?php
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\Local;
$adapter = new League\Flysystem\Adapter\Local(__DIR__.'/myfiles');
$filesystem = new Filesystem($adapter);
...and change the adapter's root folder to myfiles (is that correct?). Then I run it:
php fly-local.php
It outputs:
PHP Fatal error: Class 'League\Flysystem\Adapter\Local' not found in /[PROJECT DIR]/web/fly-local.php on line 6
PHP Stack trace:
PHP 1. {main}() /[PROJECT DIR]/web/fly-local.php:0
What am I doing wrong?
You used composer, then you need to include the composer autoload.php file.
The fly-local.php should be:
<?php
require __DIR__.'/vendor/autoload.php';
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\Local;
$adapter = new League\Flysystem\Adapter\Local(__DIR__.'/myfiles');
$filesystem = new Filesystem($adapter);
If you use a framework, you can see it includes the autoload php file for you (index.php, in general). If your test/custom file is not included to framework, you need to include the file manually.

Class 'Google\Cloud\Storage\StorageClient' not found

use Google\Cloud\Storage\StorageClient;
require __DIR__ . '\vendor\autoload.php';
$storage = new StorageClient();
That as my code.Here I have installed composer on windows and getting following error:-
Fatal error: Class 'Google\Cloud\StorageClient' not found in C:\xampp\htdocs\fingertips\application\controllers\teacher.php on line 214
And even after running commands with composer to use google cloud api's, then also nothing is happening.
On cmd, when I am running this, "composer require google/cloud-storage" ,I am getting this
Using version ^1.3 for google/cloud-storage
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files
I have run so many commands to fix this but didnt get anything in success.Can somebody please help what went wrong
In regards to your second question, you didn't include the actual error you're seeing.
I can see an issue with this code block though:
require __DIR__ . '\vendor\autoload.php';
$storage = new StorageClient();
$file = fopen($params['book']['tmp_name'], 'r');
$bucket = $storage->bucket('fingertips-books');
$object = $bucket->upload($params['book']['name'], [
'name' => 'test.pdf'
]);
I'm missing the actual data you want to upload. The upload method needs data to upload. This should work:
require __DIR__ . '\vendor\autoload.php';
$storage = new StorageClient();
$bucket = $storage->bucket('fingertips-books');
$object = $bucket->upload(file_get_contents($params['book']['tmp_name']), [
'name' => 'test.pdf'
]);
See the documentation for more examples of how to go about uploading a file.
Have you installed storage client? as stated here.
https://packagist.org/packages/google/cloud-storage
use
composer require google/cloud-storage

Elastic search configuration issue with client call php

I am using elasticsearch API php to build search results. I have configured everything in my xampp server. All the libraries downloaded from composer.json. In my composer.json file contains below code
{
"require": {
"elasticsearch/elasticsearch": "~2.0"
}
}
Libraries are successfully downloaded. After that i initialize the elastic search with below code
<?php
require 'vendor/autoload.php';
$client = ClientBuilder::create()->build();
It shows fatal error like as follows
Fatal error: Class 'ClientBuilder' not found in E:\Xampp\htdocs\codeporn\elasticsearch\app\init.php on line 4
So i change the config code as,
require_once 'vendor/autoload.php';
$es = new Elasticsearch\Client([
'hosts' => ['127.0.0.1:9200']]
]);
This also shows error like
Parse error: syntax error, unexpected ']' in E:\Xampp\htdocs\codeporn\elasticsearch\app\init.php on line 10
I am following the below youtube tutorial to build the search
https://www.youtube.com/watch?v=3xb1dHLg-Lk
Please suggest what i went wrong in Elasticsearch - PHP.
My PHP Version is 5.5.9
i have initialize the clientbuilder class, now it works fine
require 'vendor/autoload.php';
use Elasticsearch\ClientBuilder;
$client = ClientBuilder::create()->build();
you need install it with composer
composer require elasticsearch/elasticsearch

Fatal error: Class 'OpenCloud\Rackspace' not found

For a custom application, I am trying to integrate Rackspace cloud files using php-opencloud library.
This is the link I followed for setup -https://github.com/srijanaravali/php-opencloud/blob/master/docs/getting-started.md
# Install Composer
curl -sS https://getcomposer.org/installer | php
# Require php-opencloud as a dependency
php composer.phar require rackspace/php-opencloud:dev-master
However, when I try to instantiate a client object, it throws an error:
Fatal error: Class 'OpenCloud\Rackspace' not found in /var/www/example/Project/sites/all/libraries/php-opencloud/test.php on line 7
Here is the code snippet:
<?php
require 'vendor/autoload.php';
use OpenCloud\Rackspace;
// 1. Instantiate a Rackspace client.
$client = new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, array(
'username' => getenv('Axxxxxxx'),
'apiKey' => getenv('abcxxxxxxxxxxxxxxxxxxxx')
));
print_r($client); die('!!');
Any pointers about whats missing?
Got it working. For some strange reason, php-opencloud library was empty under vendors/rackspace/php-opencloud.
Cloned one from github and created a symlink to it from above directory. It is working fine now.

Categories