Connect attributes to their targets
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- C
- Sterne
- 40.4k
- Forks
- 8.1k
- Ø Merge
- 2 T. 13 Std.
- Gemergte PRs (30 T.)
- 96
Beschreibung
Description
There currently seems to be no way to get the actual target of the attribute. The getTarget method returns the bitmask of the constants. Example usage:
class X {
#[Tag]
private string $property;
#[Tag]
private string $otherProperty;
private string $extraProperty;
}
...
$attributeReflections = $propertyReflection->getAttributes(Tag::class);
// now I want to pass the reflections somewhere else and do
$property = $attributeReflection->getPropertyReflection();
$property->getValue();
Obviously there is a workaround to build some datastructure to pass the reference in along with the reflection. But it seems like it should be part of the API. Given I can limit to what type of object I can attach it to, I should be able to get the actual "instance" of the object somehow IMHO. But maybe I'm missing some important context why this doesn't make sense, sorry if that's the case :)
Essentially it's the same as when ReflectionProperty has $class even though one could argue that you always get the property from class, so you should be able to maintain the relation yourself. I believe that property attribute should at least have $class and $property, if the above proposed API is too heavy.
Does it make sense?
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, das Verhalten der Attributreflexion rund um getTarget() und die vorgeschlagene getPropertyReflection()-API zusammen mit der bestehenden Klassen- und Eigenschaftsbeziehung von ReflectionProperty zu überprüfen. Bestimme, ob Attribute von Eigenschaften ihre deklarierende Klasse und Eigenschaft oder ein allgemeineres Zielobjekt bereitstellen sollten. Als abgeschlossen gilt die Aufgabe, wenn ein abgestimmtes API-Design mit entsprechendem Verhalten und Tests für das Beispiel mit mehreren Eigenschaften vorliegt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- php
- Bereich
- backend
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 25/100