pksunkara / alpaca

Given a web API, Generate client libraries in node, php, python, ruby
Mozilla Public License 2.0
2.45k stars 89 forks source link

PHP namespace fatal error? #5

Closed ghost closed 10 years ago

ghost commented 10 years ago

Sorry if this is not a bug, as this is my first exposure to namespaces (in PHP, anyway). The issue can be re-created using the generated Buffer PHP client code. To do so, please edit Client.php and instantiate the class as follows:

$x = new Client();

Then, run from command line with: php Client.php. This generates an error:

PHP Fatal error:  Class 'Buffer\HttpClient\HttpClient' not found ...

This issue was discovered when generating a new API client, which resulted in a similar error, the example is simply to help in reproducing (what appears to be) an issue.

PHP version used: 5.3.10.

Will keep reading up on namespaces and attempt to isolate the issue (or figure out the error on my end). Thanks.

ghost commented 10 years ago

Added this to line 4 of the generated Client.php:

require_once(__DIR__ . '/HttpClient/HttpClient.php');

Added this to line 4 of the generated HttpClient.php

require_once(__DIR__ . '/../../../vendor/autoload.php');

This isn't robust or anything, just trying to isolate the issue (again, assuming I am not doing something incorrect). Seems to fix the issue.

pksunkara commented 10 years ago

Hey,

The generated PHP client library uses PSR-0 convention and is generally installed using composer. You should read up on using composer and how to use it.

Thanks.

ghost commented 10 years ago

Ok, thanks.

Just a humble suggestion (helpful for those unfamiliar with the process), maybe the docs could include information to this effect? This could include (ideally) a full sample walk-through of how to install and instantiate the API, including a sample call (perhaps using the Buffer example), for each generated language.

In my case, I will be wrapping the generated PHP code up with an extension for an existing project built in Yii 1.1, and will need to change the conventions of the project a bit in order to cleanly tie in the generated API code to an extension. Of course, using PSR-0 convention will be of good benefit -- will probably extrapolate from some of the conventions described here: http://www.yiiframework.com/wiki/392/creating-yii-applications-with-composer/ (hopefully this helps someone).

Thanks for your help.

pksunkara commented 10 years ago

The readme.md of the generated PHP library includes that information. Check here.

Is that what you are asking?

ghost commented 10 years ago

Ahh, sorry -- there they are. Thanks.

ghost commented 10 years ago

Instead of opening another ticket and adding clutter, will just ask here: Why do the docs list only PHP versions 5.4 and 5.5? https://github.com/alpaca-api/buffer-php

My understanding is that namespaces are fully supported in PHP 5.3; maybe something else in the code doesn't work with 5.3?

pksunkara commented 10 years ago

I never got to test for 5.3