4
votes

I'm trying to change the directory of my dependencies on a Symfony 3.4 application.

I need that because I'm working on macOS with Docker and I'd rather have them not shared with the host since the file synchronization is too slow.

The related documentation, says:

The change in the composer.json will look like this:

{
    "config": {
        "bin-dir": "bin",
        "vendor-dir": "/some/dir/vendor"
    },
}

That I did

Then, update the path to the autoload.php file in app/autoload.php:

// app/autoload.php

// ...
$loader = require '/some/dir/vendor/autoload.php';

I don't have any autoload.php file in my app directory.
Am I missing something in the doc ?

The application generates the following fatal error:

Warning: require(/some/dir/vendor/symfony/symfony/src/Symfony/Component/VarDumper/Resources/functions/dump.php): failed to open stream: No such file or directory in /vendor/composer/autoload_real.php on line 66

Fatal error: require(): Failed opening required '/some/dir/vendor/symfony/symfony/src/Symfony/Component/VarDumper/Resources/functions/dump.php' (include_path='.:/usr/local/lib/php') in /vendor/composer/autoload_real.php on line 66

I originally created the application with:

$ composer create-project symfony/framework-standard-edition test "3.*"
3
Hi, try adding the autoload.php. look at this gist: gist.github.com/jasson112/6ba40811473fd5231ea50399e8871a2e is my aoutoload.php maybe it works for youJasson Rojas
There is another way to speed up docker under Mac/Windows. Exclude subdirectories from volume mapping (vendors, cache, bundles). Check stackoverflow.com/questions/29181032/…Vadim Ashikhman
@JassonRojas manually adding the file works !Pierre de LESPINAY
@VadimAshikhman this is interesting, I'll give it a try. It still requires to move the dependencies elsewhere though :)Pierre de LESPINAY
@PierredeLESPINAY It doesn't, I have working developer environment with docker under Windows which loading time is close to Linux without Docker. I prepared an example here: gist.github.com/ashikhman/906d792058e9e6cfd06c5ccad555dac1Vadim Ashikhman

3 Answers

7
votes
  1. Open your composer.json file in editor.
  2. Look for "autoload-dev" section
  3. Remove whole "files" part (if exist)
  4. Save file
  5. Run composer install once again
  6. Enjoy the party.

Sample code:

"autoload-dev": {
    "psr-4": {
      "App\\Tests\\": "tests/"
    },
    "files": [
      "vendor/symfony/symfony/src/Symfony/Component/VarDumper/Resources/functions/dump.php"
    ]
  },
0
votes

In Symfony 3.4, the file app/autoload.php is removed so you should:

  • replace old vendor path by the new vendor path directly in web/app.php, web/app_dev.php, bin/console and var/SymfonyRequirements.php files
  • Rerun the command $ composer install
0
votes

I had the same issue and it was resolved doing the next.

Follow these 3 steps

1. First of all, modify composer.json to use the new vendor path:

"config": {
    ...,
    "vendor-dir": "/app-vendor"
},

And remove the next line:

"files": ["vendor/symfony/symfony/src/Symfony/Component/VarDumper/Resources/functions/dump.php"]

2. Secondly, if you are using docker-compose add a new volume where you'll put your vendors.

volumes:
  ...
  - /app-vendor

PD: /app-vendor is a mounted volume which is now empty directory.

3. Lastly, write require '/app-vendor/autoload.php'; to:

  • my_project_name/bin/console
  • my_project_name/web/app.php
  • my_project_name/web/app_dev.php

PD1: Simply, this line is pointing to the new vendor path.

PD2: It's not necessary to modify any other file (like var/SymfonyRequirements.php as I could read).

Check your changes

Once the changes are ready, remove vendor/ and also remove the containers to avoid future problems.

Start your new containers and execute composer install. Now, /vendor will be /app-vendor, it won't be in the root folder of the project anymore.

For more details, I'd recommend you to go to my docker-symfony repository and check the commits. You'll see a benchmark progression and another tips like cached volumes and non-shared /cache && /logs folders.

All for Symfony 3.4.