function bfox_tool_source_linker(BfoxRef $ref = null)
{
    global $_bfox_tool_source_linker;
    if (is_null($_bfox_tool_source_linker)) {
        $_bfox_tool_source_linker = new BfoxBibleToolLink();
        if (is_null($ref)) {
            $ref = bfox_ref();
        }
    }
    if (!is_null($ref)) {
        $_bfox_tool_source_linker->setRef($ref);
    }
    return $_bfox_tool_source_linker;
}
<?php

require_once 'biblefox-ref.php';
require_once 'bfox_bible_tool_link.php';
function urlTemplateAssert($link, $template, $target)
{
    $url = $link->urlForTemplate($template);
    if (!assert($url == $target)) {
        echo "'{$url}' != '{$target}'\n";
    }
}
$link = new BfoxBibleToolLink();
$link->setRef(new BfoxRef('Gen 1'));
urlTemplateAssert($link, 'http://www.biblegateway.com/passage/?search=%ref%&version=NIV', 'http://www.biblegateway.com/passage/?search=Genesis+1&version=NIV');
urlTemplateAssert($link, 'http://www.biblegateway.com/passage/?search=%ref%&version=NIV&interface=print', 'http://www.biblegateway.com/passage/?search=Genesis+1&version=NIV&interface=print');