### Install sebastian/exporter using Composer Source: https://github.com/sebastianbergmann/exporter/blob/main/README.md Demonstrates how to add the sebastian/exporter library to a project as a local or development dependency using Composer. ```bash composer require sebastian/exporter composer require --dev sebastian/exporter ``` -------------------------------- ### Exporter: Optimize String Export Shortcut Source: https://github.com/sebastianbergmann/exporter/blob/main/ChangeLog.md Implements a shortcut for exporting strings, making the process more efficient, as noted in issue #60. ```php public function export(mixed $value): string { if (is_string($value)) { return $value; } // ... rest of the export logic ... } ``` -------------------------------- ### Exporter: Optimize Exporter::exportString() Source: https://github.com/sebastianbergmann/exporter/blob/main/ChangeLog.md Improves the performance of the `Exporter::exportString()` method, as noted in issue #64. Also addresses unnecessary calls to `str_repeat()` in issue #65. ```php public function exportString(mixed $value): string { // Optimization for string export if (is_string($value)) { return $value; } // ... rest of the export logic } ``` -------------------------------- ### Compact Exports using shortenedExport Source: https://github.com/sebastianbergmann/exporter/blob/main/README.md Shows how to use the `shortenedExport` method for a more concise representation of PHP arrays, objects, and long strings. ```php shortenedExport(array()); // Array (...) print $exporter->shortenedExport(array(1,2,3,4,5)); // stdClass Object () print $exporter->shortenedExport(new stdClass); // Exception Object (...) print $exporter->shortenedExport(new Exception); // this\nis\na\nsuper\nlong\nstring\nt...\nspace print $exporter->shortenedExport( << ``` -------------------------------- ### Exporter: Improve Enumeration Export Source: https://github.com/sebastianbergmann/exporter/blob/main/ChangeLog.md Enhances the export process for enumerations, as detailed in issue #42. ```php public function exportEnum(UnitEnum $value): string { // Logic to export enumerations // ... } ``` -------------------------------- ### Exporter: Improve Closed Resource Export Source: https://github.com/sebastianbergmann/exporter/blob/main/ChangeLog.md Enhances the way closed resources are exported, as detailed in issue #37. ```php public function exportResource(mixed $value): string { if (is_resource($value) && get_resource_type($value) === 'Unknown') { return '[closed resource]'; } // ... rest of the export logic ... } ``` -------------------------------- ### Exporting Simple PHP Data Types Source: https://github.com/sebastianbergmann/exporter/blob/main/README.md Illustrates exporting various simple PHP data types such as integers, floats, strings, booleans, NAN, INF, null, resources, and binary strings. ```php export(46); // 4.0 print $exporter->export(4.0); // 'hello, world!' print $exporter->export('hello, world!'); // false print $exporter->export(false); // NAN print $exporter->export(acos(8)); // -INF print $exporter->export(log(0)); // null print $exporter->export(null); // resource(13) of type (stream) print $exporter->export(fopen('php://stderr', 'w')); // Binary String: 0x000102030405 print $exporter->export(chr(0) . chr(1) . chr(2) . chr(3) . chr(4) . chr(5)); ?> ``` -------------------------------- ### Exporter: Handle Recursion Warning Source: https://github.com/sebastianbergmann/exporter/blob/main/ChangeLog.md Addresses a `count(): Recursion detected` warning that could be triggered during the export process, as reported in issue #61. ```php public function export(mixed $value): string { // Logic to detect and handle recursion // ... } ``` -------------------------------- ### Exporter: Control Maximum String Length Source: https://github.com/sebastianbergmann/exporter/blob/main/ChangeLog.md Introduces an optional constructor argument to control the maximum string length for exports. This feature was also added as an optional argument to `shortenedRecursiveExport()` and `shortenedExport()`. ```php public function __construct(int $maximumStringLength = PHP_INT_MAX) public function shortenedRecursiveExport(mixed $value, int $maximumStringLength = PHP_INT_MAX): string public function shortenedExport(mixed $value, int $maximumStringLength = PHP_INT_MAX): string ``` -------------------------------- ### Exporter: Use Short Array Syntax Source: https://github.com/sebastianbergmann/exporter/blob/main/ChangeLog.md Updates the array export mechanism to utilize short array syntax, as per issue #51. ```php public function exportArray(array $value): string { // ... export logic using short array syntax ... return '[' . implode(', ', $exportedItems) . ']'; } ``` -------------------------------- ### Exporting a PHP Exception Object Source: https://github.com/sebastianbergmann/exporter/blob/main/README.md Shows how to use the Exporter class to export a PHP Exception object, displaying its properties. ```php export(new Exception); ?> ``` -------------------------------- ### Exporter: Avoid Lazy Object Initialization Source: https://github.com/sebastianbergmann/exporter/blob/main/ChangeLog.md This change optimizes the export process by preventing the initialization of lazy objects during export, as detailed in issue #69. ```php /** * @internal */ public function __construct( private readonly Exporter $exporter = new self() ) {} // ... other methods ``` -------------------------------- ### Exporter: Optimize Large Array and Object Graph Export Source: https://github.com/sebastianbergmann/exporter/blob/main/ChangeLog.md Improves the efficiency of exporting large arrays and complex object graphs, as described in issue #52. ```php public function export(mixed $value): string { // Optimized logic for large arrays and object graphs // ... } ``` -------------------------------- ### Exporter: Fix str_repeat() Parameter Type Source: https://github.com/sebastianbergmann/exporter/blob/main/ChangeLog.md Corrects an issue where the second parameter for `str_repeat()` was not an integer, as identified in issue #29. ```php public function repeatString(string $string, int $times): string { // Ensure $times is an integer before calling str_repeat return str_repeat($string, $times); } ``` -------------------------------- ### Removed HHVM-Specific Code Source: https://github.com/sebastianbergmann/exporter/blob/main/ChangeLog.md This section details the removal of HHVM-specific code that is no longer required. This change was implemented in version 7.0.0 of the exporter project. ```text Removed HHVM-specific code that is no longer needed ``` -------------------------------- ### Exporter: Restore Default Array Export Behavior Source: https://github.com/sebastianbergmann/exporter/blob/main/ChangeLog.md Fixes an issue where the export of arrays was limited by default, restoring the behavior from versions prior to 6.1.0, as per issue #62. ```php public function exportArray(array $value): string { // Default behavior: no limit on array export // ... export logic ... } ``` -------------------------------- ### Exporter: Limit Array Export for Performance Source: https://github.com/sebastianbergmann/exporter/blob/main/ChangeLog.md Introduces an option to limit the export of large arrays to improve performance, particularly useful within PHPUnit, as described in issue #59. ```php public function __construct(int $maximumArrayItems = PHP_INT_MAX) public function exportArray(array $value): string { if (count($value) > $this->maximumArrayItems) { return sprintf( '[... %d items ...]', count($value) ); } // ... export logic ... } ``` -------------------------------- ### Exporting Complex PHP Data Types Source: https://github.com/sebastianbergmann/exporter/blob/main/README.md Demonstrates exporting complex PHP data types including nested arrays and objects with self-references. ```php export(array(array(1,2,3), array("",0,FALSE))); $array = array(); $array['self'] = &$array; print $exporter->export($array); $obj = new stdClass(); $obj->self = $obj; print $exporter->export($obj); ?> ``` -------------------------------- ### Exporter: Fix Float Export Precision Source: https://github.com/sebastianbergmann/exporter/blob/main/ChangeLog.md Corrects an issue related to the precision of exported floating-point numbers, as addressed in issue #47. ```php public function exportFloat(float $value): string { // Logic to ensure correct float precision during export // ... } ``` -------------------------------- ### Exporter: Fix SplObjectStorage Index Change Source: https://github.com/sebastianbergmann/exporter/blob/main/ChangeLog.md Resolves an issue where `Exporter::toArray()` inadvertently modified the index of `SplObjectStorage`, as reported in issue #49. ```php public function toArray(mixed $value): array { // Logic to correctly export SplObjectStorage without changing its index // ... } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.