Memory.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. * @package Zend_Memory
  16. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  17. * @license http://framework.zend.com/license/new-bsd New BSD License
  18. * @version $Id$
  19. */
  20. /** Zend_Memory_Exception */
  21. require_once 'Zend/Memory/Manager.php';
  22. /** Zend_Memory_Value */
  23. require_once 'Zend/Memory/Value.php';
  24. /** Zend_Memory_Container */
  25. require_once 'Zend/Memory/Container.php';
  26. /** Zend_Memory_Exception */
  27. require_once 'Zend/Cache.php';
  28. /**
  29. * @category Zend
  30. * @package Zend_Memory
  31. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  32. * @license http://framework.zend.com/license/new-bsd New BSD License
  33. */
  34. class Zend_Memory
  35. {
  36. /**
  37. * Factory
  38. *
  39. * @param string $backend backend name
  40. * @param array $backendOptions associative array of options for the corresponding backend constructor
  41. * @return Zend_Memory_Manager
  42. * @throws Zend_Memory_Exception
  43. */
  44. public static function factory($backend, $backendOptions = array())
  45. {
  46. if (strcasecmp($backend, 'none') == 0) {
  47. return new Zend_Memory_Manager();
  48. }
  49. // because lowercase will fail
  50. $backend = @ucfirst(strtolower($backend));
  51. if (!in_array($backend, Zend_Cache::$availableBackends)) {
  52. require_once 'Zend/Memory/Exception.php';
  53. throw new Zend_Memory_Exception("Incorrect backend ($backend)");
  54. }
  55. $backendClass = 'Zend_Cache_Backend_' . $backend;
  56. // For perfs reasons, we do not use the Zend_Loader::loadClass() method
  57. // (security controls are explicit)
  58. require_once str_replace('_', DIRECTORY_SEPARATOR, $backendClass) . '.php';
  59. $backendObject = new $backendClass($backendOptions);
  60. return new Zend_Memory_Manager($backendObject);
  61. }
  62. }