PackageTrack
Sign in Get early access

jeremeamia/superclosure

Abandoned; use opis/closure. Serialize Closure objects, including their context and binding

2.4.0 61M downloads/mo #1852 most downloaded on Packagist jeremeamia/super_closure

What this package is like to depend on

Last release 8 years ago

no release in 18 months

Release timing varies

gaps range from 9 days to 1.3 years

Most releases are documented

notes for 8 of 13 stable releases

Nothing withdrawn

no release was ever pulled

14 years old

15 releases · first in 2012

0 releases in the last 12 months

see the full history below

Release timeline

15 releases · Apr 2012 to Mar 2018
2013 2015 2017 2019 2021 2023 2025
Release Pre-release

Releases

latest 15
  1. 2.4.0 21 Mar 2018
    Release notes

    What's Changed

    • Added support for PHP Parser 4 and PHP 7.2.
    Open source →
  2. 2.3.0 07 Dec 2016
    Release notes

    What's Changed

    • Added support for PHP Parser 3 and PHP 7.1.
    • Identify failed serialization with signature option.
    Open source →
  3. 2.2.0 05 Dec 2015
    Release notes

    What's Changed

    • Added support for PHP 7.
    • Added support for version 2.x of @nikic's PHP Parser.
    • Added a bindTo() method to SerializableClosure to match Closure's interface.
    • Replaced vendored hash_equals() implementation with the one in symfony/polyfill-php56.
    • Fixed an issue that caused the "class" value of some closures' locations to be reported incorrectly.
    • Fixed an issue with some edge cases related the closure binding and scope during unserialization.
    • Fixed an unserialization issue where SuperClosures in user variables were not being unboxed.
    • Improved error handling in the Serializer when the data being unserialized is invalid.

    Credits

    Lessons Learned

    It's ParseError not ParseException.

    Open source →
  4. 2.1.0 11 Mar 2015
    Release notes
    Open source →
  5. 2.0.0 26 Jan 2015
    Release notes
    • Serializes closure bindings
    • Serializes recursive closures
    • Added Serializer object
      • Main class to interact with for serializing closures
      • Has special method for wrapping closures within an array/object
    • Changed the ClosureParser into ClosureAnalyzer
      • There are two kinds of analyzers:
        • AstAnalyzer - Uses PHPParser library; many features
        • TokenAnalyzer - Uses token_get_all(); fast
      • Analyzers return an array of data about a closure
    • Removed Jeremeamia from the namespace
    • Adopted PSR-4
    • Requires PHP 5.4+
    Open source →
  6. 2.0.0-beta.1 19 Jan 2015 pre-release
    Release notes

    There are lots of big changes again, but I'm finally happy with the project's structure. There is some more testing and docs to do, but there shouldn't be any drastic changes at this point forward. Please see the README on the master branch for the latest information.

    Open source →
  7. 2.0.0-alpha2 05 Feb 2014 pre-release
    Release notes

    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
        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.
    Open source →
  8. 1.0.2 10 Jan 2015
    Release notes

    Note: This is the final 1.x release.

    • Fixed #23, where "Undefined Variable Error" was being thrown for used variables whose that had a value of null.
    Open source →
  9. 1.0.1 09 Oct 2013
    Release notes
    • Updated Composer dependencies to use a tagged release of PHP Parser.
    • Updated the SerializableClosure class to be easier to extend.
    Open source →
  10. 1.0.0 14 Jun 2013

    Nothing published for this version

  11. 0.9.2 26 May 2013

    Nothing published for this version

  12. 0.9.1 25 May 2013

    Nothing published for this version

  13. 0.9.0 14 Apr 2012

    Nothing published for this version

  14. 0.8.0 14 Jun 2013

    Nothing published for this version

  15. 2.0-alpha1 14 Jan 2014
    Release notes

    SuperClosure is getting an overhaul!

    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
        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 serialize_closure() function – If you have installed SuperClosure via Composer, then the
      serialize_closure() 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.
    • The package is now PSR-4 compliant. As soon as TravisCI is ready and Jordi (Composer author) gives the PHP world the
      green light, I'll remove the provided autoload.php in favor of Composer's PSR-4 support.

    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

    // ROBUST MODE (i.e., SLOW MODE) (Uses the AST parser with all features on)
    $serialized = serialize_closure($closure);
    
    // TURBO MODE (Uses the token parser, with all features off)
    $serialized = serialize_closure($closure, array(SC_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 = serialize_closure($closure, array(
        SC_HANDLE_CLOSURE_BINDINGS => false,
    ));
    
    // Uses the Token parser explicitly
    $serialized = serialize_closure($closure, array(
        SC_PARSER_CLASS => SC_PARSER_TOKEN,
    ));
    
    // Uses the Token parser implicitly, by disabling the features unique to the AST parser
    $serialized = serialize_closure($closure, array(
        SC_HANDLE_MAGIC_CONSTANTS => false,
        SC_HANDLE_CLASS_NAMES     => false,
    ));
    
    // This is equivalent to TURBO MODE. ZOOOOOOM!!!
    $serialized = serialize_closure($closure, array(
        SC_PARSER_CLASS    => SC_PARSER_TOKEN,
        SC_VALIDATE_TOKENS => false,
    ));

    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.
    • Collect Feedback - I've made a lot of changes. I'd love to hear what you think. Do you like the changes? Do the
      config settings make sense? Do the config defaults work well? Let me know if you have any suggestions,
      feedback, ideas, complaints, etc.
    Open source →

Every package, every release, already written down.

The archive is open and free. Watching your own project is what we are building next.

Browse the archive