PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/dev/tests/integration/framework/Magento/Test/Helper/Factory.php

https://bitbucket.org/jokusafet/magento2
PHP | 67 lines | 19 code | 3 blank | 45 comment | 1 complexity | 1f5cb20d6986d15f46e573c12d404a3b MD5 | raw file
  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  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@magentocommerce.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magentocommerce.com for more information.
  20. *
  21. * @category Magento
  22. * @package Magento_Test
  23. * @subpackage integration_tests
  24. * @copyright Copyright (c) 2012 X.commerce, Inc. (http://www.magentocommerce.com)
  25. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  26. */
  27. /**
  28. * Factory for helpers, used in Magento testing framework
  29. */
  30. class Magento_Test_Helper_Factory
  31. {
  32. /**
  33. * @var array
  34. */
  35. static protected $_instances = array();
  36. /**
  37. * Retrieves singleton instance of helper
  38. *
  39. * @param string $name
  40. * @return mixed
  41. */
  42. static public function getHelper($name)
  43. {
  44. if (!isset(self::$_instances[$name])) {
  45. $className = preg_replace('/[^_]*$/', ucfirst($name), __CLASS__, 1);
  46. self::$_instances[$name] = new $className();
  47. }
  48. return self::$_instances[$name];
  49. }
  50. /**
  51. * Sets custom helper instance to be used for specific name, or null to clear instance.
  52. * Returns previous instance (if any) or null (if no helper was defined).
  53. *
  54. * @param string $name
  55. * @param mixed $helper
  56. * @return mixed
  57. */
  58. static public function setHelper($name, $helper)
  59. {
  60. $old = isset(self::$_instances[$name]) ? self::$_instances[$name] : null;
  61. self::$_instances[$name] = $helper;
  62. return $old;
  63. }
  64. }