Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 7 additions & 4 deletions src/Resources/skeleton/security/Voter.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ class <?= $class_name ?> extends Voter
{
protected function supports($attribute, $subject)
{
// replace with your own logic
// https://symfony.com/doc/current/security/voters.html
return in_array($attribute, ['POST_EDIT', 'POST_VIEW'])
&& $subject instanceof \App\Entity\BlogPost;
// Replace with your own logic
// See https://symfony.com/doc/current/security/voters.html
//
// return in_array($attribute, ['POST_EDIT', 'POST_VIEW'])
Copy link
Member

Choose a reason for hiding this comment

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

Maybe replace POST by something else? It means "after" also, this can be confusing.

Copy link
Member

Choose a reason for hiding this comment

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

Good catch. At the very least, we could change this to BLOG_POST_EDIT... though there is also no rule that says that things need to be upper case...

If we add a question about the entity/class, then we would derive this from the entity class name.

// && $subject instanceof \App\Entity\YourEntity;

return false;
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure this is better: the now commented line were fine uncommented, no? Because there is this line to remove now, this might confuse some.

}

protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
Expand Down
7 changes: 6 additions & 1 deletion src/Resources/skeleton/serializer/Normalizer.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public function normalize($object, $format = null, array $context = array()): ar

public function supportsNormalization($data, $format = null): bool
{
return $data instanceof \App\Entity\BlogPost;
// Replace with your own logic
// See https://symfony.com/doc/current/serializer/custom_normalizer.html
//
// return $data instanceof \App\Entity\YourEntity;
Copy link
Member

Choose a reason for hiding this comment

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

Same note as above, it'd make sense uncommenting this to me.

Copy link
Member

Choose a reason for hiding this comment

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

Totally agree, That's what I said in the previous PR.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm. I agree. The current example code seems pretty clear, and it's better than needing to know to remove that return false. I think we should leave as-is or add a second question to each maker:

What class will this voter/normalizer handle? (e.g. BlogPost or leave blank)

(if a non-FQN were passed, we'd look for it in Entity). If a class is passed, we use that in the generated code. If none is passed, we leave the class-checking part off of the voter and, for the normalizer, probably put a big TODO in supportsNormalization().

WDYT?


return false;
}
}
6 changes: 4 additions & 2 deletions tests/ValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ public function testInvalidClassName()
public function testInvalidEncodingInClassName()
{
$this->expectException(RuntimeCommandException::class);
$this->expectExceptionMessage('"�Controller" is not a UTF-8-encoded string.');
Validator::validateClassName(mb_convert_encoding('Ś', 'ISO-8859-2', 'UTF-8'));
$invalidName = mb_convert_encoding('Fôö', 'ISO-8859-2', 'UTF-8');
$this->expectExceptionMessage(sprintf('"%s" is not a UTF-8-encoded string.', $invalidName));
Validator::validateClassName($invalidName);

}
}