I'm working on pulling in the AWS PHP SDK and am running into some issues since my current stack isn't using a package manager. It's not an option to start using it, either (company related -- would rather not elaborate).
That all being said, I'm pulling in the source directly and trying to add it to my include path and just including the files as I need them in my S3 wrapper objects that I'm writing. However, it's running into issues with the namespaces (I think) and those blowing up.
This is the library I'm referring to:
https://github.com/aws/aws-sdk-php
I tried following the bit at the bottom about working with AmazonS3 and uploading a file to it. So, I attempted to include the various parts of the code it referenced as follows:
Attempt One
require_once('/includes/third_party/aws-sdk-php-master/src/Aws/Common/Aws.php');
require_once('/includes/third_party/aws-sdk-php-master/src/Aws/S3/Enum/CannedAcl.php');
require_once('/includes/third_party/aws-sdk-php-master/src/Aws/S3/Exception/S3Exception.php');
Attempt Two
set_include_path(get_include_path() . "/includes/third_party/aws-sdk-php-master/src/");
include('Aws/Common/Aws.php');
include('Aws/S3/Enum/CannedAcl')
include('Aws/S3/Exception/S3Exception.php');
Both of these produced a similar error:
Fatal error: Class 'Guzzle\Service\Builder\ServiceBuilderLoader' not found in \includes\third_party\aws-sdk-php-master\src\Aws\Common\Aws.php on line 26
PHP Fatal error: Class 'Guzzle\Service\Builder\ServiceBuilderLoader' not found in \includes\third_party\aws-sdk-php-master\src\Aws\Common\Aws.php on line 26
Any advice on how to start debugging this? Would be much appreciated!
The AWS SDK for PHP nows ships a zip file with everything you need, including an autoloader: http://docs.aws.amazon.com/aws-sdk-php-2/guide/latest/installation.html#installing-via-zip.
You should stick the the recommend installation procedures. Personally, I would go with the Composer installation or just use the PHAR without Composer.
Then you just need to include the PHAR like:
require '/path/to/aws.phar';
And you will have everything you need.
The problem you have now is likely that you are not taking advantage of the autoloader. Using your approach, you will need to manually include all the classes that would normally be autoloaded.
You also need to download and include another library (Guzzle, not included in the PHAR archive).
Related
I'm working on a project with protocol buffers and after i compiled a proto file, i cant seem to include it neither run it cos it keeps giving me this exact error:
PHP Fatal error: Class 'Google\Protobuf\Internal\Message' not found in /app/generated_files/message.php on line 13
On message.php i have the auto generated file from a .proto file and it includes Google\Protobuf\Internal\Message.
While reading on the protobuf github issues, i found that a person had the same problem where he concluded that it was the composer's fault. However in my case that wouldnt be the issue cos i didnt use composer.
I used pecl to install protocol buffers, and i have the library protobuf.so located in /etc/php5/apache2/XXXXXXXXX. I also added extension=protobuf.so on the last line of php.ini.
Keep in mind that im using docker for everything, therefore it might be something different but i still doubt.
In case anyone ends up here with the same question: you just need to add componser autoloader to your file include_once './vendor/autoload.php'; (change path as required)
I had the same problem, but the reason was different for me:
Git somehow messed up the casing of the folders, which lead to a wrong file path translation.
As soon as I fixed the casing ([...]/src/Google/Protobuf instead of [...]/src/google/protobuf in the vendor folder)
I want to use the following AntiXSS library in one PHP file. It is my first time using Composer, but I followed their installation steps and I installed it successfully. I downloaded the library through Composer, updated it and Composer created the vendor/ folder in my directory with the necessary files.
Now I added the following require 'vendor/autoload.php' into my PHP file. I created a new AntiXSS class but I obtain the following error:
Class AntiXSS not found in my directory on line 3.
I tried to use an absolute path instead of vendor/autoload.php but it isn't working yet and I don't know if I should do something more.
Best regards
The class is located in the voku\helper namespace. Use new \voku\helper\AntiXSS() to instantiate it or use use imports to import the namespace.
See php.net for more information about namespaces.
Here's the code, https://github.com/google/google-api-php-client/
Here's the file that's missing, https://github.com/google/google-api-php-client/blob/master/src/Google/autoload.php
I know it's possible to create this file with composer, but was just wondering if anyone has it available.
I'm also concerned that this alone might not make the software work, as I've tried to do it the manual way and the Class it can't reference is "GuzzleHttp\Collection" which is accessed in PHP with "use GuzzleHttp\Collection". I don't know how adding "autoload.php" will help referencing a file that's not part of the "google-api-php-client".
Does anyone actually have this software working in PHP, it says Beta?
I found it using Google Cache,
http://webcache.googleusercontent.com/search?q=cache:992oyuQ76a0J:https://github.com/google/google-api-php-client/blob/master/src/Google/autoload.php+&cd=1&hl=en&ct=clnk&gl=us
This file should be load from vendor directory
// include your composer dependencies
require_once 'vendor/autoload.php';
I am trying different libraries via composer and on all of them I hit a similar error:
Fatal error: Class 'MyRestApi\Admin' not found in /usr/home/www/tmp/index.php on line 6
I have tried short and long path names:
set_include_path('/usr/home/www/vendor/marcj/php-rest-service/RestService');
require_once('/usr/home/www/vendor/marcj/php-rest-service/RestService/Server.php');
I have tried require, include, require_once, set_include_path.
Also I have tried
require "../vendor/autoload.php";
and
require "/home/www/vendor/autoload.php";
Always the same error trying to find the first class.
This particular library https://github.com/marcj/php-rest-service it the one I am trying.
How do you get a composer library to work without an autoload? (I am assuming this has something to do with my issue)
You don't. Using the autoloader of Composer is one of the central contracts that every package that gets installed with Composer relies on.
In theory you could try to invent your own autoloading. In practice: Why?
Your code is missing a require "vendor/autoload.php"; - the path to vendor depends on where your file is that wants to include the autoloader.
Note that if you add your own package and install it via Composer, it must not include the autoloader by itself - the code that uses this package is supposed to do it.
I'm hoping someone can spot what I've forgotten to do. Here are my steps:
Downloaded and unpacked the ZendFramework-2.3.5 into /usr/share.
Updated include_path in my php.ini file to include '/usr/share/ZendFramework-2.3.5/library' per the INSTALL.md, and restarted Apache to confirm the path is set (now ".:/usr/share/php:/usr/share/ZendFramework-2.3.5/library").
Created a test script in my web document root (using the class 'CamelCaseToUnderscore' as an example):
use Zend\Filter\Word\CamelCaseToUnderscore;
$filter = new CamelCaseToUnderscore();
echo $filter->filter('BigsAndLittles');
...and I get the fatal error "class 'zend\filter\word\camelcasetoseparator' not found".
In order to do use Zend classes like this, do I need to do some additional configuration or create an autoloader or something to find them? Seems like this should have worked. If I include the CamelCaseToUnderscore.php file in a require_once statement, then I get a fatal error that it's parent class doesn't exist (CamelCaseToSeparator.php). What am I missing?
You can use require 'Zend/Mvc/Application.php' to test if your include path is correct, but you will need an autoloader:
http://framework.zend.com/manual/current/en/modules/zend.loader.standard-autoloader.html.
You can find an example here (lines 18-20):
https://github.com/zendframework/zf2/blob/master/demos/Zend/Feeds/consume-feed.php
I strongly suggest using composer as it will save you a lot of time troubleshooting your include paths, but it also allows you manage version better. It makes it easier for other developers and to deploy your code.
Starting with composer is very easy, just install it and create composer.json:
https://getcomposer.org/doc/01-basic-usage.md#composer-json-project-setup
Run:
composer require zendframework/zendframework
Composer will download all libraries to vendor folder and will generate an autoloader, all you have to do is to include
require 'vendor/autoload.php';
https://getcomposer.org/doc/01-basic-usage.md#autoloading
Most popular PHP frameworks use composer for managing dependencies:
https://github.com/zendframework/zf2/blob/master/composer.json
https://github.com/symfony/symfony/blob/2.7/composer.json