Skip to content
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

Merged
merged 1 commit into from
Apr 14, 2020
Merged

Plugin method should accept string variable as argument #11

merged 1 commit into from
Apr 14, 2020

Conversation

neilime
Copy link
Contributor

@neilime neilime commented Apr 13, 2020

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:

$name = 'form';

// ...

$this->getView()->plugin($name);

@Slamdunk
Copy link
Owner

Hi, thank you for reporting the issue. Can you add tests to your patch please?

@neilime
Copy link
Contributor Author

neilime commented Apr 13, 2020

@Slamdunk I have added some tests


return new ObjectType($pluginClass);
if ($argType instanceof StringType) {
Copy link
Owner

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?

Copy link
Contributor

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);
Copy link
Owner

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?

Copy link
Contributor

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.

Copy link
Owner

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);
Copy link
Owner

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 ?

Copy link
Contributor

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.

@Slamdunk Slamdunk merged commit 6a46872 into Slamdunk:master Apr 14, 2020
@Slamdunk
Copy link
Owner

Thank you @neilime and @ondrejmirtes

@neilime neilime deleted the patch-1 branch April 14, 2020 08:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants