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

Composer installs not generating autoload.php properly? #850

Closed
mbmjertan opened this issue Aug 3, 2016 · 16 comments
Closed

Composer installs not generating autoload.php properly? #850

mbmjertan opened this issue Aug 3, 2016 · 16 comments

Comments

@mbmjertan
Copy link

mbmjertan commented Aug 3, 2016

Hey,

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": "[email protected]"
        }
    ],
     "require": {
       "phpoffice/phpword": "dev-develop"
    }
}

Composer:
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.

@avinash-0007
Copy link

did u find the answer??

@mbmjertan
Copy link
Author

@avinashdchase unfortunately, no. I did a terrible hackjob to make it somewhat work, but that fell short and I ran out of things to try.

@CodeJason
Copy link

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(
        sprintf(
            'Could not find file \'%s\'. It is generated by Composer. Use \'install --prefer-source\' or \'update --prefer-source\' Composer commands to move forward.',
            $vendorDirPath
        )
    );
}

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.

@giltroymeren
Copy link

@CodeJason's suggestion worked for me.

@lwb4
Copy link

lwb4 commented Jan 31, 2017

@CodeJason's code worked for me as well. Is there a reason this hasn't been pushed?

@Web1776
Copy link

Web1776 commented Jun 5, 2017

Thanks @CodeJason, your suggestion helped me too

@1manfactory
Copy link

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.

@vatavale
Copy link

vatavale commented Jun 5, 2018

Or you can simply change __DIR__ to $_SERVER["DOCUMENT_ROOT"]. So you can include it from any directory.

$vendorDirPath = realpath($_SERVER["DOCUMENT_ROOT"] . '/vendor');
if (file_exists($vendorDirPath . '/autoload.php')) {
    require $vendorDirPath . '/autoload.php';
} else {
    throw new Exception(
        sprintf(
            'Could not find file \'%s\'. It is generated by Composer. Use \'install --prefer-source\' or \'update --prefer-source\' Composer commands to move forward.',
            $vendorDirPath . '/autoload.php'
        )
    );
}

@chrisribe
Copy link

If you are starting the server from the samples folder (php -S localhost:800) try this:

$vendorDirPath = realpath($_SERVER["DOCUMENT_ROOT"] . '/../../../');
if (file_exists($vendorDirPath . '/autoload.php')) {
    require $vendorDirPath . '/autoload.php';
} else {
    throw new Exception(
        sprintf(
            'Could not find file \'%s\'. It is generated by Composer. Use \'install --prefer-source\' or \'update --prefer-source\' Composer commands to move forward.',
            $vendorDirPath . '/autoload.php'
        )
    );
}

Seems complex for just a self contained sample page.
Chris

@lanxiuying
Copy link

you should run composer install in your phpword DIR

@rommer-luo
Copy link

@1manfactory 很棒,弄了半天,还是你的这一句解决了我的问题!棒棒哒!

@chrisribe
Copy link

The docs need to better cover composer issues. Came back to this project to run some tests and could not get it to build. Finally ran:

composer update

And it got all the dependencies correctly and generated the autoload files so they work !
Such a wast of time, please add it to the main readme !

@troosan troosan closed this as completed Apr 24, 2019
@moly4565
Copy link

moly4565 commented Jul 3, 2019

Hi i can not update phpword package . phpword package 0.16.0 and composer version is 1.8.1
when run on cmd composer require phpoffice/phpword
getting problem
the requested package phpoffice/phpword No version set (parsed as 1.0.0) is satisfiable by phpoffice/phpword No version set (parsed as 1.0.0) but this conflict with your requirements

@moly4565
Copy link

moly4565 commented Jul 3, 2019

Laptop setup ok it working but where install it windows server 2012 r2 then composer installed ok. package cant update
my composer.json code
"require": {
"php": "^5.3.3 || ^7.0",
"ext-xml": "*",
"zendframework/zend-escaper": "^2.2",
"phpoffice/common": "^0.2.9"
}
please help me anyone

@chrisribe
Copy link

@moly4565 I added some commands in the readme for production release that may help you.
See my pull request
#1650

Chris

@IssamLammri
Copy link

@vatavale your solution is perfect and work in any case

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

No branches or pull requests