Skip to content

feat(polyfill): detached Worksheet + addSheet, eager alias surface, value binder, IOFactory registration#4

Merged
saifulferoz merged 2 commits into
mainfrom
feat/spreadsheet-value-binder-add-sheet
Jul 18, 2026
Merged

feat(polyfill): detached Worksheet + addSheet, eager alias surface, value binder, IOFactory registration#4
saifulferoz merged 2 commits into
mainfrom
feat/spreadsheet-value-binder-add-sheet

Conversation

@saifulferoz

Copy link
Copy Markdown
Owner

What

Four PhpSpreadsheet-parity gaps hit by the ERP report suite, already validated against it (19/19 report generator tests under EASY_EXCEL_ALIAS=strict):

  1. Detached new Worksheet() + Spreadsheet::addSheet($sheet, ?$index) — the multi-sheet idiom used by composite/filter-loop reports (new Worksheet(); setTitle(); $spreadsheet->addSheet($ws, $i)) fataled with "Too few arguments to Worksheet::__construct()". Both ctor args are now optional; title get/set works while detached; every native-touching call routes through workbookHandle() which throws a clear "attach it first" message; rebindParent() rejects cross-workbook moves; addSheet rejects duplicate titles (matching PhpSpreadsheet).

  2. Eager alias surface (aliasCompatSurface()) — PHP never autoloads for instanceof/typed-parameter checks, so a lazily-aliased class that was only ever returned (e.g. Worksheet from getActiveSheet()) failed consumer type hints like function (Worksheet $ws). Every implemented Compat class is aliased at bootstrap; lazy aliasing stays for unimplemented classes (strict throw / fallback defer).

  3. Workbook-level value binderSpreadsheet::setValueBinder()/getValueBinder() (PhpSpreadsheet ≥ 2.x); wins over the legacy static Cell::setValueBinder(); setCellValue()/fromArray() route through it.

  4. IOFactory::registerWriter()/registerReader() + createReaderForFile() — apps that plug custom writers (e.g. an Html-based Pdf writer) run unchanged; registered entries are consulted before the built-ins; new Reader\IReader contract + Writer\Exception/Reader\Exception (also open upstream as feat(polyfill): IOFactory registerWriter/registerReader + createReade… xiidea/easy-excel#2).

Testing

  • php tests/run.php green on the branch.
  • ERP suite: 19/19 under strict alias mode (previously 6 binder errors + 1 ctor error + latent type-check failures).
  • Verified today in the ERP dev stack (vendor-patched from this branch): detached construct + setTitle + addSheet + duplicate-title guard + typed-param/instanceof checks all pass under the Compat engine, and the composite multi-sheet report saves with the correct sheet list.

🤖 Generated with Claude Code

saifulferoz and others added 2 commits July 18, 2026 10:44
… eager alias surface

Three PhpSpreadsheet-parity gaps hit by a real ERP report suite:

- Spreadsheet::setValueBinder()/getValueBinder(): the PhpSpreadsheet >= 2.x
  workbook-level binder API. The workbook binder wins over the legacy static
  Cell::setValueBinder(); setCellValue()/fromArray() route through it.

- new Worksheet() may now be constructed detached (both ctor args optional)
  and attached later via the new Spreadsheet::addSheet($sheet, ?$index) —
  the FilterLoopReportRunner/multi-sheet idiom. Title get/set work while
  detached; native-touching calls throw a clear message via workbookHandle().
  rebindParent() rejects cross-workbook moves.

- aliasCompatSurface(): eagerly alias every Compat class at bootstrap. The
  engine skips autoloading for instanceof and typed-parameter checks, so a
  lazily-aliased class that was only ever *returned* (never explicitly
  loaded) failed type hints like function (Worksheet $ws): the alias did not
  exist yet. Lazy aliasing stays for unimplemented classes (strict throw /
  fallback defer).

Validated against the ERP report generator suite under EASY_EXCEL_ALIAS=strict:
19/19 tests pass (previously 6 binder errors + 1 ctor error + latent
type-check failures).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Mirrors PhpSpreadsheet's StringValueBinder (per-type conversion
suppression, DateTime/RichText/Stringable object binding). Callers that
call $spreadsheet->setValueBinder(new StringValueBinder()) previously
hit UnsupportedApiException under strict aliasing.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@saifulferoz
saifulferoz force-pushed the feat/spreadsheet-value-binder-add-sheet branch from ef7baed to 694cad4 Compare July 18, 2026 04:44
@saifulferoz
saifulferoz merged commit 6ef3e6a into main Jul 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant