source: branches/beta/html/test/adachi/PLLagger/PLLagger.php @ 15120

Revision 15120, 2.6 KB checked in by adati, 17 years ago (diff)

1.4.2betaのマージ

Line 
1<?php
2require_once('PLLagger/Util.php');
3//require_once('PLLgger/Constant.php');
4
5class PLLagger {
6    private $config;
7    private $plugins;
8    private $feeds;
9    private $update_feeds;
10    private $corrent_phase;
11   
12    public function __construct($config){
13        $this->config  = $config;
14        $this->plugins = array();
15        $this->feeds   = array();
16        $this->update_feeds  = array();
17        $this->corrent_phase = 'Init';
18    }
19   
20    public function run () {
21        $this->load_plugins();
22       
23        $phases = array(
24            'Subscription',
25            'Filter',
26            'Publish'
27        );
28       
29        foreach ( $phases as $phase ) {
30            $this->corrent_phase = $phase;
31            $plugins = $this->get_plugins($phase);
32           
33            foreach ( $plugins as $plugin ) {
34                $plugin->execute($this);
35            }
36        }
37    }
38   
39    private function load_plugins () {
40        foreach ($this->config['plugins'] as $name => $config) {
41            $class   = 'PLLagger_Plugin_' . $name;
42            $include = preg_replace('/_/', '/', $class) . '.php';
43            $ret     = include_once($include);
44           
45            $err = 0;
46           
47            if ($ret) {
48                if ( preg_match("/^(.+?)_/", $name, $matches) ) {
49                    $phase = $matches[1];
50                    $this->plugins[$phase][] = new $class($this, $config);
51                    $this->log('[OK] ' . $class . ' loaded');
52                }
53                else {
54                    $this->log('[ERR] ' . 'class name is invalid: ' . $class);
55                    $err++;
56                }
57            }
58            else {
59                $this->log('[ERR] ' . $class . ' not found');
60                $err++;
61            }
62        }
63       
64        if ($err) {
65            $this->_die('function load_plugins()');
66        }
67    }
68   
69    public function log ($msg) {
70        PLLagger_Util::log($this->corrent_phase, $msg);
71    }
72   
73    public function p ($var) {
74        PLLagger_Util::p($var);
75    }
76   
77    public function _die ($msg) {
78        $this->log('[DIE] ' . $msg);
79        exit();
80    }
81   
82    private function get_plugins ($phase) {
83        if ( empty($this->plugins[$phase]) ) {
84            return array();
85        }
86        return $this->plugins[$phase];
87    }
88   
89    public function get_feeds () {
90        if ( count($this->update_feeds) > 0 ) {
91            return $this->update_feeds;
92        }
93        return $this->feeds;
94    }
95   
96    public function add_feed ($feed) {
97        $this->feeds[] = $feed;
98    }
99   
100    public function update_feed ($feed) {
101   
102    }
103}
104?>
Note: See TracBrowser for help on using the repository browser.