Example #1
0
/**
 * import
 *
 * This function is for easier package handling
 * for example suppose you save all of your work
 * in the application dir like this:
 * com /
 *    your_company /
 *                models /
 *                      - client.php
 *                      - supplier.php
 *                      - products.php
 *                - base.php
 *                - supplier_search.php
 *
 * This function makes easy to import one or more
 * classes when using the controller:
 *
 * Include "client" -> import( 'com.your_company.models.client' );
 * Include all models -> import( 'com.your_company.models.*' );
 *
 * @param string $class
 * @throw Exception on error
 * @return void
 **/
function import($class)
{
    $baseDir = Zend_Registry::get("baseDir");
    $importDir = $baseDir . "/application/";
    $classDir = str_replace(".", DIRECTORY_SEPARATOR, $class);
    if (substr($classDir, -1, 1) === "*") {
        // Import several Classes
        $classDir = str_replace("*", "", $classDir);
        $importDir .= $classDir;
        $files = Gecko_Utils::list_dir($importDir, array("php"));
        foreach ($files as $file) {
            require_once $importDir . $file;
        }
    } else {
        $file = $importDir . $classDir . '.php';
        if (file_exists($file)) {
            require_once $file;
        } else {
            throw new Exception("{$class} not found");
        }
    }
}