How to use a forked repository in your composer.json

How to use a forked repository in your composer.json (and try out Zend Framework Twitter Service)

Posted on November 29, 2013

WARNING: Please note that this article was published a long time ago. The information contained might be outdated.

For a new project I needed to publish messages on Twitter via Twitter REST API. Since I'm a Zend Framework fan, I choose to give ZendServiceTwitter client a try.

I started by running php composer.phar install using a simple composer.json file:

{
    "require": {
        "zendframework/zendservice-twitter": "2.1.0"
    }
}

The library got downloaded and I was able to test my PHP script doing some "copy & paste" from the documentation:

<?php
include "vendor/autoload.php";

$config = array(
    'access_token' => array(
        'token'  => 'TOKEN',
        'secret' => 'SECRET',
    ),
    'oauth_options' => array(
        'consumerKey' => 'CONSUMER_KEY',
        'consumerSecret' => 'CONSUMER_SECRET',
    ),
    'http_client_options' => array(
        'adapter' => 'ZendHttpClientAdapterCurl',
        'curloptions' => array(
            CURLOPT_SSL_VERIFYHOST => false,
            CURLOPT_SSL_VERIFYPEER => false,
        ),
    ),
);

$twitter = new ZendServiceTwitterTwitter($config);

$response = $twitter->search->tweets('#zf2');
$tweets = $response->statuses;
var_dump($tweets);

But as result I got a fatal error:

PHP Fatal error:  Call to a member function connect() on a non-object
in /Users/me/Development/zf2-twitter-test/vendor/zendframework/zend-http/Zend/Http/Client.php on line 1359

To make a long story short I found out that the ZendOAuthClient::getAdapter() method wasn't confirm to the parent class. So I forked <https://github.com/zendframework/ZendOAuth>, changed the code to what I think it's a solution to the problem, committed and finally synced to my dev-master branch. At this point I modified my local composer.json adding my git repository and specifying the dev-master branch for zendframework/zendoauth:

{
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/lorenzoferrarajr/ZendOAuth.git"
        }
    ],
    "require": {
        "zendframework/zendoauth": "dev-master",
        "zendframework/zendservice-twitter": "2.1.0"
    }
}

After running php composer.phar update all started working great.

This post should make you interested in trying Zend Service Twitter.