Funky Composer


At work, we're using composer to manage our Drupal project, and I sort of fell in love with it.  Composer allows you to download, install, use, update, and remove packages easier than anything else I've ever used.

Then I came home. I started doing some web dev on some personal websites, including this one. I made some changes to my PHP framework Funky and realized I had no way of getting them into any of my other sites without copy/pasting!

Anyways, today, I decided to try to turn Funky into a composer package for the following reasons:

  • to make updating versions of Funky easier
  • to utilize composer's autoloader so I can easily use other Composer packages
  • be able to start a new site with a single composer command

After sifting through a few tutorials, I found the easiest way is to learn about it is to do the steps on the packagist homepage, then refer to the the basic usage page for good information on everything else.

So after setting up my composer package and submitting it to packagist, it is so easy to start a new site. I love it!  All I have to do is run this command:

composer require mistermashu/funky:dev-master && vendor/mistermashu/funky/

That's it! It downloads Funky into a nice spot, then runs the script that it comes with which scaffolds out the directory structure for you. It also sets up a .gitignore file to help you to remember to not commit the vendor/ directory, which is where all the composer files are.

Before, Funky had a custom autoloader, and it was quite complicated. Whenever I wanted to change it, I dreaded it a little.  Now, I'm using the standard PSR-4 autoloader that Composer generates, so it's nice and standardized and I don't have to worry about that code at all.  How wonderful!