Last active
August 29, 2015 14:18
-
-
Save kandran/32e0e8d7a738616002be to your computer and use it in GitHub Desktop.
Revisions
-
kandran revised this gist
Apr 15, 2015 . 8 changed files with 54 additions and 55 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,6 +2,6 @@ require_once('Document.php'); class ConfigDocument extends Document { } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,11 @@ <?php require_once('IDocumentRenderer.php'); class Document { protected $data = array(); public function setData(array $data) { $this->data = $data; } public function accept(IDocumentRenderer $renderer) @@ -14,7 +15,6 @@ public function accept(IDocumentRenderer $renderer) public function getData() { return $this->data; } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,9 +2,9 @@ require_once('IDocumentRenderer.php'); abstract class DocumentRenderer implements IDocumentRenderer { protected $output; public function getOutput() { return $this->output; } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,13 +2,13 @@ require_once('DocumentRenderer.php'); class HtmlRenderer extends DocumentRenderer { public function visit(Document $document) { $data = $document->getData(); $this->output = "<table>"; foreach ($data as $key => $value) { $this->output .= "<tr><td>$key</td><td>$value</td></tr>"; } $this->output .= "<table>"; } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,6 @@ <?php require_once('Document.php'); interface IDocumentRenderer { public function visit(Document $document); } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,12 +2,12 @@ require_once('DocumentRenderer.php'); class TextRenderer extends DocumentRenderer { public function visit(Document $document) { $data = $document->getData(); $this->output = ""; foreach ($data as $key => $value) { $this->output .= "$key:$value\n"; } } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,13 +2,13 @@ require_once('DocumentRenderer.php'); class XmlRenderer extends DocumentRenderer { public function visit(Document $document) { $data = $document->getData(); $this->output = "<items>"; foreach ($data as $key => $value) { $this->output .= "<item key='$key'>$value</item>"; } $this->output .= "<items>"; } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,16 +4,17 @@ require_once('TextRenderer.php'); require_once('XMLRenderer.php'); function render($doc, $renderer) { $doc->accept($renderer); return htmlentities($renderer->getOutput()); } $doc = new ConfigDocument(); $doc->setData(array( "key1" => "value1", "key2" => 5 )); $htmlRenderer = new HtmlRenderer(); echo "<br/><br/>html <br/>" . render($doc, $htmlRenderer); @@ -22,6 +23,3 @@ function render($doc, $renderer){ $xmlRenderer = new XmlRenderer(); echo "<br/><br/>xml <br/>" . render($doc, $xmlRenderer); -
kandran revised this gist
Apr 8, 2015 . 2 changed files with 9 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ <?php require_once('Document.php'); class ConfigDocument extends Document{ } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ <?php require_once('ConfigDocument.php'); require_once('HtmlRenderer.php'); require_once('TextRenderer.php'); require_once('XMLRenderer.php'); @@ -9,7 +9,7 @@ function render($doc, $renderer){ return htmlentities($renderer->getOutput()); } $doc = new ConfigDocument(); $doc->setData(array( "key1" => "value1", "key2" => 5 -
kandran revised this gist
Apr 7, 2015 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,8 +5,8 @@ require_once('XMLRenderer.php'); function render($doc, $renderer){ $doc->accept($renderer); return htmlentities($renderer->getOutput()); } $doc = new Document(); @@ -15,13 +15,13 @@ function render($doc, $renderer){ "key2" => 5 )); $htmlRenderer = new HtmlRenderer(); echo "<br/><br/>html <br/>" . render($doc, $htmlRenderer); $textRenderer = new TextRenderer(); echo "<br/><br/>text <br/>" . render($doc, $textRenderer); $xmlRenderer = new XmlRenderer(); echo "<br/><br/>xml <br/>" . render($doc, $xmlRenderer); -
kandran revised this gist
Apr 7, 2015 . 4 changed files with 27 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ <?php require_once('DocumentRenderer.php'); class HtmlRenderer extends DocumentRenderer { public function visit(Document $document) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ <?php require_once('DocumentRenderer.php'); class TextRenderer extends DocumentRenderer { public function visit(Document $document) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ <?php require_once('DocumentRenderer.php'); class XmlRenderer extends DocumentRenderer { public function visit(Document $document) { $data = $document->getData(); $this->output = "<items>"; foreach ($data as $key => $value) { $this->output .= "<item key='$key'>$value</item>"; } $this->output .= "<items>"; } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,19 +2,26 @@ require_once('Document.php'); require_once('HtmlRenderer.php'); require_once('TextRenderer.php'); require_once('XMLRenderer.php'); function render($doc, $renderer){ $doc->accept($textRenderer); echo "<br/><br/>text output : <br/>" . htmlentities($renderer->getOutput()); } $doc = new Document(); $doc->setData(array( "key1" => "value1", "key2" => 5 )); $htmlRenderer = new HtmlRenderer(); render($doc, $htmlRenderer); $textRenderer = new TextRenderer(); render($doc, $textRenderer); $xmlRenderer = new XmlRenderer(); render($doc, $xmlRenderer); -
kandran revised this gist
Apr 7, 2015 . 6 changed files with 79 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,20 @@ <?php require_once('IDocumentRenderer.php'); class Document{ protected $data = array(); public function setData(array $data) { $this->data = $data; } public function accept(IDocumentRenderer $renderer) { $renderer->visit($this); } public function getData() { return $this->data; } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ <?php require_once('IDocumentRenderer.php'); abstract class DocumentRenderer implements IDocumentRenderer { protected $output; public function getOutput() { return $this->output; } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ <?php require_once('Document.php'); class HtmlRenderer extends DocumentRenderer { public function visit(Document $document) { $data = $document->getData(); $this->output = "<table>"; foreach ($data as $key => $value) { $this->output .= "<tr><td>$key</td><td>$value</td></tr>"; } $this->output .= "<table>"; } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ <?php require_once('Document.php'); interface IDocumentRenderer{ public function visit(Document $document); } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ <?php require_once('Document.php'); class TextRenderer extends DocumentRenderer { public function visit(Document $document) { $data = $document->getData(); $this->output = ""; foreach ($data as $key => $value) { $this->output .= "$key:$value\n"; } } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ <?php require_once('Document.php'); require_once('HtmlRenderer.php'); require_once('TextRenderer.php'); $doc = new Document(); $doc->setData(array( "key1" => "value1", "key2" => 5 )); $htmlRenderer = new HtmlRenderer(); $doc->accept($htmlRenderer); echo "<br/><br/>html output : <br/>" . htmlentities($htmlRenderer->getOutput()); $textRenderer = new TextRenderer(); $doc->accept($textRenderer); echo "<br/><br/>text output : <br/>" . htmlentities($textRenderer->getOutput()); -
kandran created this gist
Apr 7, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ <?php class Document{ }