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.
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
22 /** Zend_Memory_Exception */
23 require_once 'Zend/Memory/Manager.php';
25 /** Zend_Memory_Value */
26 require_once 'Zend/Memory/Value.php';
28 /** Zend_Memory_Container */
29 require_once 'Zend/Memory/Container.php';
31 /** Zend_Memory_Exception */
32 require_once 'Zend/Cache.php';
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
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
50 public static function factory($backend, $backendOptions = array())
52 if (strcasecmp($backend, 'none') == 0) {
53 return new Zend_Memory_Manager();
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;
67 if (!$backendIsFound) {
68 require_once 'Zend/Memory/Exception.php';
69 throw new Zend_Memory_Exception("Incorrect backend ($backend)");
72 $backendClass = 'Zend_Cache_Backend_' . $backend;
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';
78 $backendObject = new $backendClass($backendOptions);
80 return new Zend_Memory_Manager($backendObject);