From b67f1bafb7f61b4c3f299220454c3ddfe7c53002 Mon Sep 17 00:00:00 2001 From: Adam Backstrom Date: Wed, 23 May 2012 11:18:49 -0400 Subject: [PATCH] OBJECT ALL THE THINGS :fist: --- classes.php | 153 ++++++++++++++++++++++++++++++++++++++++++++++++++ functions.php | 19 +++++++ index.php | 35 ++++++++++-- 3 files changed, 201 insertions(+), 6 deletions(-) create mode 100644 classes.php create mode 100644 functions.php diff --git a/classes.php b/classes.php new file mode 100644 index 0000000..b194030 --- /dev/null +++ b/classes.php @@ -0,0 +1,153 @@ +value = $value; + } + + public function setContainer( ContainerInterface $container ) + { + $this->container = $container; + } + + public function setFormatter( FormatterInterface $formatter ) + { + $this->formatter = $formatter; + } + + public function esc_raw() + { + return nl2br( htmlentities( $this->value ) ); + } + + abstract public function decode(); + + public function __toString() + { + $value = $this->decode(); + $formatted = $this->formatter->format( $value ); + return $this->container->wrap( $formatted ); + } +} + +class ActionQuotedPrintableDecode extends AbstractAction +{ + public function __construct( $value ) + { + parent::__construct( $value ); + $this->setContainer( new TextareaContainer ); + $this->setFormatter( new EchoFormatter ); + } + + public function decode() + { + return quoted_printable_decode( $this->value ); + } +} + +class ActionUrldecode extends AbstractAction +{ + public function __construct( $value ) + { + parent::__construct( $value ); + $this->setContainer( new TextareaContainer ); + $this->setFormatter( new EchoFormatter ); + } + + public function decode() + { + return urldecode( $this->value ); + } +} + +class ActionUrlencode extends AbstractAction +{ + public function __construct( $value ) + { + parent::__construct( $value ); + $this->setContainer( new TextareaContainer ); + $this->setFormatter( new EchoFormatter ); + } + + public function decode() + { + return urlencode( $this->value ); + } +} + +class ActionUnserialize extends AbstractAction +{ + public function __construct( $value ) + { + parent::__construct( $value ); + $this->setContainer( new DivContainer ); + $this->setFormatter( new DbugFormatter ); + } + + public function decode() + { + return unserialize( $this->value ); + } +} + +interface ContainerInterface +{ + public function wrap( $contents ); +} + +class DivContainer implements ContainerInterface +{ + public function wrap( $contents ) + { + return '
' . $contents . '
'; + } +} + +class TextareaContainer extends DivContainer +{ + public function wrap( $contents ) + { + return parent::wrap( '' ); + } +} + +interface FormatterInterface +{ + public function format( $value ); +} + +class DbugFormatter implements FormatterInterface +{ + public function format( $value ) + { + ob_start(); + new dBug( $value ); + return ob_get_clean(); + } +} + +class VardumpFormatter implements FormatterInterface +{ + public function format( $value ) + { + ob_start(); + var_dump( $value ); + return ob_get_clean(); + } +} + +class EchoFormatter implements FormatterInterface +{ + public function format( $value ) + { + return $value; + } +} diff --git a/functions.php b/functions.php new file mode 100644 index 0000000..89dd6b0 --- /dev/null +++ b/functions.php @@ -0,0 +1,19 @@ +