ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

Symfony​2 Snippets

by raulfraile ST2/ST3

A Sublime Text bundle for Symfony2 development

Labels snippets

Details

  • 2016.03.14.21.55.43
  • github.​com
  • github.​com
  • 2 years ago
  • 2 hours ago
  • 6 years ago

Installs

  • Total 28K
  • Win 13K
  • OS X 7K
  • Linux 9K
Dec 15 Dec 14 Dec 13 Dec 12 Dec 11 Dec 10 Dec 9 Dec 8 Dec 7 Dec 6 Dec 5 Dec 4 Dec 3 Dec 2 Dec 1 Nov 30 Nov 29 Nov 28 Nov 27 Nov 26 Nov 25 Nov 24 Nov 23 Nov 22 Nov 21 Nov 20 Nov 19 Nov 18 Nov 17 Nov 16 Nov 15 Nov 14 Nov 13 Nov 12 Nov 11 Nov 10 Nov 9 Nov 8 Nov 7 Nov 6 Nov 5 Nov 4 Nov 3 Nov 2 Nov 1 Oct 31
Windows 0 1 5 2 11 6 8 7 4 8 7 4 4 1 8 9 6 4 10 0 2 12 3 6 4 6 5 5 3 6 10 15 9 4 6 4 11 8 5 6 5 5 8 9 7 11
OS X 0 1 3 3 3 2 1 3 0 3 0 4 1 1 2 3 2 0 1 0 1 2 1 3 2 3 1 0 2 2 2 2 1 0 1 2 0 1 3 1 0 2 5 2 1 1
Linux 0 3 2 0 3 1 2 1 1 6 3 5 0 3 2 2 3 7 1 0 3 2 2 2 6 4 2 4 7 3 2 5 4 4 1 4 5 4 4 5 1 4 7 2 3 3

Readme

Source
raw.​githubusercontent.​com

This is a Sublime Text package which includes handy snippets for doing Symfony2 framework development.

Important: The master branch of this plugin will always be in sync with the latest stable release of Symfony2.

Installation

With Package Control

If you have the Package Control package installed, you can install Symfony2 Snippets from inside Sublime Text itself. Open the Command Palette and select “Package Control: Install Package”, then search for Symfony2 Snippets.

Without Package Control

If you haven't got Package Control installed you will need to make a clone of this repository into your packages folder, like so:

git clone https://github.com/raulfraile/sublime-symfony2 symfony2-snippets

If you need to install a specific branch of the plugin (2.0 in this example), please use the following commands:

cd symfony2-snippets
git checkout origin/2.0

Shortcuts

All shortcuts start with the sf prefix and are both short and intuitive:

Controller

sfcontroller

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class DefaultController extends Controller
{
    public function indexAction()
    {
        return $this->render('.html.twig');
    }
}

sfcontrollera

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class DefaultController extends Controller
{
    /**
     * @Route("/", name="")
     * @Template()
     */
    public function indexAction()
    {

    }
}

sfaction

public function indexAction()
{
    return $this->render('.html.twig');
}

sfactiona

/**
 * @Route("/", name="")
 * @Template()
 */
public function indexAction()
{

}

sfem

$em = $this->getDoctrine()->getManager();

sfrepo

$em->getRepository('Bundle:Repository');

sfforward

$this->forward('Bundle:Controller:action', array(), array());

sfredirect

$this->redirect($this->generateUrl('route', array()));

sfrender

$this->render('Bundle:Folder:template.html.twig', array());

sfgetsession

$this->getRequest()->getSession();

sfsetflash

$this->get('session')->getFlashBag()->add('type', 'message');

sfdump

\Doctrine\Common\Util\Debug::dump();

Command

