Several woven classes in one file: their proxies overwrite each other, all but the last class are lost (Class not found)
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 38/100
Línea de trabajo
Start in WeavingTransformer::saveProxyToCache() in src/Instrument/Transformer/WeavingTransformer.php (around lines 974-993), where the proxy path is built from the source file alone, and in the include lines the woven source gets. Read the snapshot tests multiple-classes-woven.php and multiple-ns.php under tests/Instrument/Transformer/_files/, then bump CachePathManager::FORMAT_VERSION if the layout changes. Done means one combined proxy file per source file, with every woven class in its own namespace, plus a test that actually loads all the classes.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Problem
When one source file declares several classes that are woven, every proxy is written to the same cache file. The last proxy wins, and the other classes are never defined at runtime.
Reproduce (master 4e95fdd)
// app/Two.php
namespace Bug1;
class First { public function hello(): string { return 'first'; } }
class Second { public function hello(): string { return 'second'; } }
The aspect is #[Before('execution(public Bug1\**->hello(*))')]. The kernel uses appDir = app/.
After the file is included through the loader:
class_exists('Bug1\Second', false)→true;(new Second())->hello()runs the advice.class_exists('Bug1\First', false)→false;new First()fails withError: Class "Bug1\First" not found.trait_exists('Bug1\FirstOriginalTrait', false)→true. The trait is woven, but its proxy class is gone.cache/Two.php(the proxy file) contains onlyclass Second.
Cause
WeavingTransformer::saveProxyToCache()(src/Instrument/Transformer/WeavingTransformer.php:974-993) builds the proxy path from the source file path only:{cacheDir}/{relative source path}. Each woven class of the file overwrites the previous proxy.- The woven source then contains one
include_once AOP_CACHE_DIR . '/…/Two.php';per class, all for the same path. The first one loads the last written proxy, and the later ones do nothing.
The existing snapshot tests/Instrument/Transformer/_files/multiple-classes-woven.php already encodes this: three classes share the identical include_once AOP_CACHE_DIR . '/Transformer/_files/multiple-classes.php'. The test never loads the classes, so it passes.
Expected / decided direction
Keep one proxy file per source file: put all proxies of the file together in that single cache file, not one file per class.
- The woven source includes that file once, after all
…OriginalTraitdeclarations it needs are defined. - The runtime class map (
_include.cache) maps every woven class of the file to the same cached file. - Namespaces: a source file may declare classes in several namespaces (see
multiple-ns.php). The combined proxy file has to keep every proxy in its own namespace, with its own imports, for example as braced namespace blocks.
Acceptance
- The snapshot tests for
multiple-classesandmultiple-nsare updated, and a test actually loads all classes of such a file (unit or functional). - Classes in the same file that are not woven stay as they are.
- Single-class files produce byte-identical output to master, or any difference is explained.
- If the cache layout or format changes, bump
CachePathManager::FORMAT_VERSION.
- Lenguaje dominante
- PHP
- Estrellas
- 1.7k
- Forks
- 166
- Merge medio
- 19 h 39 min
- PR fusionados (30 d)
- 48
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de goaop/framework
-
Enhancement Performance
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
goaop/framework#747 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Enhancement Performance To Be Discussed
Dificultad 3/5 Medio día Aptitud para principiantes 55/100
Los mantenedores suelen responder en 1 día
-
Feature
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
Los mantenedores suelen responder en 1 día
-
Bug Known Issue
Dificultad 4/5 3-5 días Aptitud para principiantes 30/100
goaop/framework#696 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 5/100
Los mantenedores suelen responder en 1 día
Todos los issues de goaop/framework
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
jwage/phpamqplib-messenger#159 ·
-
L: javascript
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
dependabot/dependabot-core#16744 ·
Los mantenedores suelen responder en 1 día
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
linuxserver/docker-bookstack#302 · 1 comentario ·
-
Dificultad 2/5 Menos de una hora Aptitud para principiantes 62/100
OpenConext/OpenConext-devconf#101 ·
-
component/document-portal domain/b2b
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 1 día