JSON encode/decode, plus abstract BufferedFormatter
Retab all the things.
This commit is contained in:
parent
70770d7cac
commit
2802ad66df
74
classes.php
74
classes.php
@ -143,6 +143,36 @@ class ActionUnserialize extends AbstractAction
|
||||
}
|
||||
}
|
||||
|
||||
class ActionJsonDecode extends AbstractAction
|
||||
{
|
||||
public function __construct( $value )
|
||||
{
|
||||
parent::__construct( $value );
|
||||
$this->setContainer( new DivContainer );
|
||||
$this->setFormatter( new VarexportFormatter );
|
||||
}
|
||||
|
||||
public function decode()
|
||||
{
|
||||
return json_decode( $this->value, true );
|
||||
}
|
||||
}
|
||||
|
||||
class ActionJsonEncode extends AbstractAction
|
||||
{
|
||||
public function __construct( $value )
|
||||
{
|
||||
parent::__construct( $value );
|
||||
$this->setContainer( new TextareaContainer );
|
||||
$this->setFormatter( new EchoFormatter );
|
||||
}
|
||||
|
||||
public function decode()
|
||||
{
|
||||
return json_encode( $this->value );
|
||||
}
|
||||
}
|
||||
|
||||
interface ContainerInterface
|
||||
{
|
||||
public function wrap( $contents );
|
||||
@ -169,23 +199,39 @@ interface FormatterInterface
|
||||
public function format( $value );
|
||||
}
|
||||
|
||||
class DbugFormatter implements FormatterInterface
|
||||
{
|
||||
public function format( $value )
|
||||
{
|
||||
abstract class BufferedFormatter implements FormatterInterface {
|
||||
const ESCAPE = false;
|
||||
|
||||
public function format( $value ) {
|
||||
ob_start();
|
||||
$this->bufferedFormat( $value );
|
||||
$output = ob_get_clean();
|
||||
|
||||
if (static::ESCAPE) {
|
||||
$output = '<pre>' . htmlentities($output) . '</pre>';
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
abstract public function bufferedFormat( $value );
|
||||
}
|
||||
|
||||
class DbugFormatter extends BufferedFormatter
|
||||
{
|
||||
public function bufferedFormat( $value )
|
||||
{
|
||||
new dBug( $value );
|
||||
return ob_get_clean();
|
||||
}
|
||||
}
|
||||
|
||||
class VardumpFormatter implements FormatterInterface
|
||||
class VardumpFormatter extends BufferedFormatter
|
||||
{
|
||||
public function format( $value )
|
||||
const ESCAPE = true;
|
||||
|
||||
public function bufferedFormat( $value )
|
||||
{
|
||||
ob_start();
|
||||
var_dump( $value );
|
||||
return ob_get_clean();
|
||||
}
|
||||
}
|
||||
|
||||
@ -196,3 +242,13 @@ class EchoFormatter implements FormatterInterface
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
class VarexportFormatter extends BufferedFormatter
|
||||
{
|
||||
const ESCAPE = true;
|
||||
|
||||
public function bufferedFormat( $value )
|
||||
{
|
||||
var_export( $value );
|
||||
}
|
||||
}
|
||||
|
10
index.php
10
index.php
@ -37,10 +37,12 @@ if( 'POST' === $_SERVER['REQUEST_METHOD'] ) {
|
||||
<option value="QuotedPrintableDecode" <?php echo selected($action_str, 'QuotedPrintableDecode'); ?>>quoted_printable_decode()</option>
|
||||
<option value="QuotedPrintableEncode" <?php echo selected($action_str, 'QuotedPrintableEncode'); ?>>quoted_printable_encode()</option>
|
||||
<option value="Urlencode" <?php echo selected($action_str, 'Urlencode'); ?>>urlencode()</option>
|
||||
<option value="Urldecode"<?php echo selected($action_str, 'Urldecode'); ?>>urldecode()</option>
|
||||
<option value="Unserialize"<?php echo selected($action_str, 'Unserialize'); ?>>unserialize()</option>
|
||||
<option value="Base64Decode"<?php echo selected($action_str, 'Base64Decode'); ?>>base64_decode()</option>
|
||||
<option value="Base64Encode"<?php echo selected($action_str, 'Base64Encode'); ?>>base64_encode()</option>
|
||||
<option value="Urldecode" <?php echo selected($action_str, 'Urldecode'); ?>>urldecode()</option>
|
||||
<option value="Unserialize" <?php echo selected($action_str, 'Unserialize'); ?>>unserialize()</option>
|
||||
<option value="Base64Decode" <?php echo selected($action_str, 'Base64Decode'); ?>>base64_decode()</option>
|
||||
<option value="Base64Encode" <?php echo selected($action_str, 'Base64Encode'); ?>>base64_encode()</option>
|
||||
<option value="JsonDecode" <?php echo selected($action_str, 'JsonDecode'); ?>>json_decode()</option>
|
||||
<option value="JsonEncode" <?php echo selected($action_str, 'JsonEncode'); ?>>json_encode()</option>
|
||||
<select>
|
||||
<input type="submit">
|
||||
</form>
|
||||
|
Loading…
Reference in New Issue
Block a user