autoloader ( $class )

Automatically load classes that aren’t included.

Access

public static

Parameters

Parameter

Type

Required

Description

$class

string

Required

The classname to load.

Returns

Type

Description

boolean

Whether or not the file was successfully loaded.

Source

Method defined in sdk.class.php | Toggle source view (108 lines) | View on GitHub

public static function autoloader($class)
{
    $path = dirname(__FILE__) . DIRECTORY_SEPARATOR;

    // Amazon SDK classes
    if (strstr($class, 'Amazon'))
    {
        if (file_exists($require_this = $path . 'services' . DIRECTORY_SEPARATOR . str_ireplace('Amazon', '', strtolower($class)) . '.class.php'))
        {
            require_once $require_this;
            return true;
        }

        return false;
    }

    // Utility classes
    elseif (strstr($class, 'CF'))
    {
        if (file_exists($require_this = $path . 'utilities' . DIRECTORY_SEPARATOR . str_ireplace('CF', '', strtolower($class)) . '.class.php'))
        {
            require_once $require_this;
            return true;
        }

        return false;
    }

    // Load CacheCore
    elseif (strstr($class, 'Cache'))
    {
        if (file_exists($require_this = $path . 'lib' . DIRECTORY_SEPARATOR . 'cachecore' . DIRECTORY_SEPARATOR . strtolower($class) . '.class.php'))
        {
            require_once $require_this;
            return true;
        }

        return false;
    }

    // Load RequestCore
    elseif (strstr($class, 'RequestCore') || strstr($class, 'ResponseCore'))
    {
        if (file_exists($require_this = $path . 'lib' . DIRECTORY_SEPARATOR . 'requestcore' . DIRECTORY_SEPARATOR . 'requestcore.class.php'))
        {
            require_once $require_this;
            return true;
        }

        return false;
    }

    // Load Transmogrifier
    elseif (strstr($class, 'Transmogrifier'))
    {
        if (file_exists($require_this = $path . 'lib' . DIRECTORY_SEPARATOR . 'dom' . DIRECTORY_SEPARATOR . 'Transmogrifier.php'))
        {
            require_once $require_this;
            return true;
        }

        return false;
    }

    // Load Authentication Signers
    elseif (strstr($class, 'Auth'))
    {
        if (file_exists($require_this = $path . 'authentication' . DIRECTORY_SEPARATOR . str_replace('auth', 'signature_', strtolower($class)) . '.class.php'))
        {
            require_once $require_this;
            return true;
        }

        return false;
    }

    // Load Signer interface
    elseif ($class === 'Signer')
    {
        if (!interface_exists('Signable', false) &&
            file_exists($require_this = $path . 'authentication' . DIRECTORY_SEPARATOR . 'signable.interface.php'))
        {
            require_once $require_this;
        }

        if (file_exists($require_this = $path . 'authentication' . DIRECTORY_SEPARATOR . 'signer.abstract.php'))
        {
            require_once $require_this;
            return true;
        }

        return false;
    }

    // Load Symfony YAML classes
    elseif (strstr($class, 'sfYaml'))
    {
        if (file_exists($require_this = $path . 'lib' . DIRECTORY_SEPARATOR . 'yaml' . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'sfYaml.php'))
        {
            require_once $require_this;
            return true;
        }

        return false;
    }

    return false;
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback