Memory.php 2.3 KB

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