You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The names are empty because, by default, the name property in the Context constructor is not populated. While calling withName('...') works, the constructor comment states:
// Do not use this argument, it is only used internally by the application
This raises concerns about potential side effects or breaking behavior if withName() is explicitly used by users.
Current Behavior:
Context names remain empty when manually instantiating or resolving contexts.
The attribute #[AsContext(name: '...')] does not auto-populate the name of context instance.
Expected Behavior:
The context name should be auto-populated from the AsContext attribute upon instantiation.
Possible Solutions:
Automatically populate the name property when instantiating a context if the AsContext attribute is set with a name.
Allow explicit use of withName() without concerns, and clarify whether its use is officially supported.
Environment:
Castor version: 0.21.0
PHP version: 8.4.0
Additional Notes:
It’s unclear if manually setting the name or withName() could cause issues. Is there any risk in doing so, or can it be safely permitted?
The text was updated successfully, but these errors were encountered:
Here, I reproduce the issue and it can be fixed with a simple modification in the ContextRegistry, by calling withName before registering the context. I will open an PR soon about it.
// here it should be one or another ? which have the priority ?
array:3 [
"context()->name" => "my_default"
"context('my_default')->name" => "my_default_runtime"
"defaultContext()->name" => "my_default_runtime"
]
But the same context (no call to withName(...)or name in constructor:
// Here it should be my_default everywhere
array:3 [
"context()->name" => "my_default"
"context('my_default')->name" => ""
"defaultContext()->name" => ""
]
I think if possible, we need to only have one way to define a name for context or we need to clarify them
For certain checks, I need to determine which context is authorized by its name. To achieve this, I declared a context using the
AsContext
attribute:Here, the name
'symfony'
is set and accessible using code like:However, when I attempt to manually resolve the name like this:
The resulting array is:
The names are empty because, by default, the
name
property in theContext
constructor is not populated. While callingwithName('...')
works, the constructor comment states:// Do not use this argument, it is only used internally by the application
This raises concerns about potential side effects or breaking behavior if
withName()
is explicitly used by users.Current Behavior:
#[AsContext(name: '...')]
does not auto-populate the name of context instance.Expected Behavior:
AsContext
attribute upon instantiation.Possible Solutions:
name
property when instantiating a context if theAsContext
attribute is set with a name.withName()
without concerns, and clarify whether its use is officially supported.Environment:
Additional Notes:
It’s unclear if manually setting the
name
orwithName()
could cause issues. Is there any risk in doing so, or can it be safely permitted?The text was updated successfully, but these errors were encountered: