Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ApiWrapper not loading for PSR-4 #32

Closed
viccherubini opened this issue May 28, 2015 · 16 comments
Closed

ApiWrapper not loading for PSR-4 #32

viccherubini opened this issue May 28, 2015 · 16 comments
Labels

Comments

@viccherubini
Copy link

I'm using Composer version 1.0-dev 69210d5bc130f8cc9f96f99582a041254d7b9833 2015-05-25 13:29:26 and the ApiWrapper class can not be found using the autoloader.

First, I downloaded Composer from getcomposer.org and then ran the following command:

php composer.phar require "expectedbehavior/php-docraptor" "1.0.0"

This created a composer.json file that looks like this:

{
    "require": {
        "expectedbehavior/php-docraptor": "1.0.0"
    }
}

I copied the sample code from the README into this file:

<?php

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

$apiKey = 'MY_API_KEY';

$docRaptor = new \DocRaptor\ApiWrapper($apiKey);
$docRaptor->setDocumentContent('<h1>Test</h1>')
    ->setDocumentType('pdf')
    ->setTest(true)
    ->setName('test.pdf');

$file = $docRaptor->fetchDocument();
file_put_contents('test.pdf', $file);

When running this, I get the following error:

PHP Fatal error:  Class 'DocRaptor\ApiWrapper' not found in example.php on line 7

If I go into the vendor/expectedbehavior/php-docraptor/src/ directory and rename DocRaptor.php to ApiWrapper.php it works fine.

Am I missing something with my Composer file, or does PSR-4 expect the class and file to have the same name?

@markushausammann
Copy link

Always run composer self-update before you do anything else. What PHP Version are you on? This shouldn't happen, you shouldn't need to rename any files, PSR-4 doesn't require the filename to be anything specific.

@janxious janxious added the bug label May 28, 2015
@viccherubini
Copy link
Author

I'm using the latest version of Composer. And I tested on PHP 5.5.20 on OSX and PHP 5.6.5 on Ubuntu 12.04 64bit.

@markushausammann
Copy link

This is very weird. I can reproduce it but it doesn't make sense. It should work. Need to investigate. Maybe it's even a composer bug which I would normally strongly doubt.

@janxious
Copy link
Contributor

I have read a bit about psr-4 and it seems like the library is slightly in the wrong. I believe the rename is the correct thing to do. This is the most clear article I have found on the subject: http://www.sitepoint.com/battle-autoloaders-psr-0-vs-psr-4/

@viccherubini
Copy link
Author

My knowledge of the PSR's is pretty limited but I think the class name and file name need to match.

@markushausammann
Copy link

I guess I was wrong about psr-4. Only strange that it worked for me so far that way. I'll try to find some time to find out why.

@janxious
Copy link
Contributor

janxious commented Jun 1, 2015

@leftnode @markushausammann I will try to get a PR up for this this week if you don't beat me to it.

@janxious
Copy link
Contributor

janxious commented Jun 4, 2015

PR up!

@janxious
Copy link
Contributor

janxious commented Jun 4, 2015

@leftnode Can you try Version 1.1.0 and let me know if you run into the same problems?

@markushausammann
Copy link

@janxious you'll need to tag a release before that, just in case.

@janxious
Copy link
Contributor

janxious commented Jun 4, 2015

Derp. That is done, and also added one for 1.0.1.

@viccherubini
Copy link
Author

May have to do a new release, this one is missing a few things:

PHP Notice:  Undefined variable: config in /Users/vic/Development/utilities/docs/vendor/expectedbehavior/php-docraptor/src/HttpClient.php on line 46
PHP Fatal error:  Call to a member function getReportUserAgent() on a non-object in /Users/vic/Development/utilities/docs/vendor/expectedbehavior/php-docraptor/src/HttpClient.php on line 46

Updated the call to $config on line 46 to be $this->config and updated the call to userAgent() on line 47 to be $this->userAgent() (both in HttpClient.php). Everything else worked from there.

@janxious
Copy link
Contributor

janxious commented Jun 5, 2015

Was running into issues where our tests are not actually testing the HTTPClient directly. There is a new version 1.1.1 that should resolve the issue. I have also deleted the 1.1.0 tag since that was no good.

@viccherubini
Copy link
Author

Just pulled in 1.1.1 and was able to build a document correctly. Thanks!

@janxious
Copy link
Contributor

janxious commented Jun 5, 2015

👍 Good to hear! I really appreciate your patience, and I am sorry for taking so much of your time.

@viccherubini
Copy link
Author

Hah, no problem at all - glad it got worked out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants