PageRenderTime 15ms CodeModel.GetById 6ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/framework/vendor/zend/Zend/Memory.php

http://zoop.googlecode.com/
PHP | 82 lines | 30 code | 11 blank | 41 comment | 5 complexity | 57a29adc2daf82f5bc5bea8c64ddb786 MD5 | raw file
 1<?php
 2/**
 3 * Zend Framework
 4 *
 5 * LICENSE
 6 *
 7 * This source file is subject to the new BSD license that is bundled
 8 * with this package in the file LICENSE.txt.
 9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
14 *
15 * @category   Zend
16 * @package    Zend_Memory
17 * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18 * @license    http://framework.zend.com/license/new-bsd     New BSD License
19 * @version    $Id: Memory.php 20805 2010-02-01 15:52:15Z alexander $
20 */
21
22/** Zend_Memory_Exception */
23require_once 'Zend/Memory/Manager.php';
24
25/** Zend_Memory_Value */
26require_once 'Zend/Memory/Value.php';
27
28/** Zend_Memory_Container */
29require_once 'Zend/Memory/Container.php';
30
31/** Zend_Memory_Exception */
32require_once 'Zend/Cache.php';
33
34/**
35 * @category   Zend
36 * @package    Zend_Memory
37 * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
38 * @license    http://framework.zend.com/license/new-bsd     New BSD License
39 */
40class Zend_Memory
41{
42    /**
43     * Factory
44     *
45     * @param string $backend backend name
46     * @param array $backendOptions associative array of options for the corresponding backend constructor
47     * @return Zend_Memory_Manager
48     * @throws Zend_Memory_Exception
49     */
50    public static function factory($backend, $backendOptions = array())
51    {
52        if (strcasecmp($backend, 'none') == 0) {
53            return new Zend_Memory_Manager();
54        }
55
56        // Look through available backendsand
57        // (that allows to specify it in any case)
58        $backendIsFound = false;
59        foreach (Zend_Cache::$availableBackends as $zendCacheBackend) {
60            if (strcasecmp($backend, $zendCacheBackend) == 0) {
61                $backend = $zendCacheBackend;
62                $backendIsFound = true;
63                break;
64            }
65        }
66
67        if (!$backendIsFound) {
68            require_once 'Zend/Memory/Exception.php';
69            throw new Zend_Memory_Exception("Incorrect backend ($backend)");
70        }
71
72        $backendClass = 'Zend_Cache_Backend_' . $backend;
73
74        // For perfs reasons, we do not use the Zend_Loader::loadClass() method
75        // (security controls are explicit)
76        require_once str_replace('_', DIRECTORY_SEPARATOR, $backendClass) . '.php';
77
78        $backendObject = new $backendClass($backendOptions);
79
80        return new Zend_Memory_Manager($backendObject);
81    }
82}