Richard Holloway Blog

Use the latest Redbean in RjhRedbean

Posted in November 2014 by under redbeanphp

Using RedbeanPHP makes working with databases so easy and using RjhRedbean makes it trivial to add RedbeanPHP to your Zend Framework 2 project. A little while ago Gabor announced that RedbeanPHP would no longer support composer as they had already thought out the distribution problem. This is true and using RedbeanPHP is simple, but when you are using composer for your other dependencies, it makes sense to use one method to load all dependencies.

It is possible to configure composer to use pretty much anything as a source, it defaults to packagist, but you can configure it to use a tar file as a repository. I thought I'd do this in RjhRedbean to load RedbeanPHP 4 but composer cannot define respositories in dependencies so this hasn't been possible.

Here are the steps you need to get the latest RedbeanPHP into your ZF2 project

Edit your composer.json and add a section like

    "repositories": [
        {
            "type": "package",
            "package": {
                "name": "gabordemooij/redbean",
                "version": "4.0.9",
                "dist": {
                    "url": "http://www.redbeanphp.com/downloadredbean.php",
                    "type": "tar"
                }
            }
        }
    ],
    "minimum-stability": "dev",
            

Edit the require section to add "gabordemooij/redbean": "4.0.9", so that it looks like

    "require": {
        "php": ">=5.3.3",
        "gabordemooij/redbean": "4.0.9",
        "zendframework/zendframework": "2.3.*",
        "richardjh/rjhredbean": "dev-master"
    }
}
            

For example, my composer.json in a ZF2 skeleton application, with these changes to load the latest redbean, looks like

{
    "name": "zendframework/skeleton-application",
    "description": "Skeleton Application for ZF2",
    "license": "BSD-3-Clause",
    "keywords": [
        "framework",
        "zf2"
    ],
    "homepage": "http://framework.zend.com/",
    "minimum-stability": "dev",
    "repositories": [
        {
            "type": "package",
            "package": {
                "name": "gabordemooij/redbean",
                "version": "4.0.9",
                "dist": {
                    "url": "http://www.redbeanphp.com/downloadredbean.php",
                    "type": "tar"
                }
            }
        }
    ],
    "require": {
        "php": ">=5.3.3",
        "gabordemooij/redbean": "4.0.9",
        "zendframework/zendframework": "2.3.3",
        "richardjh/rjhredbean": "dev-master"
    }
}
            

Then run composer update and redbean v3.5.1 should be removed and redbean 4.0.9 should be available instead.

Finally update autoload_classmap.php to find the new redbean include file.

// Was
$redbeanIncFile = __DIR__ . '/../../gabordemooij/redbean/RedBean/redbean.inc.php';

// Change to
$redbeanIncFile = __DIR__ . '/../../gabordemooij/redbean/rb.inc.php';