TYPO3  7.6
Diff.php
Go to the documentation of this file.
1 <?php
2 
19 namespace cogpowered\FineDiff;
20 
27 
31 class Diff
32 {
36  protected $granularity;
37 
41  protected $renderer;
42 
46  protected $parser;
47 
59  {
60  // Set some sensible defaults
61 
62  // Set the granularity of the diff
63  $this->granularity = ($granularity !== null) ? $granularity : new Character;
64 
65  // Set the renderer to use when calling Diff::render
66  $this->renderer = ($renderer !== null) ? $renderer : new Html;
67 
68  // Set the diff parser
69  $this->parser = ($parser !== null) ? $parser : new Parser($this->granularity);
70  }
71 
77  public function getGranularity()
78  {
79  return $this->parser->getGranularity();
80  }
81 
89  {
90  $this->parser->setGranularity($granularity);
91  }
92 
98  public function getRenderer()
99  {
100  return $this->renderer;
101  }
102 
110  {
111  $this->renderer = $renderer;
112  }
113 
119  public function getParser()
120  {
121  return $this->parser;
122  }
123 
131  {
132  $this->parser = $parser;
133  }
134 
143  public function getOpcodes($from_text, $to_text)
144  {
145  return $this->parser->parse($from_text, $to_text);
146  }
147 
157  public function render($from_text, $to_text)
158  {
159  // First we need the opcodes
160  $opcodes = $this->getOpcodes($from_text, $to_text);
161 
162  return $this->renderer->process($from_text, $opcodes);
163  }
164 }