xp-framework / core

The XP Framework is an all-purpose, object oriented PHP framework.
Other
19 stars 6 forks source link

Store original attribute names in DETAIL_TARGET_ANNO #334

Closed thekid closed 1 year ago

thekid commented 1 year ago

This fixes a problem when using old and new reflection libraries in conjunction. This is due to the fact that both use xp::$meta for caching reasons, but fill it differently.

<?php

use web\frontend\Handler;

#[Handler]
class Users {

}

Before

Using the lang.XPClass annotation API will infer with the results returned by lang.reflection.Type:

# Return value as expected:
$ xp -w 'return [...\lang\Reflection::type("Users")->annotations()]'
[web.frontend.Handler => lang.reflection.Annotation<web.frontend.Handler([])>]

# The annotation name is only returned in lowercase!
$ xp -w '\lang\XPClass::forName("Users")->getAnnotations();
return [...\lang\Reflection::type("Users")->annotations()]'
[handler => lang.reflection.Annotation<handler([])>]

After

The lang.XPClass annotation API now also records the original annotation names, and lang.reflection.Type now returns the expected annotation:

$ xp -w '\lang\XPClass::forName("Users")->getAnnotations();
return [...\lang\Reflection::type("Users")->annotations()]'
[web.frontend.Handler => lang.reflection.Annotation<web.frontend.Handler([])>]
thekid commented 1 year ago

Released in https://github.com/xp-framework/core/releases/tag/v11.8.2