InstanceFactory.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\App\Cache;
  7. class InstanceFactory
  8. {
  9. /**
  10. * @var \Magento\Framework\ObjectManagerInterface
  11. */
  12. protected $_objectManager;
  13. /**
  14. * @param \Magento\Framework\ObjectManagerInterface $objectManager
  15. */
  16. public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager)
  17. {
  18. $this->_objectManager = $objectManager;
  19. }
  20. /**
  21. * Get cache instance model
  22. *
  23. * @param string $instanceName
  24. * @return \Magento\Framework\Cache\FrontendInterface
  25. * @throws \UnexpectedValueException
  26. */
  27. public function get($instanceName)
  28. {
  29. $instance = $this->_objectManager->get($instanceName);
  30. if (!$instance instanceof \Magento\Framework\Cache\FrontendInterface) {
  31. throw new \UnexpectedValueException("Cache type class '{$instanceName}' has to be a cache frontend.");
  32. }
  33. return $instance;
  34. }
  35. }