10000 [Validator] Access container array in Expression/Context by Engerim · Pull Request #23134 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Validator] Access container array in Expression/Context #23134

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

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
* fix cs
  • Loading branch information
Alexander Miehe committed Jun 28, 2017
commit 9e0882bc878d7d4eab7189c6ff08fa7c140bc2af
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ private function getPropertyAccessor()
if (!class_exists('Symfony\Component\PropertyAccess\PropertyAccess')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should use the class constant instead

throw new RuntimeException('Unable to use expressions with data path as the Symfony PropertyAccess component is not installed.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should not throw this exception in the constraint to allow to detect this mistake earlier.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course we could throw it there. But than we need to check there if dataPath is set because only then we check if the PropertyAccess is avaibale

10000
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that would be fine.

}

return PropertyAccess::createPropertyAccessor();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the exception in src/Symfony/Component/Validator/Constraints/Expression.php should be moved here IMHO:
since the property is public, the check in the constructor is very fragile, only here would be robust

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather make the property private then. Catching these mistakes when the constraint is created allows to spot issues earlier which improves DX.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made the property private and added a magic __get like it was done in the File Constraint.

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,9 @@ public function testExpressionLanguageUsage()

public function testExpressionLanguageUsageWithCustomDataPath()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this name make sense? Maybe just testExpressionWithCustomDataPath?

Copy link
Contributor Author
@Engerim Engerim Jun 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I orientated me on the naming from the test function above with name testExpressionLanguageUsage . But I can change it for better understanding

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I saw that. But the previous test actually tests that passing in a custom ExpressionLanguage instance works. Hence the name 😄

{
$constraint = new Expression(['expression' => 'value <= this["dateEnd"]', 'dataPath' => 'root[data]']);
$constraint = new Expression(array('expression' => 'value <= this["dateEnd"]', 'dataPath' => 'root[data]'));

$this->setRoot(['data' => ['dateEnd' => '2011-06-07', 'dateStart' => '2011-06-05']]);
$this->setRoot(array('data' => array('dateEnd' => '2011-06-07', 'dateStart' => '2011-06-05')));
$this->setPropertyPath('');
$this->setProperty(null, 'property');

Expand Down
0