Load a googlecode repo with composer (that doesn't have a composer.json file already)

Load an x.googlecode.com repo with composer

Quick post, full / better info in the links below.
So I'm working on a project with composer and needed to integrate with the Google Analytics API.
This project on google code provides exactly what i need:
 https://code.google.com/p/google-api-php-client/ I really would like to load this in with composer and manage it that way, but they don't offer a composer.json file.
There are several forks of it in packagist but they all seem focused on changing the library to have namespaces, which ultimately yes will great, but they don't all seem to be actively developed like the main google code repo so I'll use the main repo for now to keep up to date better.
I did think about creating my own mirror on github, but then stumbled across a couple blog posts about loading in a repo from an external repo without a composer.json file inside it.

So to the point i modified my composer.json file to include the following:

{
    "repositories": {
        "googlecode": {
            "type": "package",
            "package": {
                "name": "googlecode/google-api-php-client",
                "version": "0.6.2",
                "source": {
                    "url": "http://google-api-php-client.googlecode.com/svn",
                    "type": "svn",
                    "reference": "tags/0.6.2"
                }
            }
        }
    },
    "require": {
        "googlecode/google-api-php-client": "0.6.*"
    },
    "autoload": {
        "classmap": ["vendor/googlecode/google-api-php-client/src"]
    }
}

After that i ran composer update to install and i can start using the Google_Client class as normal.

All its really doing is:

  1. Creating a vendor directory via composer called googlecode/google-api-php-client.
  2. Faking the version as 0.6.2 (which is the real version number back on the repo)
  3. Setting the source location to http://google-api-php-client.googlecode.com/svn
  4. Setting it to be loaded as a SVN repo and to grab the 0.6.2 tag.
  5. Then in the require block I'm loading it in how i would for any other lib
  6. And in the autoload block I'm just adding its main src/ directory to the classmap composer's autoloader will use, simply making it globally available.
    These links really helped here btw:

  7. http://burgiblog.com/2012/03/08/depending-on-packages-without-composer-json-in-composer-php-dependency-manager/

  8. http://eugenemorgan.com/adding-a-random-github-repository-to-your-project-using-composer/
comments powered by Disqus
Want to setup your own server? Digital Ocean offer $100 free for new accounts.
DigitalOcean Referral Badge