Skip to content
Parses serialized PHP things to an AST
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
spec
src
.gitignore
.travis.yml
composer.json
composer.lock
phpspec.yml
psalm.xml
readme.md

readme.md

SerializedToAST Build Status Coverage Status

Parses serialized PHP data, without deserializing, into a simple AST.

Example

class Test {
    private $foo = "Private Foo";
    public $bar = 12345;
    protected $baz = ["lorem", "ipsum" => "dolor amet", 67890];
}

$parser = new Prewk\SerializedToAst;
$node = $parser->parse(serialize(new Test));

// Array representation..
$arrayAst = $node->toArray();

// ..or JSON (see below)
$jsonAst = json_encode($node);
{
    "type": "object",
    "public_properties": {
        "bar": {
            "type": "integer",
            "value": 12345
        }
    },
    "protected_properties": {
        "baz": {
            "type": "array",
            "items": {
                "0": {
                    "type": "string",
                    "value": "lorem"
                },
                "ipsum": {
                    "type": "string",
                    "value": "dolor amet"
                },
                "1": {
                    "type": "integer",
                    "value": 67890
                }
            }
        }
    },
    "private_properties": {
        "foo": {
            "type": "string",
            "value": "Private Foo"
        }
    }
}

Installation

composer require prewk/serialized-to-ast

Works for

  • Booleans
  • Integers
  • Strings
  • Floats
  • Null
  • Arrays
  • Objects

Will cry if fed other stuff.

Warning: Experimental and not tested for edge cases.

License

MIT

You can’t perform that action at this time.