update php snippets

This commit is contained in:
Simon Vieille 2024-08-25 21:25:08 +02:00
commit d34bc5ab32

View file

@ -1,9 +1,4 @@
snippet pf "Create a public function" b
/**
* $3.
*
* $4
*/
public function $1($2)
{
$5
@ -11,11 +6,6 @@ public function $1($2)
endsnippet
snippet ppf "Create a protected function" b
/**
* $3.
*
* $4
*/
protected function $1($2)
{
$5;
@ -23,11 +13,6 @@ protected function $1($2)
endsnippet
snippet pvf "Create a private function" b
/**
* $3.
*
* $4
*/
private function $1($2)
{
$5;
@ -54,6 +39,15 @@ public function get${1/\w+\s*/\u$0/g}(): $2
}
endsnippet
snippet g "Getter"
public function get${1/\w+\s*/\u$0/g}(): $2
{
return \$this->$1;
}
endsnippet
snippet sf2:a "Create a symfony2 controller function" b
/**
* @param Request $request
@ -374,3 +368,76 @@ endsnippet
snippet sec "Securiy attribute"
#[Security('is_granted("ROLE_ADMIN") or is_granted("ROLE_DPO")')]
endsnippet
snippet ig "Securiy attribute"
#[IsGranted('$1', 'entity')]
endsnippet
snippet igs "Securiy attribute"
#[IsGranted('show', 'entity')]
endsnippet
snippet ige "Securiy attribute"
#[IsGranted('edit', 'entity')]
endsnippet
snippet igd "Securiy attribute"
#[IsGranted('delete', 'entity')]
endsnippet
snippet voter "Voter"
<?php
namespace App\Security\Voter;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use Symfony\Component\Security\Core\Security;
use `!p snip.rv = "App\Entity\\" + snip.basename.replace("Voter", "")` as Entity;
class `!p snip.rv = snip.basename` extends EntityVoter
{
protected function isValidType(mixed $entity): bool
{
return $entity instanceof Entity;
}
protected function voteOnAttribute(string $attribute, mixed $entity, TokenInterface $token): bool
{
$vote = $this->genericVote($attribute, $entity, $token);
if (is_bool($vote)) {
return $vote;
}
if ('show' === $attribute) {
return $this->canRead($entity);
}
if ('edit' === $attribute) {
return $this->canWrite($entity);
}
if ('delete' === $attribute) {
return $this->canDelete($entity);
}
return false;
}
// protected function canWrite(mixed $entity): bool
// {
// return $this->isAdmin();
// }
//
// protected function canDelete(mixed $entity): bool
// {
// return $this->isAdmin();
// }
//
// protected function canRead(mixed $entity): bool
// {
// return $this->isAdmin();
// }
}
endsnippet