Adding a random GitHub repository to your project using Composer

I’m becoming a big fan of Composer. I recently had to re-create the environment for an older project on a different development machine, a process which unfortunately included quite a few manual steps to get the dependencies configured.

I decided to set up the project with Composer, and now setting up the project is fast and easy (well at least easy … waiting for the Zend Framework files to download does take a little while).

It’s super easy to get started and follow the Composer documentation to use dependencies that are available through Packagist. More and more packages, like both Zend Framework 1 and Zend Framework 2, are becoming available there.

But what about packages that aren’t available through Packagist? If you control the package, you can publish it there, or if it’s something for private/corporate use, you can set it up as a Composer package using Satis.

But what if you don’t have control over the package? What if it’s just a random GitHub repository?

Because Composer can work with any source code repository, it’s actually not difficult to make it work with a third-party repository on GitHub (or Bitbucket, whatever … as long as it uses Git, Mercurial or Subversion).

For example, for my Zend Framework 1 projects, I like to use a dependency injection container called Yadif. With some help, I was able to get it set up in my project like so:

"repositories": {
    "yadif": {
        "type": "package",
        "package": {
            "name": "beberlei/yadif",
            "version": "1.0.0",
            "source": {
                "url": "",
                "type": "git",
                "reference": "d874042a50"
"require": {
    "beberlei/yadif": "1.0.0"
"autoload": {
    "psr-0": {
        "Yadif": "vendor/beberlei/yadif/src/"

Because the Yadif repository doesn’t have any tags for version numbers, we have to tell Composer very explicitly about it. Under “repositories”, we give the package its name and specify a version number (I used 1.0.0 but you could plug in whatever makes sense). We then tie that version to a specific commit, in this case d8740042a50.

After basically defining the repository for Composer, we then tell Composer to require the repository. Then — and I love this part — we tell Composer how to autoload the classes from the package. Because Yadif basically follows the PSR-0 convention, we just tell Composer where the core class files are found, and autoloading is all set up — no need to mess with symlinks or include paths.

Note: Check this post for more explanation and sample composer.json code.

Simple Vim trick: sorting alphabetically

Some days I feel like I am only using Vim to a fraction of its capacity. Today I discovered a simple time-saver that I hadn’t known about before — Vim’s :sort command.

The sort function can be used to sort a whole file alphabetically or certain lines within a file. It’s perfect for CSS code, for example, where I like to alphabetize the properties.

So for something like this:

.some-class {
  padding: 5px;
  margin: 5px;
  width: 180px;
  /* ... */
  line-height: 1.2;

… I can position my cursor within the brackets and type vi{ and then :sort, and the properties are sorted alphabetically.

Setting up “contact us about this property” forms in AgentPress

The AgentPress theme from StudioPress is a very nice theme, but it’s not always apparent how to set up your client’s site to look like the demo.

One example is the form titled “Contact Us About This Property” that shows up at the bottom of each property listing.

The “Contact Us About This Property” form from the AgentPress demo

The demo does let us know that the form uses the Gravity Forms plugin. If you’ve used Gravity Forms before, it’s pretty straightforward to set up all of the form fields, except for one: the “Which Property Are You Interested In?” dropdown.

Now, manually setting up the options for a dropdown field like this in Gravity Forms is fairly simple, but when you’re managing multiple listings, setting up these options for every listing is going to get really old really quick. Unfortunately it doesn’t look like there’s a way to make the dropdown menu dynamic based on your listings.

So the solution I came up with was to just ditch the dropdown field. Honestly, I’m not sure what value it adds. The person submitting the form is going to be interested in the property on the page 99% of the time.

But if we ditch the dropdown, we still need a way for the form to tell us which property the user was viewing when submitting the form. The answer is to use a hidden field in the form.

I actually set up two hidden fields, one for the name of the listing and one for the URL of the listing.

To do this, go into Gravity Forms in the WordPress admin and add a couple of hidden fields to the form. For the first field, under “Field Value,” give it a name (I used “Listing viewed”), and then under the Advanced tab, pull down the “Insert variable” dropdown and choose “Embed Post/Page Title.”

Screen shot of hidden field for property name

For the second field, give it a name as well, and under Advanced, choose “Embed URL” from the “Insert variable” dropdown.

Screen shot of hidden field for property URL

Now when someone fills out the “Contact Us About This Property” form, the name of the property and the URL of the listing will automatically be added to the form.