LogEngineRegistry.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP(tm) Project
  12. * @since CakePHP(tm) v 2.2
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Log;
  16. use Cake\Core\App;
  17. use Cake\Error;
  18. use Cake\Log\LogInterface;
  19. use Cake\Utility\ObjectRegistry;
  20. /**
  21. * Registry of loaded log engines
  22. */
  23. class LogEngineRegistry extends ObjectRegistry {
  24. /**
  25. * Resolve a logger classname.
  26. *
  27. * Part of the template method for Cake\Utility\ObjectRegistry::load()
  28. *
  29. * @param string $class Partial classname to resolve.
  30. * @return string|false Either the correct classname or false.
  31. */
  32. protected function _resolveClassName($class) {
  33. if (is_object($class)) {
  34. return $class;
  35. }
  36. return App::classname($class, 'Log/Engine', 'Log');
  37. }
  38. /**
  39. * Throws an exception when a logger is missing.
  40. *
  41. * Part of the template method for Cake\Utility\ObjectRegistry::load()
  42. *
  43. * @param string $class The classname that is missing.
  44. * @param string $plugin The plugin the logger is missing in.
  45. * @throws Cake\Error\Exception
  46. */
  47. protected function _throwMissingClassError($class, $plugin) {
  48. throw new Error\Exception(__d('cake_dev', 'Could not load class %s', $class));
  49. }
  50. /**
  51. * Create the logger instance.
  52. *
  53. * Part of the template method for Cake\Utility\ObjectRegistry::load()
  54. * @param string|LogInterface $class The classname or object to make.
  55. * @param array $settings An array of settings to use for the logger.
  56. * @return LogEngine The constructed logger class.
  57. * @throws Cake\Error\Exception when an object doesn't implement
  58. * the correct interface.
  59. */
  60. protected function _create($class, $settings) {
  61. if (is_object($class)) {
  62. $instance = $class;
  63. }
  64. if (!isset($instance)) {
  65. $instance = new $class($settings);
  66. }
  67. if ($instance instanceof LogInterface) {
  68. return $instance;
  69. }
  70. throw new Error\Exception(__d(
  71. 'cake_dev',
  72. 'Loggers must implement Cake\Log\LogInterface.'
  73. ));
  74. }
  75. /**
  76. * Remove a single logger from the registry.
  77. *
  78. * @param string $name The logger name.
  79. * @return void
  80. */
  81. public function unload($name) {
  82. unset($this->_loaded[$name]);
  83. }
  84. }