RepositoryPHP
SY

symfony/var-exporter

Provides tools to export, instantiate, hydrate, clone and lazy-load PHP objects

2.1ksao
7fork
0issue
2lượt xem

🚀 VarExporter — Công cụ quản lý trạng thái nội bộ đối tượng PHP từ Symfony

Export, clone, instantiate, lazy-load — toàn bộ trong một thành phần nhẹ.

symfony/var-exporter là một thành phần của framework Symfony, cung cấp các công cụ để làm việc với trạng thái nội bộ của các đối tượng PHP bao gồm xuất (export), sao chép (clone), khởi tạo (instantiate) và tải lazy-loading. Thành phần này tận dụng OPcache để tối ưu hiệu năng và hỗ trợ cả tiện ích mở rộng PHP ext-deepclone hoặc polyfill tương đương.

✨ Điểm nổi bật

  • VarExporter::export(): Xuất mọi cấu trúc dữ liệu PHP tuần tự hóa thành mã PHP thuần, tuân thủ ngữ pháp PSR-2.
  • DeepCloner: Sao chép sâu các giá trị PHP, giữ nguyên ngữ nghĩa copy-on-write của PHP cho chuỗi và mảng.
  • ProxyHelper::generateLazyProxy(): Tạo proxy lazy-loading cho các lớp trừu tượng, lớp nội bộ và interface.
  • Hỗ trợ OPcache: Mã xuất ra nhanh hơn và tiết kiệm bộ nhớ hơn so với serialize() hoặc igbinary.
  • Bảo toàn tham chiếu phức tạp: Giữ nguyên tham chiếu trong SplObjectStorage, ArrayObject, ArrayIterator.
  • Xử lý lỗi chặt chẽ: Ném ClassNotFoundException thay vì tạo đối tượng PHP_Incomplete_Class.
  • Hạn chế lớp Reflection: Ngăn serialize các lớp Reflection*, IteratorIterator, RecursiveIteratorIterator.
  • Tích hợp ext-deepclone: Sử dụng deepclone_to_array(), deepclone_from_array() và deepclone_hydrate() để tăng tốc.

💡 Vì sao đáng chú ý

VarExporter vượt trội so với serialize() nhờ khả năng tận dụng OPcache, biến mã PHP thành mã thực thi trực tiếp nhanhan hơn và nhẹ hơn. DeepCloner tránh chi phí của serialize/unserialize bằng cách duy trì copy-on-write, giảm tiêu thụ bộ nhớ. Lazy proxy hữu ích cho các lớp nặng hoặc phụ thuộc phức tạp, trì hoãn khởi tạo đến thời điểm thực sự cần thiết.


#Symfony #PHP #VarExporter #LazyLoading #Clone #TiniX

Dự án tương tự

Khám phá các dự án và mô hình AI khác có sự tương đồng.

RepositoryPHP
symfony/console

Eases the creation of beautiful and testable command line interfaces

9.8k
Nov 30, 2026
RepositoryPHP
symfony/http-foundation

Defines an object-oriented layer for the HTTP specification

8.6k
Nov 28, 2026
RepositoryPHP
symfony/event-dispatcher

Provides tools that allow your application components to communicate with each other by dispatching events and listening to them

8.5k
Nov 28, 2026
RepositoryPHP
symfony/finder

Finds files and directories via an intuitive fluent interface

8.4k
Nov 13, 2026
RepositoryPHP
symfony/http-kernel

Provides a structured process for converting a Request into a Response

8.1k
Nov 28, 2026
RepositoryPHP
symfony/polyfill-mbstring

Symfony polyfill for the Mbstring extension

7.8k
Oct 28, 2026
RepositoryPHP
symfony/routing

Maps an HTTP request to a set of configuration variables

7.6k
Nov 25, 2026
RepositoryPHP
symfony/process

Executes commands in sub-processes

7.5k
Nov 27, 2026
RepositoryPHP
symfony/var-dumper

Provides mechanisms for walking through any arbitrary PHP variable

7.4k
Nov 28, 2026