root/trunk/src/main/php/net/stubbles/util/log/stubLogDataFactory.php

Revision 1534, 2.2 kB (checked in by mikey, 1 month ago)

refactoring #139, part 1: moved net::stubbles::util::stubRegistry to net::stubbles::lang::stubRegistry

Line 
1 <?php
2 /**
3  * Factory to create log data objects.
4  *
5  * @author      Frank Kleine <mikey@stubbles.net>
6  * @package     stubbles
7  * @subpackage  util_log
8  */
9 stubClassLoader::load('net::stubbles::ioc::stubBinder',
10                       'net::stubbles::lang::stubRegistry',
11                       'net::stubbles::lang::exceptions::stubRuntimeException',
12                       'net::stubbles::util::log::stubLogData',
13                       'net::stubbles::util::log::stubLogger'
14 );
15 /**
16  * Factory to create log data objects.
17  *
18  * @static
19  * @package     stubbles
20  * @subpackage  util_log
21  */
22 class stubLogDataFactory
23 {
24     /**
25      * returns the injector instance
26      *
27      * @param  stubLogData  $logData
28      */
29     protected static function handleInjections(stubLogData $logData)
30     {
31         static $injector;
32         if (null === $injector) {
33             $binder = stubRegistry::get(stubBinder::REGISTRY_KEY);
34             if (($binder instanceof stubBinder) === false) {
35                 return;
36             }
37             
38             $injector = $binder->getInjector();
39         }
40         
41         $injector->handleInjections($logData);
42     }
43
44     /**
45      * creates a stubLogData object
46      *
47      * @param   string       $target  target where the log data should go to
48      * @param   int          $level   optional  log level of the log data
49      * @return  stubLogData
50      * @throws  stubRuntimeException
51      */
52     public static function create($target, $level = stubLogger::LEVEL_INFO)
53     {
54         $fqClassName = stubRegistry::getConfig(stubLogData::CLASS_REGISTRY_KEY, 'net::stubbles::util::log::stubBaseLogData');
55         $nqClassName = stubClassLoader::getNonQualifiedClassName($fqClassName);
56         if (class_exists($nqClassName, false) === false) {
57             stubClassLoader::load($fqClassName);
58         }
59         
60         $logData = new $nqClassName($target, $level);
61         if (($logData instanceof stubLogData) === false) {
62             throw new stubRuntimeException('Configured ' . stubLogData::CLASS_REGISTRY_KEY . ' is not an instance of net::stubbles::util::log::stubLogData.');
63         }
64         
65         self::handleInjections($logData);
66         return $logData;
67     }
68 }
69 ?>
Note: See TracBrowser for help on using the browser.