Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #28231 [VarExporter] a new component to serialize values to p…
…lain PHP code (nicolas-grekas) This PR was merged into the 4.2-dev branch. Discussion ---------- [VarExporter] a new component to serialize values to plain PHP code | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - This PR proposes moving what is currently the `PhpMarshaller` class in the Cache component to a separate component. This component would provide only one public static method: `VarExporter::export($value, bool &$isStaticValue = null): string`. This method returns `$value` serialized as plain PHP code. Running this code creates the same exact data structure that `$value` contained. This is exactly like `serialize()` and `unserialize()`, from which all semantics are preserved (`__sleep`, `__wakeup` and `Serializable`). The reason to use this method *vs* `serialize()` or even igbinary is performance: thanks to OPcache, the resulting code is significantly faster and more memory efficient than using `unserialize()` or `igbinary_unserialize()`. Unlike `var_export()`, this works on any serializable PHP value. It also provides a few improvements over `var_export()`/`serialize()`: - the output is PSR-2 compatible - the output can be re-indented without messing up with any `\r` or `\n` in the data - missing classes throw a `ReflectionException` instead of being unserialized to a `PHP_Incomplete_Class` object - references involving `SplObjectStorage`, `ArrayObject` or `ArrayIterator` instances are preserved - `Reflection*`, `IteratorIterator` and `RecursiveIteratorIterator` classes throw an exception when being serialized (their unserialized version is broken anyway, see https://bugs.php.net/76737.) Commits ------- 7831ad7 [VarExporter] a new component to serialize values to plain PHP code
- Loading branch information
Showing
47 changed files
with
651 additions
and
433 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 0 additions & 29 deletions
29
src/Symfony/Component/Cache/Tests/Marshaller/Fixtures/array-iterator.php
This file was deleted.
Oops, something went wrong.
29 changes: 0 additions & 29 deletions
29
src/Symfony/Component/Cache/Tests/Marshaller/Fixtures/array-object-custom.php
This file was deleted.
Oops, something went wrong.
37 changes: 0 additions & 37 deletions
37
src/Symfony/Component/Cache/Tests/Marshaller/Fixtures/array-object.php
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
src/Symfony/Component/Cache/Tests/Marshaller/Fixtures/clone.php
This file was deleted.
Oops, something went wrong.
31 changes: 0 additions & 31 deletions
31
src/Symfony/Component/Cache/Tests/Marshaller/Fixtures/datetime.php
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
src/Symfony/Component/Cache/Tests/Marshaller/Fixtures/hard-references-recursive.php
This file was deleted.
Oops, something went wrong.
26 changes: 0 additions & 26 deletions
26
src/Symfony/Component/Cache/Tests/Marshaller/Fixtures/hard-references.php
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
src/Symfony/Component/Cache/Tests/Marshaller/Fixtures/incomplete-class.php
This file was deleted.
Oops, something went wrong.
40 changes: 0 additions & 40 deletions
40
src/Symfony/Component/Cache/Tests/Marshaller/Fixtures/private.php
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
src/Symfony/Component/Cache/Tests/Marshaller/Fixtures/serializable.php
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
src/Symfony/Component/Cache/Tests/Marshaller/Fixtures/simple-array.php
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
src/Symfony/Component/Cache/Tests/Marshaller/Fixtures/spl-object-storage.php
This file was deleted.
Oops, something went wrong.
31 changes: 0 additions & 31 deletions
31
src/Symfony/Component/Cache/Tests/Marshaller/Fixtures/wakeup.php
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.