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

Question on autoload failure. #5998

Closed
ToddRowan opened this issue Dec 27, 2016 · 2 comments
Closed

Question on autoload failure. #5998

ToddRowan opened this issue Dec 27, 2016 · 2 comments

Comments

@ToddRowan
Copy link

ToddRowan commented Dec 27, 2016

I initially posted this question here: http://stackoverflow.com/questions/41250405/composer-plugin-autoload-depedency.

I'm working on a composer command plugin that uses the AWS php SDK to grab files from S3. I'm using composer 1.2.4.

I am seeing an autoload issue where AWS classes autoload as expected but functions declared in a separate file do not. The AWS SDK composer.json appears correct.

My composer.json:

{
    "name": "myco/composer-s3-downloader",
    "type": "composer-plugin",
    "version": "0.1",
    "require": {
        "composer-plugin-api": "1.1.*",
        "aws/aws-sdk-php": "3.20.*"
    },
    "autoload": {
        "psr-4": {"MyCo\\Composer\\": "MyCo/"}
    },
    "extra": {
        "class": "MyCo\\Composer\\S3Downloader"
    }
}

Excerpt of aws composer.json:

"autoload": {
    "psr-4": {
        "Aws\\": "src/"
    },
    "files": ["src/functions.php"]
}

When I run my command I get the following output:

PHP Fatal error:  Call to undefined function Aws\manifest() in /.../vendor/aws/aws-sdk-php/src/AwsClient.php on line 143

I can see the AWS classes showing up in the stack trace, so I know they're being loaded.

...
PHP  14. Aws\S3\S3Client->__construct() /.../filename.php:102
PHP  15. Aws\AwsClient->__construct() /.../vendor/aws/aws-sdk-php/src/S3/S3Client.php:243

But the functions defined in vendor/aws/aws-sdk-php/src/functions.php aren't being included.

I can verify that none of the files listed in vendor/composer/autoload_files.php are being included.

Is there an autoload step I'm missing to get these loaded and accessible? My current workaround is to manually include them, but that doesn't feel right.

private function getIncludes() {
        if (file_exists(getcwd() . "/vendor/composer/autoload_files.php")) {
            foreach (require getcwd() . "/vendor/composer/autoload_files.php" as $a => $b) {
                require $b;
            }
        }
    }
@alcohol
Copy link
Member

alcohol commented Dec 28, 2016

I am guessing you run into this error during script or plugin execution. This is at runtime, which means the final autoloader has not been generated yet. The autoloader that is generated on the fly at runtime does not load/contain "files" directives.

@ToddRowan
Copy link
Author

Ah, that makes sense. Dependency calculation is ultimately for the app being built and not the commands that contribute to that end.

I will update my command to mimic what's in the postAutoloadDump event in the scripts topic.

Thank you for the help and the clarification.

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

No branches or pull requests

2 participants