Best practices for reusing code in multiple projects

I’d appreciate insights from anyone who engineered an elegant solution for a similar problem:

My company just launched a site for a client. The site is built upon Yii2. Now we’re building a new site for the same client, and I want to reuse a lot of helper classes/libraries that we built for the previous site. Just a few examples for the sake of illustration:

  • An SEO helper class that extracts SEO content from a model and renders SEO HTML tags

  • A bootstrap file that determines the current language based upon the domain

  • A bootstrap file that adds a login screen to the dev/testing environments

  • An SDK that we custom-built to integrate with a 3rd party service

Obviously we could very easily just copy-paste all of the relevant code files into the new project. The question if anyone has experience with this kind of situation.


There are many options but nowadays I’d prefer composer packages. Either public or private (if you do not want to expose code).

You could create private GitHub repos. I don’t know if Packagist can handle private though, but you can add your GitHub project to Composer without the need for Packagist.

Another option is to store them all locally, and use the path type in Composer, and point to your packages locally. They don’t need to be under version control.

Check out - looks like its a more controllable alternative to Packagist. Looks pretty cool, but I haven’t tried it so I can’t confirm it does what your wanting.

In the Composer docs, they talk about Satis and Toran Proy:

Hope it helps!

Packagist cannot but composer can via private package repositories hosted with the help of Satis.