SolvedPHPWord Composer installs not generating autoload.php properly?


I tried installing PHPWord using composer install --prefer-source and the composer.json that you suggest developers should use in the documentation, but I'm getting this error in my error log when I try running the samples:

[04-Aug-2016 00:39:25 Europe/Zagreb] PHP Fatal error:  Uncaught Exception: Could not find file '/autoload.php'. It is generated by Composer. Use 'install --prefer-source' or 'update --prefer-source' Composer commands to move forward. in /Users/mbm/projekti/SomeProject/vendor/phpoffice/phpword/bootstrap.php:22
Stack trace:
#0 /Users/mbm/projekti/SomeProject/vendor/phpoffice/phpword/samples/Sample_Header.php(2): require_once()
#1 /Users/mbm/projekti/SomeProject/vendor/phpoffice/phpword/samples/index.php(2): include_once('/Users/mbm/proj...')
#2 {main}
  thrown in /Users/mbm/projekti/SomeProject/vendor/phpoffice/phpword/bootstrap.php on line 22

This is my composer.json:

    "name": "mbmjertan/SomeProject",
    "authors": [
            "name": "Mario Borna Mjertan",
            "email": ""
     "require": {
       "phpoffice/phpword": "dev-develop"

Composer version 1.2-dev (06499749ff8875f939f413cf9a3725792d4ee4f9) 2016-07-11 07:16:26

PHP 7.0.0 on Mac OS X 10.11.6 (El Capitan) under Apache

Is there something I'm doing wrong or missing? This is my first time using Composer in a project.

For what it's worth, I tried looking at the source myself and it seems that PHPOffice is trying to include files from $vendorDirPath = realpath(__DIR__ . '/vendor');, a folder that does not exist.

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

17 Answers

✔️Accepted Answer

Basically the bootstrap file is not getting the right path, at least for the samples page.
Here's what I changed phpoffice/phpword/bootstrap.php to:

$vendorDirPath = __DIR__ . "/../../autoload.php";

if (file_exists($vendorDirPath)) {
    require $vendorDirPath;
} else {
    throw new Exception(
            'Could not find file \'%s\'. It is generated by Composer. Use \'install --prefer-source\' or \'update --prefer-source\' Composer commands to move forward.',

Once we get to the current directory, we need to travel back up two folders.
Don't know if it'll stuff up when I actually try using phpword but at lease the samples work.

Other Answers:

Had to use this

$vendorDirPath = __DIR__ . "/../../";

Reminds me again why I dislike composer. I had never been able to install at least one package with composer successfully from scratch. All needed rework.

More Issues: