Perforce Chronicle 2012.2/486814
API Documentation

P4Cms_Image_Driver_Factory Class Reference

Provides method for creating image drivers implementing P4Cms_Image_Driver_Interface. More...

List of all members.

Static Public Member Functions

static create ($className=null)
 Create and return a single instance of an image driver implementing P4Cms_Image_Driver_Interface.
static getDriverClasses ()
 Return list of driver classes the factory is aware of.
static isValidType ($className)
 Determine if the given Image driver type is valid.

Static Protected Attributes

static $_drivers

Detailed Description

Provides method for creating image drivers implementing P4Cms_Image_Driver_Interface.

Copyright:
2011-2012 Perforce Software. All rights reserved
License:
Please see LICENSE.txt in top-level folder of this distribution.
Version:
2012.2/486814

Member Function Documentation

static P4Cms_Image_Driver_Factory::create ( className = null) [static]

Create and return a single instance of an image driver implementing P4Cms_Image_Driver_Interface.

Parameters:
string$classNameoptional - driver class name; if omitted, first driver that can be instantiated from the following list (in given order) will be returned: imagick, gmagick, gd
Returns:
P4Cms_Image_Driver_Interface an image driver implementation
Exceptions:
P4Cms_Image_Exceptionif a given $className is not a valid driver class
    {
        // if driver class was provided, ensure its valid and return new driver instance
        if ($className) {
            if (!static::isValidType($className)) {
                throw new P4Cms_Image_Exception(
                    "Cannot create a driver: Class " . $className . " is not a valid image driver."
                );
            }

            return new $className;
        }

        // if no driver class was provided by user, try to return first driver we can create
        foreach (static::$_drivers as $driver) {
            try {
                return new $driver;
            } catch (P4Cms_Image_Exception $e) {
                // continue to try next driver
            }
        }

        // if we made it to this point, it means that user didn't provide any driver
        // and we are unable to create one from available candidates
        throw new P4Cms_Image_Exception("Cannot create image driver.");
    }
static P4Cms_Image_Driver_Factory::getDriverClasses ( ) [static]

Return list of driver classes the factory is aware of.

Returns:
array list with available driver classes
    {
        return static::$_drivers;
    }
static P4Cms_Image_Driver_Factory::isValidType ( className) [static]

Determine if the given Image driver type is valid.

Parameters:
string$classNamethe driver implementation class name to check
Returns:
bool true if the given Driver class exists and implements P4Cms_Image_Driver_Interface, false otherwise
    {
        if (!class_exists($className)) {
            return false;
        }
        if (!in_array('P4Cms_Image_Driver_Interface', class_implements($className))) {
            return false;
        }

        return true;
    }

Member Data Documentation

P4Cms_Image_Driver_Factory::$_drivers [static, protected]
Initial value:
 array(
        'P4Cms_Image_Driver_Imagick',
        'P4Cms_Image_Driver_Gd'
    )

The documentation for this class was generated from the following file: