romeugodoi / sublime-symfony2

A Sublime Text bundle for Symfony2 development

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

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

Shortcuts

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

Controller

sfcontroller

namespace VendorName\Bundle\BundleNameBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class ControllerNameController extends Controller
{
    public function indexAction()
    {
        return $this->render('VendorNameBundleNameBundle:ControllerName:index.html.twig');
    }
}

sfem

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

sfrepo

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

sfforward

$this->forward('TestBundle:Folder:view', array());

sfredirect

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

sfrender

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

sfsession

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

sfsetflash

this->get('session')->setFlash('notice', 'message');

Forms

sfform

namespace VendorName\Bundle\BundleNameBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;

class FormNameType extends AbstractType
{
    public function buildForm(FormBuilder $builder, array $options)
    {

    }

    public function getDefaultOptions(array $options)
    {
        return array(
            'data_class' => 'VendorName\\Bundle\\BundleNameBundle\\Entity\\FormName',
        );
    }

    public function getName()
    {
        return 'formName';
    }
}

sfdatatransformer

namespace VendorName\Bundle\BundleNameBundle\Form\DataTransformer;

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

class TransformerNameTransformer implements DataTransformerInterface
{
    /**
     * Transforms a value from the original representation to a transformed representation.
     *
     * @param  mixed $value              The value in the original representation
     *
     * @return mixed                     The value in the transformed representation
     *
     * @throws UnexpectedTypeException   when the argument is not a string
     * @throws TransformationFailedException  when the transformation fails
     */
    public function transform($value)
    {

    }

    /**
     * Transforms a value from the transformed representation to its original
     * representation.
     *
     * @param  mixed $value              The value in the transformed representation
     *
     * @return mixed                     The value in the original representation
     *
     * @throws UnexpectedTypeException   when the argument is not of the expected type
     * @throws TransformationFailedException  when the transformation fails
     */
    public function reverseTransform($value)
    {

    }
}

Doctrine

Annotations

sfentity

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

sfidcolumn

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

sfstringcolumn

/**
 * @ORM\Column(type="string", length=100)
 */

sfdecimalcolumn

/**
 * @ORM\Column(type="decimal", scale=${1:2})
 */

sfstextcolumn

/**
 * @ORM\Column(type="text")
 */

Twig

sftwigextension

namespace VendorName\Bundle\BundleNameBundle\Twig\Extension;

class ExtensionNameExtension extends \Twig_Extension
{
    /**
     * Returns a list of filters to add to the existing list.
     *
     * @return array An array of filters
     */
    public function getFilters()
    {
        return array();
    }

    /**
     * Returns a list of tests to add to the existing list.
     *
     * @return array An array of tests
     */
    public function getTests()
    {
        return array();
    }

    /**
     * Returns a list of functions to add to the existing list.
     *
     * @return array An array of functions
     */
    public function getFunctions()
    {
        return array();
    }
}

YAML

sfroute

route_name:
    pattern:   /url
    defaults:  { _controller: AcmeTestBundle:Test:action }

Contribute

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

Contributors list

About

A Sublime Text bundle for Symfony2 development