source: branches/dev/html/test/adachi/LLReader/LLReader.php @ 14612

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