Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Log / LoggerAbstractServiceFactory.php
blobe392877bdf1a00d8aaed3036d1e13ef76de7963d
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\Log;
12 use Zend\ServiceManager\AbstractFactoryInterface;
13 use Zend\ServiceManager\ServiceLocatorInterface;
15 /**
16 * Logger abstract service factory.
18 * Allow to configure multiple loggers for application.
20 class LoggerAbstractServiceFactory implements AbstractFactoryInterface
22 /**
23 * @var array
25 protected $config;
27 /**
28 * Configuration key holding logger configuration
30 * @var string
32 protected $configKey = 'log';
34 /**
35 * @param ServiceLocatorInterface $services
36 * @param string $name
37 * @param string $requestedName
38 * @return bool
40 public function canCreateServiceWithName(ServiceLocatorInterface $services, $name, $requestedName)
42 $config = $this->getConfig($services);
43 if (empty($config)) {
44 return false;
47 return isset($config[$requestedName]);
50 /**
51 * @param ServiceLocatorInterface $services
52 * @param string $name
53 * @param string $requestedName
54 * @return Logger
56 public function createServiceWithName(ServiceLocatorInterface $services, $name, $requestedName)
58 $config = $this->getConfig($services);
59 $config = $config[$requestedName];
60 $this->processConfig($config, $services);
61 return new Logger($config);
64 /**
65 * Retrieve configuration for loggers, if any
67 * @param ServiceLocatorInterface $services
68 * @return array
70 protected function getConfig(ServiceLocatorInterface $services)
72 if ($this->config !== null) {
73 return $this->config;
76 if (!$services->has('Config')) {
77 $this->config = array();
78 return $this->config;
81 $config = $services->get('Config');
82 if (!isset($config[$this->configKey])) {
83 $this->config = array();
84 return $this->config;
87 $this->config = $config[$this->configKey];
88 return $this->config;
91 protected function processConfig(&$config, ServiceLocatorInterface $services)
93 if (!isset($config['writers'])) {
94 return;
97 foreach ($config['writers'] as $index => $writerConfig) {
98 if (!isset($writerConfig['name'])
99 || strtolower($writerConfig['name']) != 'db'
101 continue;
103 if (!isset($writerConfig['options'])
104 || !isset($writerConfig['options']['db'])
106 continue;
108 if (!is_string($writerConfig['options']['db'])) {
109 continue;
111 if (!$services->has($writerConfig['options']['db'])) {
112 continue;
115 // Retrieve the DB service from the service locator, and
116 // inject it into the configuration.
117 $db = $services->get($writerConfig['options']['db']);
118 $config['writers'][$index]['options']['db'] = $db;