snippet pf "Create a public function" b
public function $1($2)
{
    $5
}
endsnippet

snippet ppf "Create a protected function" b
protected function $1($2)
{
    $5;
}
endsnippet

snippet pvf "Create a private function" b
private function $1($2)
{
    $5;
}
endsnippet

snippet php
<?php 

$1
endsnippet

snippet gs "Getter and setter"
public function set${1/\w+\s*/\u$0/g}($2 \$$1): $3
{
    $this->$1 = \$$1;

    return \$this;
}

public function get${1/\w+\s*/\u$0/g}(): $2
{
    return \$this->$1;
}
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
 *
 * @return \Symfony\Bundle\FrameworkBundle\Controller\Response
 */
public function $1Action(Request $request)
{
    if ($response = $this->handleNodeSecurity($request)) {
        return $response;
    }

    return $this->defaultRender();
}
endsnippet

snippet page "Create trinity page"
<?php

namespace `!p
relpath = os.path.relpath(path)
m = re.search(r'[A-Z].+(?=/)', relpath)
if m:
	snip.rv = m.group().replace('/', '\\')
`;

use Trinity\Bundle\ContentManagerBundle\Model\Page;
use Trinity\Bundle\ContentManagerBundle\Model\Block;
use Trinity\Bundle\ContentManagerBundle\Form\Type\BlockType;
use Trinity\Bundle\ContentManagerBundle\Form\Type\TinymceAdvancedBlockType;

/**
 * Class `!p snip.rv = snip.basename`.
 *
 * @author Simon Vieille <simon@deblan.fr>
 */
class `!p snip.rv = snip.basename` extends Page
{
    /**
     * Constructor.
     *
     * @param string $template
     */
    public function __construct($template = '$1')
    {
        parent::__construct($template);
    }

    /**
     * {@inheritdoc}
     */
    public function getConfiguration()
    {
        return $this->configuration
            ->setDefaultControllerClass('${2:Foo}\Bundle\\${3:Bar}Bundle\Controller\\${4:My}Controller::${5:bob}Action')
            ->setBlock('title', BlockType::class)
            ->setBlock('content', TinymceAdvancedBlockType::class);
    }

    /**
     * Get the block "title".
     *
     * @return Block
     */
    public function getBlockTitle()
    {
        return $this->getBlock('title');
    }

    /**
     * Set the block "title".
     *
	 * @param Block $block
	 *
	 * @return `!p snip.rv = snip.basename`
	 */
    public function setBlockTitle(Block $block)
    {
        return $this->setBlock($block);
    }

    /**
     * Get the block "content".
     *
     * @return Block
     */
    public function getBlockContent()
    {
        return $this->getBlock('content');
    }

    /**
     * Set the block "title".
     *
	 * @param Block $block
	 *
	 * @return `!p snip.rv = snip.basename`
	 */
    public function setBlockContent(Block $block)
    {
        return $this->setBlock($block);
    }
}
endsnippet

snippet command "Create sf2 command"
<?php

namespace `!p
relpath = os.path.relpath(path)
m = re.search(r'[A-Z].+(?=/)', relpath)
if m:
	snip.rv = m.group().replace('/', '\\')
`;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;

/**
 * class `!p snip.rv = snip.basename`.
 *
 * @author `!v g:snips_author`
 */
class `!p snip.rv = snip.basename` extends ContainerAwareCommand
{
    /**
     * {@inheritdoc}
     */
    protected function configure()
    {
        $this
            ->setName('$1')
            ->setDescription('$2')
            // ->addArgument('foo', InputArgument::OPTIONAL, '')
            // ->addOption('bar', null, InputOption::VALUE_NONE, '')
            ->setHelp("The <info>%command.name%</info> $3");
    }

    /**
     * {@inheritdoc}
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        // $this->getContainer()->get('foo.bar');
        // $output->writeln(sprintf('<comment>%s</comment> bar.', $example));
        // $input->getArgument('foo');
        // $input->getOption('bar');
        $4
    }
}
endsnippet

snippet controller "Create trinity controller"
<?php

namespace `!p
relpath = os.path.relpath(path)
m = re.search(r'[A-Z].+(?=/)', relpath)
if m:
	snip.rv = m.group().replace('/', '\\')
`;

use Symfony\Component\HttpFoundation\Request;
use Trinity\Bundle\ContentManagerBundle\Controller\PageController;

/**
 * class `!p snip.rv = snip.basename`.
 *
 * @author `!v g:snips_author`
 */
class `!p snip.rv = snip.basename` extends PageController
{
    /**
     * @param Request $request
     *
     * @return \Symfony\Bundle\FrameworkBundle\Controller\Response
     */
    public function $1Action(Request $request)
    {
        if ($response = $this->handleNodeSecurity($request)) {
            return $response;
        }

        $2

        return $this->defaultRender();
    }
}
endsnippet


snippet form "Create sf2 form"
<?php

namespace `!p
relpath = os.path.relpath(path)
m = re.search(r'[A-Z].+(?=/)', relpath)
if m:
	snip.rv = m.group().replace('/', '\\')
`;

use Propel\PropelBundle\Form\BaseAbstractType;
use Symfony\Component\Form\FormBuilderInterface;

/**
 * class `!p snip.rv = snip.basename`.
 *
 * @author `!v g:snips_author`
 */
class `!p snip.rv = snip.basename` extends BaseAbstractType
{
    /**
     * @var array
     */
    protected $options = [
        'name' => '$1',
    ];

    /**
     * {@inheritdoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $2
    }
}
endsnippet

snippet array "Create array"
[$1]
endsnippet

snippet foreach "foreach"
foreach (\$${1}s as \$$1) {
    $2
}
endsnippet

snippet block "block"
/**
 * Set the block "$1".
 *
 * @param Block $block
 *
 * @return `!p snip.rv = snip.basename`
 */
public function setBlock${1/\w+\s*/\u$0/}(Block $block)
{
	return $this->setBlock($block);
}

/**
 * Get the block "$1".
 *
 * @return Block
 */
public function getBlock${1/\w+\s*/\u$0/}()
{
	return $this->getBlock('${1/(\w+)/\l$0/}');
}
endsnippet

snippet ind "inheritdoc comment" b
/**
 * {@inheritdoc}
 */
endsnippet

snippet prop "Class attribute/property" b
/**
 * @var $2
 */
protected \$$1;

$3
endsnippet

snippet class "Class" b
<?php

namespace `!p
relpath = os.path.relpath(path)
m = re.search(r'[A-Z].+(?=/)', relpath)
if m:
	snip.rv = m.group().replace('/', '\\')
`;

/**
 * class $1.
 *
 * @author `!v g:snips_author`
 */
class $1
{
    $2
}
endsnippet

snippet rest "JMS annotation" b
/**
 * @JMS\Serializer\Annotation\SerializedName("$1")
 * @JMS\Serializer\Annotation\Groups({"$2"})
 * @JMS\Serializer\Annotation\VirtualProperty
 */
public function getRest${1/\w+\s*/\u$0/}()
{
	return $this->get${1/\w+\s*/\u$0/}();
}
endsnippet

snippet rest_class "JMS class annotation"
* @JMS\Serializer\Annotation\ExclusionPolicy("all")
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
