Symfony Flex 101


query talkSymfonyFlex {
	person(id: "renatomefi") {
		name
		twitter
        company
		bioPerLine
	}
	talk(id: "symfony-flex-101") {
	    title
	    date
	    type
	}
}
                    

{
  "data": {
    "person": {
      "name": "Renato Mendes Figueiredo",
      "twitter": "@renatomefi",
      "company": "@enrise",
      "bioPerLine": [
        "ZCE, ZCPE, ZFCE, LPIC-1, LFCS, LFCE Professional",
        "a.k.a.: A guy who loves linux and software dev!",
        "Co-organizer of @PHPAmersfoort and @rumoazcephp",
        "Contributor php-vcr and OverblogGraphQLBundle"
      ]
    },
    "talk": {
      "title": "Symfony Flex 101",
      "date": "2017-10-07T18:10:00.042Z",
      "type": "Symfony Camp UA 2017"
    }
  }
}
                    

RAD - Rapid Appplication Development

  • Fast prototyping
  • Iterative development
  • Less planning

Translates to

  • Highly opinionated
  • Magic
  • Black wizardry

Bundle App

Bundle-less


├── app
├── bin
├── composer.json
├── composer.lock
├── LICENSE
├── phpunit.xml.dist
├── README.md
├── src
├── tests
├── var
└── web
							

├── bin
├── composer.json
├── composer.lock
├── config
├── Makefile
├── public
├── src
├── templates
└── var
							

Bundle App

Bundle-less


├── AppCache.php
├── AppKernel.php
├── config
│   ├── config_dev.yml
│   ├── config_prod.yml
│   ├── config_test.yml
│   ├── config.yml
│   ├── parameters.yml.dist
│   ├── routing_dev.yml
│   ├── routing.yml
│   ├── security.yml
│   └── services.yml
└── Resources
    └── views
        ├── base.html.twig
        └── default
            └── index.html.twig
							

├── config
│   ├── bundles.php
│   ├── packages
│   │   ├── dev
│   │   │   └── routing.yaml
│   │   ├── framework.yaml
│   │   ├── routing.yaml
│   │   └── test
│   │       └── framework.yaml
│   ├── routes.yaml
│   └── services.yaml
└── src
    ├── Controller
    └── Kernel.php
							

Flex is default on Symfony 4.0

Works on SF 3.3 >


{
    "name": "symfony/skeleton",
    "type": "project",
    "license": "proprietary",
    "description": "Project description",
    "require": {
        "php": "^7.0.8",
        "symfony/framework-bundle": "^3.3",
        "symfony/yaml": "^3.3"
    },
    "require-dev": {
        "symfony/flex": "^1.0",
        "symfony/dotenv": "^3.3"
    }
}
			

composer create-project "symfony/skeleton:^3.3" flex-demo
			

# flex-demo ./bin/console
zsh: no such file or directory: ./bin/console
			

composer req cli
			

# flex-demo ./bin/console server:run


  [Symfony\Component\Console\Exception\CommandNotFoundException]
  There are no commands defined in the "server" namespace.

            

composer req webserver
			

composer req overblog/graphql-bundle
			

Symfony operations: 2 recipes
  - Configuring doctrine/doctrine-cache-bundle (1.3.1): From auto-generated recipe
  -  WARNING  overblog/graphql-bundle (0.9): From github.com/symfony/recipes-contrib:master
    The recipe for this package comes from the "contrib" repository, which is open to community contributions.
    Do you want to execute this recipe?
    [y] Yes
    [n] No
    [a] Yes for all packages, only for the current installation session
    [p] Yes permanently, never ask again for this project
    (defaults to n): y

			

------------------------------------------- -----------------------------
  Name                                       Path
 ------------------------------------------ -----------------------------
  overblog_graphql_endpoint                  /
  overblog_graphql_batch_endpoint            /batch
  overblog_graphql_multiple_endpoint         /graphql/{schemaName}
  overblog_graphql_batch_multiple_endpoint   /graphql/{schemaName}/batch
  overblog_graphql_graphiql                  /graphiql
  overblog_graphql_graphiql_multiple         /graphiql/{schemaName}

			

composer req twig
			

composer req debug-pack
			

Recipes

symfony.sh

manifest.json


{
    "bundles": {
        "Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle": ["all"]
    },
    ...
}
			    

config/bundles.php


<?php

return [
    Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
];

			    

manifest.json


{
    ...
    "copy-from-recipe": {
        "config/": "%CONFIG_DIR%/",
        "public/": "%PUBLIC_DIR%/",
        "src/": "%SRC_DIR%/"
    },
    ...
}
			    

manifest.json


{
    ...
    "composer-scripts": {
        "make cache-warmup": "script",
        "assets:install --symlink --relative %PUBLIC_DIR%": "symfony-cmd"
    },
    ...
}
			    

manifest.json


{
    ...
    "env": {
        "APP_ENV": "dev",
        "APP_DEBUG": "1",
        "APP_SECRET": "%generate(secret)%"
    },
    ...
}
			    

.env


# This file is a "template" of which env vars need to be defined for your application
# Copy this file to .env file for development, create environment variables when deploying to production
# https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration

###> symfony/framework-bundle ###
APP_ENV=dev
APP_DEBUG=1
APP_SECRET=c7f96874fff8401e487a4e8a0c28a356
###< symfony/framework-bundle ###

			    

manifest.json


{
    ...
    "gitignore": [
        ".env",
        "/public/bundles/"
        "/var/",
        "/vendor/"
    ]
    ...
}
			    

.env


##> symfony/framework-bundle ###
.env
/public/bundles/
/var/
/vendor/
###< symfony/framework-bundle ###

###> symfony/web-server-bundle ###
.web-server-pid
###< symfony/web-server-bundle ###

###> symfony/phpunit-bridge ###
/phpunit.xml
###< symfony/phpunit-bridge ###

			    

Thank you! Any Questions?

http://talks.mefi.in/symfony-flex-101-symfonycampua