Question

I'm using Zend Framework 2 and started with the ZendSkeletonApplication. Locally I work with composer and it uses the vendor/autoload.php for autoloading. The problem is that vendor/autoload.php and vendor/composer is not included in git. (gitignore)

So my questions are:

  • Do I have to edit the init_autoloader.php that is shipped with the ZendSkeletonApplication?
  • What is the best practice to handle composer, git and autoloading in development and production?
  • Should I use a large classmap for autoloading in production?
  • Composer is never used in production environment?

By the way I work with a Zend Server where the ZF2 library is preinstalled and I have a private package under vendor folder which is not on packagist.

Was it helpful?

Solution

Composer should be managing all the app dependencies within vendor/. Even if you already have a copy of ZF2 on the server, you should let composer do it's thing and install an app-specific copy. As well as keeping all the dependencies in one place this means you can easily have apps on the same server using different versions of ZF2, and easily upgrade/downgrade as you need to.

Composer can install packages not listed on packagist, either directly from source control or from zip/gzip files and so on. So let it take care of your private package as well.

You should be able to completely delete your vendor/ folder and then restore it again just by running composer install. If you're not already in that position then I'd suggest you try and get there - it will make your life easier.

Answering your specific questions:

Do I have to edit the init_autoloader.php that is shipped with the ZendSkeletonApplication?

No.

What is the best practice to handle composer, git and autoloading in development and production?

The skeleton app uses the best practices:

  • vendor/ should be excluded from source control
  • composer.json and composer.lock should both be in source control

Should I use a large classmap for autoloading in production?

Classmaps always provide a performance boost over the standard autoloader. How much of a difference this makes depends on your app.

Composer is never used in production environment?

The composer autoloader is, yes. Personally I have composer install as part of my automated deployment process to populate the vendor/ folder when I deploy a new version.

OTHER TIPS

they are in gitignore because you have to download composer on the server side and push composer.json to install required packages

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top