Symfony Flex: Paving the Path to a Faster, Better Symfony
Symfony Flex: Paving the Path to a Faster, Better Symfony
Still Under Development

What’s Different?
- PHP 7+ is required
- all folders are optional. If your project isn’t using one, it doesn’t have to be there. This makes the directory tree much simpler and more readable. Additionally, often useless files like
.htaccess,LICENSE, andREADMEhave been removed as well – a project which needs those can easily add them. - there is no more
webfolder. Instead, there is thepublicfolder, like in all other major frameworks. This consolidates user experience across ecosystems. - temporary files go under
/varin the root of the project folder, with the/var/cachesubfolder reserved for long term cache, like merged class files for deploying apps as read-only artifacts - source code goes under
/src. No/app. - configuration goes into
/config. - templates go into
/templates. - Flex will have its own Symfony-verified list of packages that are referenced by one and one alias alone. So executing
composer require cliwill actually trigger Flex, which will look in its list of packages, find the one tagged ascli(in this case, Symfony Console), and install it. These “official” packages are called recipes, and can be found here. To accept user-submitted recipes, a flag exists in Flex’s configuration which needs to be set to true:composer config extra.symfony.allow-contrib true. Those recipes can be found here. By officially endorsing some packages, Symfony is in many ways becoming as opinionated as Laravel. While this is bad in some ways, it’s very good in many more ways: a consolidated, opinionated way to build Symfony apps used by most people so that everyone is on the same page. - bundle fragments no longer need to be custom-activated and added into a ton of files. Flex automates this, as well as their removal.
- instead of parameters in config files, Symfony 4 will be using environment variables like Laravel
Bootstrapping
composer create-project symfony/skeleton flexy

index:
path: /
defaults: { _controller: 'App\Controller\DefaultController::index' }
<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
class DefaultController
{
public function index()
{
return new Response('Hello');
}
}

Execution Permissions
~ bin/console
-bash: bin/console: Permission denied
- running the console with
php bin/consoleinstead of running it directly, or - adding the “execute” permission to the file on the host machine (not from within the virtual machine), by executing:
chmod +x bin/console. This will allow the direct execution ofbin/consolefrom within the VM then.
Adding Bundles
composer req template
{% extends '../base.html.twig' %}
{% block body %}
{{ greeting }}
{% endblock %}
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class DefaultController extends Controller
{
public function index()
{
return $this->render('default/index.html.twig', ['greeting' => 'hello']);
}
}

Big Bundles
composer req admin
mysql -u homestead -psecret
create database flexy character set utf8mb4 collate utf8mb4_unicode_ci;
DATABASE_URL="mysql://homestead:secret@127.0.0.1:3306/flexy?charset=utf8mb4&serverVersion=5.7"
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Class Submission
* @package App\Entity
*
* @ORM\Entity
* @ORM\Table(name="submission")
*/
class Submission
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
public $id;
/**
* @ORM\Column(type="string", length=255)
*/
public $name;
/**
* @ORM\Column(type="string", length=255)
*/
public $url;
/**
* @ORM\Column(type="text")
*/
public $description;
}
easy_admin:
entities:
- App\Entity\Submission
bin/console doctrine:schema:update --force


Unofficial Bundles
composer config extra.symfony.allow-contrib true
composer req ramsey/uuid-doctrine

doctrine:
dbal:
url: '%env(DATABASE_URL)%'
types:
uuid: Ramsey\Uuid\Doctrine\UuidType
orm:
...
...
class Submission
{
/**
* @var \Ramsey\Uuid\Uuid
*
* @ORM\Id
* @ORM\Column(type="uuid", unique=true)
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class="Ramsey\Uuid\Doctrine\UuidGenerator")
*/
public $id;
...
bin/console doctrine:schema:drop --force
bin/console doctrine:schema:update --force

Comments
Post a Comment