Creating Symfony projects like a sir
I’m pretty sure many of you don’t like to download the latest version of Symfony Standard Distribution from symfony.com, install it, remove the AcmeDemoBundle from src directory and remove those stuff mentioning it every time you start a new project. I don’t like it either. Fortunately, I have a better way to do so.
hacfi from Freenode channel #symfony-dev suggested me a way to start new projects, the only thing I’ve done is to create a bash script to automatize it. So first thing you have to do is install composer:
$ curl -S http://getcomposer.org/installer | php
$ mv composer.phar /usr/bin/composer
This way you can reach composer from anywhere you want by typing “composer” to the shell – you don’t even have to type “php” or “phar”. Next thing you should do is put a record to your crontab so it would update itself regularly (or if you prefer, you can do manually when you want with “composer self-update”).
Here comes the real trick: create a nice function to your ~/.bashrc file:
export EDITOR=vim | |
__createsymfony () { | |
composer create-project symfony/framework-standard-edition $1 $2; | |
rm -rf $1/src/Acme $1/*.md $1/web/apple-touch-icon.png $1/web/favicon.ico $1/app/cache/dev $1/LICENSE | |
find $1/app $1/src -type f -exec sed -i '/Acme/d' {} \; | |
sed -i '/^_demo.*$/,/^$/d' $1/app/config/routing_dev.yml | |
} | |
alias create-symfony='__createsymfony' | |
# Usage: create-symfony path version | |
# Example: create-symfony /var/www/fooproject 2.1.4 |
The usage of this little script is:
$ create-symfony path version
For example you want to create a new Symfony 2.1.3 project called foo:
$ create-symfony foo 2.1.3
This command will create a directory foo containing a new Symfony 2.1.3 project, but without the Acme directory, every reference to it, the apple-touch-icon.png and the favicon.ico. Now you can work with it :)
UPDATE: the way I described leaves two unfinished routes in app/config/routing_dev.yml, which has to be removed manually (_demo and _demo_secure).
UPDATE 2: no need to manually remove _demo and _demo_secure path now.
this is nice, but then why not creating a skeleton? and do rather composer create-project myproject/mysymfony-skeleton?
Well, maybe that’s an easier solution :) I didn’t even think about that, despite I’m creating a custom distribution (closed :() for our own projects. The difference is that in our custom distribution is for projects with some special properties, which are similar to each other – so there will be some “pre-coded” stuff.
you should share an in between distro just removing the pre-coded stuff, like biga did
you mean like a SymfonyDemolessDistribution? :D
Nice..maybe we should add this to the zsh symfony2 plugin:
https://github.com/robbyrussell/oh-my-zsh/blob/master/plugins/symfony2/symfony2.plugin.zsh
Hi, I’m Emanuele, the main developer of http://symfonybricks.com. After looking at your article, I invite you to have a look at this platform, where you could publish guides and recipes about Symfony.
It is also possible post a guide (named “brick”) on SymfonyBricks, referencing the original article by specifying the canonical url.
Cheers!
http://symfonybricks.com
https://github.com/inmarelibero/SymfonyBricks