OSDN Git Service

Import current code.
[osdn-codes/wiki-parser.git] / sfjp / wiki / parser.php
1 <?php
2 namespace sfjp\Wiki;
3
4 class Parser {
5         public $text;
6         public $processor;
7
8         function __construct($context = null, $processor = null, $formatter = null) {
9                 if ($processor) {
10                         $this->processor = $processor;
11                 } else {
12                         $this->processor = new Processor\Trac();
13                 }
14                 if ($context)
15                         $this->processor->setContext($context);
16                 if ($formatter)
17                         $this->processor->setFormatter($formatter);
18                 $storage_class = $this->processor->getContext('storage.class');
19                 if (!$storage_class) $storage_class = 'Dummy';
20                 $c = new \ReflectionClass("sfjp\\Wiki\\Storage\\{$storage_class}");
21                 $storage = $c->newInstance();
22                 $this->processor->setContext(array('storage' => $storage));
23         }
24
25         public function parse($text) {
26                 $this->processor->reset();
27                 return $this->processor->process($text)->getFormattedText();
28         }
29
30         public function getFormattedText() {
31                 return $this->processor->getFormattedText();
32         }
33
34         public function isVary() {
35                 return $this->processor->isVary();
36         }
37   
38         public function setContext($c) {
39                 $this->processor->setContext($c);
40         }
41
42         public function getContext($key = null) {
43                 return $this->processor->getContext($key);
44         }
45
46         public function removeContext($key) {
47                 $this->processor->removeContext($key);
48         }
49
50         public function clearContext() {
51                 $this->processor->clearContext();
52         }
53
54         public function reset() {
55                 $this->processor->reset();
56         }
57 }