/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. /** Zend_Memory_Exception */
  22. require_once 'Zend/Memory/Manager.php';
  23. /** Zend_Memory_Value */
  24. require_once 'Zend/Memory/Value.php';
  25. /** Zend_Memory_Container */
  26. require_once 'Zend/Memory/Container.php';
  27. /** Zend_Memory_Exception */
  28. require_once 'Zend/Cache.php';
  29. /**
  30. * @category Zend
  31. * @package Zend_Memory
  32. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  33. * @license http://framework.zend.com/license/new-bsd New BSD License
  34. */
  35. class Zend_Memory
  36. {
  37. /**
  38. * Factory
  39. *
  40. * @param string $backend backend name
  41. * @param array $backendOptions associative array of options for the corresponding backend constructor
  42. * @return Zend_Memory_Manager
  43. * @throws Zend_Memory_Exception
  44. */
  45. public static function factory($backend, $backendOptions = array())
  46. {
  47. if (strcasecmp($backend, 'none') == 0) {
  48. return new Zend_Memory_Manager();
  49. }
  50. // Look through available backendsand
  51. // (that allows to specify it in any case)
  52. $backendIsFound = false;
  53. foreach (Zend_Cache::$availableBackends as $zendCacheBackend) {
  54. if (strcasecmp($backend, $zendCacheBackend) == 0) {
  55. $backend = $zendCacheBackend;
  56. $backendIsFound = true;
  57. break;
  58. }
  59. }
  60. if (!$backendIsFound) {
  61. require_once 'Zend/Memory/Exception.php';
  62. throw new Zend_Memory_Exception("Incorrect backend ($backend)");
  63. }
  64. $backendClass = 'Zend_Cache_Backend_' . $backend;
  65. // For perfs reasons, we do not use the Zend_Loader::loadClass() method
  66. // (security controls are explicit)
  67. require_once str_replace('_', DIRECTORY_SEPARATOR, $backendClass) . '.php';
  68. $backendObject = new $backendClass($backendOptions);
  69. return new Zend_Memory_Manager($backendObject);
  70. }
  71. }