SuperClosure v2.0.0-alpha2 Release Notes

Release Date: 2014-02-05 // about 10 years ago
  • ๐Ÿ”„ Changelog

    • ๐Ÿ“œ There are are now 2 parses supported
      • AST Parser โ€“ Implemented with the nikic/PHPParser library. This parser is the most robust and allows you to
        0๏ธโƒฃ resolve magic constants and fully-qualified class names in your closure. This is the default parser.
      • Token Parser โ€“ Implemented using the code from the old jeremeamia/FunctionParser library. This library was
        ๐Ÿ‘‰ used in a previous version of SuperClosure, and has been ported back in. While it does not handle all edge cases
        like resolving magic constants, it is MUCH faster (at least an order of magnitude).
    • You can now serialize closure bindings โ€“ If you are using closures in PHP 5.4+, closures are bound to an object and
      scope such that you can reference $this inside of a closure. Unserialized closures from version 1 of SuperClosure
      needed to be rebound to an object manually to prevent failure in functions containing $this, but this version can
      ๐Ÿ– handle bindings just fine.
    • ๐Ÿ“œ The ability to turn features on and off โ€“ Closure parser objects accept an array of options that can allow you to
      ๐ŸŽ configure the capability vs. performance of your closure serialization. If you don't want to serialize closure
      bindings or resolve magic constants, you can turn those features off.
      • Along with this is a option called turbo_mode that turns all the non-essential features off, This will make
        closure serialization much faster, but is the least robust at handling edge cases.
    • The easy SuperClosure\serialize() function โ€“ If you have installed SuperClosure via Composer, then the
      SuperClosure\serialize() function will automagically be available. This allows you to easily serialize the closure
      with out have to import/use any of the classes from the library directly. This function also allows you to specify the
      ๐Ÿ“œ options for the parser.
    • ๐Ÿšš I removed Jeremeamia from the namespace. However, there is a class alias automatically
      specified for the SerializableClosure class to
      maintain some backwards compatibility. You can use either SuperClosure\SerializableClosure or
      Jeremeamia\SuperClosure\SerializableClosure.
    • ๐Ÿ“ฆ The package is now PSR-4 compliant.

    Is everything different and broken?

    It depends. Mostly no.

    If you were just using the SerializableClosure object, then it should work exactly the same way as before.

    $closure = new SerializableClosure($closure);$serialized = serialize($closure);
    

    ๐Ÿ“œ If you were relying directly on the ClosureParser object, then you will have breaking changes for sure. They likely
    will not be difficult to fix though since SuperClosure is still a small library. Just keep in mind that there is now
    ๐Ÿ“œ more than one type of parser available.

    Examples

    use SuperClosure\SerializableClosure;use SuperClosure\ClosureParser\Options;use SuperClosure\ClosureParser\Ast\AstParser;use SuperClosure\ClosureParser\Token\TokenParser;// TRADITIONAL MODE (Same as in v1.0; uses "ROBUST MODE")$closure = new SerializableClosure($closure);$serialized = serialize($closure);// ROBUST MODE (i.e., SLOW MODE) (Uses the AST parser with all features on)$serialized = SuperClosure\serialize($closure);// TURBO MODE (Uses the token parser, with all features off)$serialized = SuperClosure\serialize($closure, array(Options::TURBO\_MODE =\> true));// The rest are examples of mixing and matching features//-------------------------------------------------------// Does everything else, but ignores closure bindings// This is perfect for functions in PHP 5.4+ that are declared in a class, but do not reference `$this`$serialized = SuperClosure\serialize($closure, array(Options::HANDLE\_CLOSURE\_BINDINGS =\> false,));// Uses the Token parser implicitly, by disabling the features unique to the AST parser$serialized = SuperClosure\serialize($closure, array(Options::HANDLE\_MAGIC\_CONSTANTS =\> false,Options::HANDLE\_CLASS\_NAMES=\> false,));// Uses the Token parser explicitly$serialized = SuperClosure\serialize($closure, new TokenParser);// This is equivalent to TURBO MODE. ZOOOOOOM!!!$options = new Options(array(Options::VALIDATE\_TOKENS =\> false));$serialized = SuperClosure\serialize($closure, new TokenParser($options)));
    

    TODO

    • โœ… Unit Tests - I removed all of the previous unit tests due to the extreme changes. However, I currently have a
      โœ… suite of integration tests that exercise the code nicely and show how it handles different scenarios. I plan on adding
      ๐Ÿš€ the unit tests back before the stable release.
    • ๐Ÿ“š Documentation - A lot of the docblocks are missing, incomplete, or out of date. I'll work on fixing these us
      ๐Ÿš€ before the stable release as well.