Skip to content

feat: PSR-4 compatible cache structure for generated proxy files#568

Draft
Copilot wants to merge 3 commits intomasterfrom
copilot/improve-cache-structure-psr4
Draft

feat: PSR-4 compatible cache structure for generated proxy files#568
Copilot wants to merge 3 commits intomasterfrom
copilot/improve-cache-structure-psr4

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 30, 2026

Cache files were generated under a convoluted _proxies/<original-relative-path>/<FQCN>.php layout that encoded the source file path rather than the class identity, making the cache directory unusable as a PSR-4 autoloader root and breaking correctness when classes are renamed or moved.

Proxy file path layout

Before: <cacheDir>/_proxies/src/Application/Main.php/Go/Tests/TestProject/Application/Main.php
After: <cacheDir>/Go/Tests/TestProject/Application/Main.php

Each proxy file now lives at a path derived purely from its FQCN, matching PSR-4 conventions.

ReflectionClass::getFileName() on proxy classes

With PSR-4 paths the proxy location no longer encodes the source path, so MagicConstantTransformer::resolveFileName() needed a new mechanism. Each generated proxy file now ends with a self-registration call:

// appended at the bottom of every generated proxy file:
\Go\Instrument\Transformer\MagicConstantTransformer::registerProxyFile(
    __FILE__,
    'src/Application/Main.php'   // relative to appDir; portable across environments
);

MagicConstantTransformer gains a static $proxyFileMap registry populated at include_once time, giving resolveFileName() an O(1) lookup before falling back to the existing cache-dir→app-dir path substitution for woven files.

DebugWeavingCommand proxy discovery

Replaced the hardcoded _proxies/ subdirectory scan with a recursive scan of the full cacheDir, filtering on the presence of \Go\Aop\Proxy in file content. The filter is broadened from implements \Go\Aop\Proxy to just \Go\Aop\Proxy to correctly match classes that implement additional interfaces before the proxy marker.

Cross-platform path handling

Both saveProxyToCache() and resolveFileName() normalize paths to forward slashes before computing relative paths so that Windows backslash paths from ReflectionClass::getFileName() are handled correctly.

Test/snapshot updates

  • All *-woven.php snapshot files updated with new include_once AOP_CACHE_DIR . '/Ns/ClassName.php' paths.
  • All *-proxy.php snapshot files updated with the registerProxyFile() footer.
  • Regex patterns in WeavingTransformerTest fixed to escape the literal PHP concatenation dot (\.).

Copilot AI and others added 2 commits April 30, 2026 11:18
- WeavingTransformer.saveProxyToCache() now generates proxy files at PSR-4
  paths (<cacheDir>/<Namespace/ClassName>.php) instead of the old convoluted
  <cacheDir>/_proxies/<original-file-path>/<FQCN>.php layout
- Each generated proxy file includes a MagicConstantTransformer::registerProxyFile()
  call at the end so that wrapped ReflectionClass::getFileName() calls in woven
  sources correctly resolve back to the original source path at runtime
- MagicConstantTransformer gains a static $proxyFileMap registry and
  registerProxyFile() / resolveFileName() updated to use it with portable
  relative paths
- DebugWeavingCommand.getProxies() now scans the full cacheDir instead of the
  removed _proxies/ subdirectory, filtered by \Go\Aop\Proxy presence
- Update woven snapshot files (*-woven.php) with new include_once paths
- Update proxy snapshot files (*-proxy.php) with registerProxyFile() footer
- ClassWovenConstraint, ClassIsNotWovenConstraint, ProxyClassReflectionHelper
  already updated to use PSR-4 paths in earlier commits

Agent-Logs-Url: https://github.com/goaop/framework/sessions/0600c407-30da-4f37-81df-a43730e6099d

Co-authored-by: lisachenko <640114+lisachenko@users.noreply.github.com>
- Normalize both appDir and classFileName to forward slashes in
  WeavingTransformer::saveProxyToCache() for cross-platform correctness
- Normalize rootPath to forward slashes in MagicConstantTransformer::resolveFileName()
- Escape literal dot in AOP_CACHE_DIR regex patterns in WeavingTransformerTest

Agent-Logs-Url: https://github.com/goaop/framework/sessions/0600c407-30da-4f37-81df-a43730e6099d

Co-authored-by: lisachenko <640114+lisachenko@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor cache files to adhere to PSR-4 structure feat: PSR-4 compatible cache structure for generated proxy files Apr 30, 2026
Copilot AI requested a review from lisachenko April 30, 2026 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

[Improvement] PSR-4 compatible structure of cache files

2 participants