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
|
interface ContainerInterface
|
||||||
{
|
{
|
||||||
public function wrap( $contents );
|
public function wrap( $contents );
|
||||||
@ -169,23 +199,39 @@ interface FormatterInterface
|
|||||||
public function format( $value );
|
public function format( $value );
|
||||||
}
|
}
|
||||||
|
|
||||||
class DbugFormatter implements FormatterInterface
|
abstract class BufferedFormatter implements FormatterInterface {
|
||||||
{
|
const ESCAPE = false;
|
||||||
public function format( $value )
|
|
||||||
{
|
public function format( $value ) {
|
||||||
ob_start();
|
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 );
|
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 );
|
var_dump( $value );
|
||||||
return ob_get_clean();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,3 +242,13 @@ class EchoFormatter implements FormatterInterface
|
|||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class VarexportFormatter extends BufferedFormatter
|
||||||
|
{
|
||||||
|
const ESCAPE = true;
|
||||||
|
|
||||||
|
public function bufferedFormat( $value )
|
||||||
|
{
|
||||||
|
var_export( $value );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -41,6 +41,8 @@ if( 'POST' === $_SERVER['REQUEST_METHOD'] ) {
|
|||||||
<option value="Unserialize" <?php echo selected($action_str, 'Unserialize'); ?>>unserialize()</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="Base64Decode" <?php echo selected($action_str, 'Base64Decode'); ?>>base64_decode()</option>
|
||||||
<option value="Base64Encode" <?php echo selected($action_str, 'Base64Encode'); ?>>base64_encode()</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>
|
<select>
|
||||||
<input type="submit">
|
<input type="submit">
|
||||||
</form>
|
</form>
|
||||||
|
Loading…
Reference in New Issue
Block a user