diff --git a/vim/UltiSnips/php.snippets b/vim/UltiSnips/php.snippets index d326e5c..14b4f1f 100644 --- a/vim/UltiSnips/php.snippets +++ b/vim/UltiSnips/php.snippets @@ -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" +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