sfcommand

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class DefaultCommand extends Command
{
    /**
     * {@inheritdoc}
     */
    protected function configure()
    {
        $this
            ->setName('default:command')
            ->setDescription('Default description')
        ;
    }

    /**
     * {@inheritdoc}
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {

    }
}

sfcommandca

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

class DefaultCommand extends ContainerAwareCommand
{
    /**
     * {@inheritdoc}
     */
    protected function configure()
    {
        $this
            ->setName('default:command')
            ->setDescription('Default description')
        ;
    }

    /**
     * {@inheritdoc}
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {

    }
}

Doctrine

Classes

sfentityclass

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * @ORM\Entity(repositoryClass="")
 * @ORM\Table(name="")
 */
class Entity
{
    /**
     * @ORM\Id()
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;
}

sfdocumentclass

use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * @MongoDB\Document(collection="", repositoryClass="")
 */
class Document
{
    /**
     * @MongoDB\Id()
     */
    protected $id;
}

sfrepository

use Doctrine\ORM\EntityRepository;

class EntityNameRepository extends EntityRepository
{
}

sfgetset Just type your variable name (firstName for instance), and the snippets will name the functions automatically (getFirstName).

/**
* Get 
* @return  
*/
public function get()
{
    return $this->;
}

/**
* Set 
* @return $this
*/
public function set($)
{
    $this-> = $;
    return $this;
}

Annotations

After triggering the snippets, just type your var name and it will automatically set the name in the annotation (If you type 'firstName', your variable will be named 'firstName' and in the annotation the name will be 'first_name').

sfentity

/**
 * @ORM\Entity()
 * @ORM\Table(name="name")
 */

sfidcolumn

/**
 * @ORM\Column(name="id", type="integer", nullable=false)
 * @ORM\Id()
 * @ORM\GeneratedValue(strategy="IDENTITY")
 */
 private $id;

sfstringcolumn

/**
 * @ORM\Column(name="", type="string", length=255)
 */
 private $;

sfdecimalcolumn

/**
 * @ORM\Column(name="", type="decimal", scale=2)
 */
 private $;

sftextcolumn

/**
 * @ORM\Column(name="", type="text")
 */
 private $;

sfintegercolumn

/**
 * @ORM\Column(name="", type="integer")
 */
 private $;

sfbooleancolumn

/**
 * @ORM\Column(name="", type="boolean")
 */
 private $;

sfsmallintcolumn

/**
 * @ORM\Column(name="", type="smallint")
 */
 private $;

sfbigintcolumn

/**
 * @ORM\Column(name="", type="bigint")
 */
 private $;

sfdatetimecolumn

/**
 * @ORM\Column(name="", type="datetime")
 */
 private $;

sfdatecolumn

/**
 * @ORM\Column(name="", type="date")
 */
 private $;

sftimecolumn

/**
 * @ORM\Column(name="", type="time")
 */
 private $;

sffloatcolumn

/**
 * @ORM\Column(name="", type="float")
 */
 private $;

sfarraycolumn

/**
 * @ORM\Column(name="", type="array")
 */
 private $;

sfobjectcolumn

/**
 * @ORM\Column(name="", type="object")
 */
 private $;

Forms

sfform

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class NameType extends AbstractType
{
    /**
     * {@inheritdoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {

    }

    /**
     * {@inheritdoc}
     */
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => '',
        ));
    }

    /**
     * {@inheritdoc}
     */
    public function getName()
    {
        return 'name';
    }
}

sfdatatransformer

use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Form\Exception\TransformationFailedException;

class NameTransformer implements DataTransformerInterface
{
    /**
     * {@inheritdoc}
     */
    public function transform($value)
    {

    }

    /**
     * {@inheritdoc}
     */
    public function reverseTransform($value)
    {

    }
}

Twig

sftwigextension

class NameExtension extends \Twig_Extension
{
    /**
     * {@inheritdoc}
     */
    public function getFilters()
    {
        return array();
    }

    /**
     * {@inheritdoc}
     */
    public function getTests()
    {
        return array();
    }

    /**
     * {@inheritdoc}
     */
    public function getFunctions()
    {
        return array();
    }
}

sftwigform

<form class="" action="{{ path('') }}" method="post" {{ form_enctype(form) }}>
    {{ form_errors(form) }}
    {{ form_widget(form) }}
    <input type="submit" value="Submit" />
</form>

sftwigrow

{{ form_row(form.) }}

trans

{% trans %}{% endtrans %}

Template

sfasset

{{ asset('bundles/')}}

sfasseticjs

{% javascripts '@/Resources/public/js/*' %}
    <script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}

sfasseticcss

{% stylesheets 'bundles//css/*' filter='cssrewrite' %}
    <link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}

Validation

sfconstraint

use Symfony\Component\Validator\Constraint;

/**
 * @Annotation
 */
class NameConstraint extends Constraint
{
    public $message = '';
}

sfconstraintvalidator

use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;

class NameValidator extends ConstraintValidator
{
    public function validate($value, Constraint $constraint)
    {

    }
}

DependencyInjection

sfdiconfiguration

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

class Configuration implements ConfigurationInterface
{
    public function getConfigTreeBuilder()
    {
        $treeBuilder = new TreeBuilder();
        $rootNode = $treeBuilder->root('bundle_name');

        $rootNode
            ->children()
                ->scalarNode('enabled')
                    ->setInfo('Enable the container extension')
                    ->setDefault(true)
                ->end()
            ->end()
        ;

        return $treeBuilder;
    }
}

sfdiextension

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

class BundleExtension extends Extension
{
    public function load(array $configs, ContainerBuilder $container)
    {
        $config = $this->processConfiguration(new Configuration(), $configs);
        if (false === $config['enabled']) {
            return;
        }

        $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
        $loader->load('services.xml');
    }
}

sfdiservices

<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

    <services>
        <service id="id" class="class" />
    </services>
</container>

YAML

sfroute

route_name:
    path:   /
    defaults:  { _controller: Bundle:Controller:action }

Contribute

If you miss something, feel free to fork this repository and send a PR with your awesome snippets for Symfony2 :)

Contributors list