-
-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plugin method should accept string variable as argument #11
Conversation
Hi, thank you for reporting the issue. Can you add tests to your patch please? |
@Slamdunk I have added some tests |
|
||
return new ObjectType($pluginClass); | ||
if ($argType instanceof StringType) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way in this case to get the string raw value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the type is ConstantStringType
then you can ask for $argType->getValue()
|
||
public function getDynamicTypeFromStringVariable(string $name): AbstractHelper | ||
{ | ||
return $this->phpRenderer->plugin($name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ondrejmirtes we would like to catch here the raw value of $name
variable, which is 'url'
from few lines above, can we?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can see the literal values only in the same method body, not across method boundaries.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok thank you
$argType->describe(VerbosityLevel::typeOnly()) | ||
)); | ||
$argType = $scope->getType($methodCall->args[0]->value); | ||
$strings = TypeUtils::getConstantStrings($argType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@neilime why not simply$argType instanceof ConstantStringType
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually better. It accounts for 'foo'|'bar'
etc.
Thank you @neilime and @ondrejmirtes |
Fix error "Internal error: Argument passed to Laminas\View\Renderer\PhpRenderer::plugin should be a string, string given" when ViewModel->plugin is called with a variable containing a string instead of a pure string: