File indexing completed on 2024-12-22 05:37:17

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Memory
0017  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0018  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0019  * @version    $Id$
0020  */
0021 
0022 /** Zend_Memory_Exception */
0023 // require_once 'Zend/Memory/Manager.php';
0024 
0025 /** Zend_Memory_Value */
0026 // require_once 'Zend/Memory/Value.php';
0027 
0028 /** Zend_Memory_Container */
0029 // require_once 'Zend/Memory/Container.php';
0030 
0031 /** Zend_Memory_Exception */
0032 // require_once 'Zend/Cache.php';
0033 
0034 /**
0035  * @category   Zend
0036  * @package    Zend_Memory
0037  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0038  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0039  */
0040 class Zend_Memory
0041 {
0042     /**
0043      * Factory
0044      *
0045      * @param string $backend backend name
0046      * @param array $backendOptions associative array of options for the corresponding backend constructor
0047      * @return Zend_Memory_Manager
0048      * @throws Zend_Memory_Exception
0049      */
0050     public static function factory($backend, $backendOptions = array())
0051     {
0052         if (strcasecmp($backend, 'none') == 0) {
0053             return new Zend_Memory_Manager();
0054         }
0055 
0056         // Look through available backendsand
0057         // (that allows to specify it in any case)
0058         $backendIsFound = false;
0059         foreach (Zend_Cache::$standardBackends as $zendCacheBackend) {
0060             if (strcasecmp($backend, $zendCacheBackend) == 0) {
0061                 $backend = $zendCacheBackend;
0062                 $backendIsFound = true;
0063                 break;
0064             }
0065         }
0066 
0067         if (!$backendIsFound) {
0068             // require_once 'Zend/Memory/Exception.php';
0069             throw new Zend_Memory_Exception("Incorrect backend ($backend)");
0070         }
0071 
0072         $backendClass = 'Zend_Cache_Backend_' . $backend;
0073 
0074         // For perfs reasons, we do not use the Zend_Loader::loadClass() method
0075         // (security controls are explicit)
0076         // require_once str_replace('_', DIRECTORY_SEPARATOR, $backendClass) . '.php';
0077 
0078         $backendObject = new $backendClass($backendOptions);
0079 
0080         return new Zend_Memory_Manager($backendObject);
0081     }
0082 }