Skip to content

eewee/symfony4

Repository files navigation

symfony4

PHP Storm

File / Settings / Plugins / Browse remote

Plugin :

Symfony plugin : https://plugins.jetbrains.com/plugin/7219-symfony-plugin

PHP Annotations : https://plugins.jetbrains.com/plugin/7320-php-annotations

PHP Toolbox : https://plugins.jetbrains.com/plugin/8133-php-toolbox

Video :

Grafikart : YouTube

Les teachers du net : YouTube

https://symfonycasts.com/screencast/symfony

https://symfonycasts.com/screencast/symfony/setup

Note :

https://github.com/eewee/Symfony4

Doc API :

https://api.symfony.com/4.1/Symfony/Component/Routing/Generator/UrlGenerator.html

https://api.symfony.com/4.1/Symfony/Component/Serializer/Encoder/CsvEncoder.html

Vrac :

Liste bundle : flex.symfony.com (=https://symfony.sh/)

Demo/source Symfony 4 : demo

Subscriber : permet d'écouter les events de l'ORM preUpdate, postUpdate, preRemove, postRemove, ...

Setup

Projet web :

composer create-project symfony/website-skeleton my-project

Serveur web (option) :

composer require symfony/web-server-bundle --dev

Run serveur local sur http://127.0.0.1:8000/ :

php bin/console server:run

Checking for Security Vulnerabilities :

composer require sensiolabs/security-checker --dev

Apache - htaccess - Rewrite Rules (source) :

composer require symfony/apache-pack

Annotation :

composer require annotations

Check route :

php bin/console debug:router

SwiftMailer (source) :

composer require symfony/swiftmailer-bundle

Form (source / type) :

https://symfony.com/doc/current/forms.html

composer require symfony/form

composer require symfony/validator

// Disable : HTML5 validator (required) :

{{ form_start(form, {'attr': {'novalidate': 'novalidate'}}) }}

DOCTRINE :

Voir la req qui sera utilisée lors de la création du schéma de la db

php bin/console doctrine:schema:create --dump-sql

Créer le schéma de la db :

php bin/console doctrine:schema:create

Maj le schéma de la db :

php bin/console doctrine:schema:update

Autre :

php bin/console doctrine:migrations:status --show-versions

php bin/console doctrine:migrations:version YYYYMMDDHHMMSS --delete

ADD :

php bin/console doctrine:migrations:execute YYYYMMDDHHMMSS --up

DROP :

php bin/console doctrine:migrations:execute YYYYMMDDHHMMSS --down

CREATE MIGRATION :

php bin/console make:migration

EXEC MIGRATIONS :

php bin/console doctrine:migrations:migrate

Si on ajoute manuellement une valeur dans entity :

php bin/console make:entity --regenerate

Status :

php bin/console doctrine:migrations:status

Faire une requête :

php bin/console doctrine:query:sql "SELECT * FROM user"

Result : 
array(1) {
  [0]=>
  array(3) {
    ["id"]=>
    string(1) "1"
    ["username"]=>
    string(6) "Thomas"
    ["password"]=>
    string(60) "$2y$12$7kID8aQ/DOsY1Ue28SJV0OJwHXolrIsNce.Dhf/7dEt16gRH17ep6"
  }
}

php bin/console doctrine:query:dql "SELECT u FROM App\Entity\User u"

array(1) {
  [0]=>
  object(stdClass)#597 (5) {
    ["__CLASS__"]=>
    string(15) "App\Entity\User"
    ["id:App\Entity\User:private"]=>
    int(1)
    ["username:App\Entity\User:private"]=>
    string(6) "Thomas"
    ["password:App\Entity\User:private"]=>
    string(60) "$2y$12$7kID8aQ/DOsY1Ue28SJV0OJwHXolrIsNce.Dhf/7dEt16gRH17ep6"
    ["text:App\Entity\User:private"]=>
    array(0) {
    }
  }

Comprendre le OneToOne, OneToMany, ManyToOne et ManyToMany + Repository :

OpenClassRoom

L'annotation ManyToOne a un attribut inversedBy.

L'annotation OneToMany a un attribut mappedBy.

FRONT

Installer "Encore" pour la gestion des scss, css et js.

Lancer la commande “yarn encore dev --watch” durant le dev pour la compilation du scss.

Encore (assets > scss, css, js, …) :

https://symfony.com/doc/4.0/frontend/encore/installation.html

https://symfony.com/doc/current/frontend/encore/simple-example.html

Compile assets once : yarn encore dev

Or, recompile assets automatically when files change : yarn encore dev --watch

On deploy, create a production build : yarn encore production

Bootstrap CSS/JS :

https://symfony.com/doc/current/frontend/encore/bootstrap.html

https://symfony.com/doc/current/form/bootstrap4.html

Generate url (absolute / relative) :

https://symfony.com/doc/current/routing.html#routing-requirements (generateUrl)

https://symfony.com/doc/current/controller.html (redirectToRoute / redirect)

Template erreur 404, 500, etc … :

https://symfony.com/doc/current/controller/error_pages.html

Log :

https://symfony.com/doc/current/logging.html

https://github.com/Seldaek/monolog/blob/master/doc/02-handlers-formatters-processors.md

Déploiement :

https://symfony.com/doc/current/deployment.html

Tuto pour déployer avec Git :

https://fr.tuto.com/compte/achats/video/101881/player/#190751-preparation-du-depot-distant

OVH > https://geekco.fr/blog/deployer-un-site-symfony3-sur-ovh

https://thatelo.fr/blog/deployer-symfony-git-serveur

SUR SERVEUR DISTANT :

1/ git init :

cd /kunden/homepages/xx/dxxxxxxxxx/htdocs/var/git

mkdir sf4.git

cd sf4.git

git init --bare

2/ se placer dans le dossier hooks :

cd hooks

vi post-receive

3/ Edit post-receive ET coller ceci :

#!/bin/sh

git --work-tree=/kunden/homepages/xx/dxxxxxxxxx/htdocs/sf4_test/ --git-dir=/kunden/homepages/xx/dxxxxxxxxx/htdocs/var/git/sf4_test.git checkout -f

4/ Droit execution :

chmod +x post-receive

SUR SERVEUR LOCAL (dans le dossier du projet symfony en local) :

git init

git remote add live ssh://uxxxxxxxx@homexxxxxxxxx.1and1-data.host/kunden/homepages/xx/dxxxxxxxxx/htdocs/var/git/sf4_test.git

git add .

git commit -m "Premier déploiement avec git"

git push live master

php composer.phar self-update

php composer.phar update

php composer.phar install --no-dev --optimize-autoloader

php bin/console cache:clear --env=prod --no-debug

php bin/console assets:install

DIVERS :

// install composer

curl -sS https://getcomposer.org/installer | /usr/bin/php7.1-cli

// update composer

/usr/bin/php7.1-cli composer.phar self-update

// Heroku deploy :

https://afsy.fr/avent/2017/03-deployer-un-projet-symfony-flex-sur-heroku

SSH 1and1 :

Source : https://www.1and1.fr/digitalguide/serveur/securite/generer-des-cles-ssh-pour-votre-connexion-reseau/

http://thisisnotcnn.blogspot.com/2015/07/setup-remote-git-repository-on-1-server.html

http://flosy.info/2012/07/utilisation-de-git-avec-un-hebergement-de-1and1/

1/ Générer key :

cd .ssh

ssh-keygen -t rsa -C “contact@tld.com” -b 4096

/Users/xxx/.ssh/1and1_rsa

mdp (optionnel)

2/ Copier contenu 1and1_rsa.pub (local) dans ~/.ssh/authorized_keys (distant à la racine).

on peut le faire en uploadant 1and1_rsa.pub sur le serveur.

cat id_rsa.pub >> ~.ssh\authorized_keys

3/ En local :

cd ~/.ssh

ssh-add 1and1_rsa

4/ En distant :

On copie la key public dans .ssh/authorized_keys (à la racine du FTP 1and1) :

cat ~/id_rsa_1and1.pub >> ~/.ssh/authorized_keys

5/ test en indiquant :

ssh uxxxxxxxx@homexxxxxxxxx.1and1-data.host ls

On doit avoir le rendu sans devoir indiquer le mot de passe ssh.

clone :

git clone ssh://uxxxxxxxx@homexxxxxxxxx.1and1-data.host/kunden/homepages/xx/dxxxxxxxxx/htdocs/var/git/sf4_test.git

pull :

git pull ssh://uxxxxxxxx@homexxxxxxxxx.1and1-data.host/kunden/homepages/xx/dxxxxxxxxx/htdocs/var/git/sf4_test.git master