}
function psr0_autoloader_searchLast($dir)
{
    $dir = realpath($dir);
    psr0_autoloader_dontSearchIn($dir);
    // add the new directory to the end of the path
    set_include_path(get_include_path() . PATH_SEPARATOR . $dir);
}
function psr0_autoloader_dontSearchIn($dir)
{
    // check to make sure that $dir is not already in the path
    $pathToSearch = explode(PATH_SEPARATOR, get_include_path());
    foreach ($pathToSearch as $dirToSearch) {
        $dirToSearch = realpath($dirToSearch);
        if ($dirToSearch == $dir) {
            // we have found it
            // remove it from the list
            // $key points to the *next* entry in the list,
            // not the current entry
            $key = key($pathToSearch);
            $key -= 1;
            unset($pathToSearch[$key]);
        }
    }
    // set the revised search path
    set_include_path(implode(PATH_SEPARATOR, $pathToSearch));
}
spl_autoload_register('psr0_autoloader_autoload');
// assume that we are at the top of a vendor tree to load from
psr0_autoloader_searchFirst(LIB_ROOT);
예제 #2
0
<?php

// =========================================================================
//
// tests/bootstrap.php
//		A helping hand for running our unit tests
//
// Author	Stuart Herbert
//		(stuart@stuartherbert.com)
//
// Copyright	(c) 2011 Stuart Herbert
//		Released under the New BSD license
//
// =========================================================================
// step 1: create the APP_TOPDIR constant that all components require
define('APP_TOPDIR', realpath(__DIR__ . '/../../php'));
define('APP_LIBDIR', realpath(__DIR__ . '/../../../vendor/php'));
define('APP_TESTDIR', realpath(__DIR__ . '/php'));
// step 2: find the autoloader, and install it
require_once APP_LIBDIR . '/psr0.autoloader.php';
// step 3: add the additional paths to the include path
psr0_autoloader_searchFirst(APP_LIBDIR);
psr0_autoloader_searchFirst(APP_TESTDIR);
psr0_autoloader_searchFirst(APP_TOPDIR);
// step 4: enable ContractLib if it is available
if (class_exists('Phix_Project\\ContractLib\\Contract')) {
    \Phix_Project\ContractLib\Contract::EnforceWrappedContracts();
}