ultisnips-php


Ⅰ. 插件描述

A vim bundle for Symfony2 development

Ⅱ. 基本信息

创建日期:  2014-06-23
使用用户:  1
Github星:  1
插件作者:  Cosmin-Mihai Tutunaru

Ⅲ. 安装方法

使用Vundle管理器安装

在你的.vimrc下添加:
Plugin 'stocarul/ultisnips-symfony2'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall

对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。

使用NeoBundle管理器安装

在你的.vimrc下添加:
NeoBundle 'stocarul/ultisnips-symfony2'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall

使用VimPlug管理器安装

在你的.vimrc下添加:
Plug 'stocarul/ultisnips-symfony2'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall

使用Pathogen管理器安装

在终端中运行以下命令:
cd ~/.vim/bundle
git clone https://github.com/stocarul/ultisnips-php

Ⅳ. 文档说明

ultisnips-symfony2

A vim bundle with snippets for symfony developers

Required bundles:

Shortcuts

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

Bundle

sfbundle

<?php

namespace Wee\DefaultBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class WeeDefaultBundle extends Bundle
{
}

sfbundleextension

<?php

namespace Wee\DefaultBundle\DependencyInjection;

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

/**
 * This is the class that loads and manages your bundle configuration
 *
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
 */
class WeeDefaultBundleExtension extends Extension
{
    /**
     * {@inheritDoc}
     */
    public function load(array $configs, ContainerBuilder $container)
    {
        $configuration = new Configuration();
        $config = $this->processConfiguration($configuration, $configs);

        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
        $loader->load('services.yml');
    }
}

sfbundleconfig

<?php

namespace Wee\DefaultBundle\DependencyInjection;

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

/**
 * This is the class that validates and merges configuration from your app/config files
 *
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
 */
class Configuration implements ConfigurationInterface
{
    /**
     * {@inheritDoc}
     */
    public function getConfigTreeBuilder()
    {
        $treeBuilder = new TreeBuilder();
        $rootNode = $treeBuilder->root('wee_default');

        return $treeBuilder;
    }
}

Class

sfclass

<?php

namespace Wee\DefaultBundle\Class;

class CustomClass
{

}

sfinterface

<?php

namespace Wee\DefaultBundle\Class;

interface CustomInterface
{

}

Command

sfcommandca

<?php

namespace Wee\DefaultBundle\Command;

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

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

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

    }
}

sfcommand

<?php

namespace Wee\DefaultBundle\Command;

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

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

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

    }
}

Controller

sfcontroller

<?php

namespace Wee\DefaultBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;

class DefaultController extends Controller
{
    public function indexAction(Request $request)
    {

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

sfcontrollera

<?php

namespace Wee\DefaultBundle\Controller;

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

class DefaultController extends Controller
{
    /**
     * @Route("index", name="default.index")
     * @Template(index)
     */
    public function indexAction(Request $request)
    {

    }
}

sfaction

public function customAction(Request $request)
{

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

sfactiona

/**
 * @Route("custom", name="default.custom")
 * @Template(custom)
 */
public function customAction(Request $request)
{

}

sfrender

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

sfforward

$this->forward(
    'Default:Controller:index',
    array()
);

sfredirect

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

Doctrine

sfrepository

<?php

namespace Wee\DefaultBundle\Repository;

use Doctrine\ORM\EntityRepository;

class CustomRepository extends EntityRepository
{
}

sfentity

<?php

namespace Wee\DefaultBundle\Entity;

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

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

sfcolumn

/**
 * @ORM\Column(type="string")
 */
protected $column;

Form

sfform

<?php

namespace Wee\DefaultBundle\Form\Type;

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

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

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

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

sfdatatransformer

<?php

namespace Wee\DefaultBundle\Form\Transformer;

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

class CustomDataTransformer extends AbstractType
{
    /**
     * {@inheritdoc}
     */
    public function transform($value)
    {

    }

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

    }
}

Twig

sftwigextension

<?php

namespace Wee\DefaultBundle\Twig;

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

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

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

Validator

sfcontraint

<?php

namespace Wee\DefaultBundle\Validator\Constraint;

use Symfony\Component\Validator\Constraint;

class CustomConstraint extends Constraint
{
    public $message = 'Custom';
}

sfvalidator

<?php

namespace Wee\DefaultBundle\Validator\Constraint;

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

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

    }
}

YML

sfroute

route_name:
    path: /
    defaults:
        _controller: Bundle:Controller:action
    requirements:
        _method: GET|POST

sfservice

service_name:
    class: %service_name.class%
    arguments:
        -

添加新评论