Symfony Flashcards

1
Q

is symfony a full framework?

A

No it starts as a microframework then it builds up to be a frame work

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

how to make a new symfony project?

A

composer create-project symfony/skeleton name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what is index.php in the public folder?

A

it’s the front controller it’s a file that gets executed when you go to any url

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what is a route?

A

configuration that defines the url of a page

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what is a controller

A

a function that builds the content of the page

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what is the rule of a controller method?

A

it must return a symfony response object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

what is a slug?

A

it’s a url version of the title

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

what are the benefits of flex?

A

aliases

recipes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

what are the aliases for flex?

A

it’s just a shortcut for the name of the bundle

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

what is a recipe for flex?

A

it is executed by flex to add files or create directories or even modify files so that the bundle works without anymore config

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

what is symfony.lock?

A

it’s a file managed by flex and keeps track of what recipes have been installed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

what is bundles.php

A

it’s a file that has all the third party bundles that work with symfony

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

what is the AbstarctController

A

it’s a class that gives the controller shortcuts to methods and u don’t have to extend from it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

how to return a template?

A

$this->render(templateName , array( title => $title))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

what is the syntax of twig?

A

{{}} say something as it prints like a variable ora string or have logic in it like name = no ?? yes

{%%} do something

{##} comment

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

how to for loop in twig?

A

{% for comment in comments %}

{% endfor %}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

how to inherit in twig?

A

{% extends ‘base.html.twig’ %}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

what is the filter to get the length in twig?

A

comments | length

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

what happens when u tell twig to extend another template?

A

that u want to put your template inside of that template and the block are the holes where we can put our child template

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

how to put your content inside of a twig block?

A

{% block body %}

{% endblock %}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

can u give the blocks in twig a default ?

A

yes and u can then override it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

where can u use dump() from the profiler bundle?

A

ianywhere even twig {{ dump() }}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

what is a pack?

A

it’s a single file that installs a bunch of other bundles in the same step

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

how to unpack a pack?

A

composer unpack name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

where is the cache direcotry?

A

var/cache

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

why do we ut things in the public directory?

A

because they need to be accessed by the user browser

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

how should u include css or javascript?

A

using asset() function and it will give us more flexability to version our asset or cdn them

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

how to get url names in console?

A

php bin/console debug:router

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

how to generate url in twig?

A

{{ path() }}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

how to generate a url for a wildcard?

A

{{ path() , { slug : value} }}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

what happens when you override javascript or any block?

A

you completely override the parent so u must call {{ parent() }}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

how to return a json response from the controller?

A

JsonResponse

$this->json

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

what is a servidce?

A

it’s an object that does something like generate urls or send emails

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

what is autowiring?

A

it’s a process by which symfony injects the object into the function by looking at the type hint u provided

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

how to get services from the console?

A

bin/console debug:autowiring

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

where does services live?

A

inside the container

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

who put the services inside the container?

A

bundles

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q

what is a bundle?

A

it’s symfony plugin system and it lives in bundles.php as they provide services which are tools which means more bundles means more services

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

what is pipe raw in twig?

A

twig automatically escapes html in a variable and the pipe tells twig that it’s safe to use them

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
Q

what are the aliases for services?

A

every service has a unique name and any service that has the same alias u can use any one of them

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
41
Q

how to dump the configurations for a bundle?

A

php bin/console config:dump KnpMarkDownBundle

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
42
Q

what is the use of a config for a bundle

A

change the way the bundle behaves

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
43
Q

where does the config of a bundle live?

A

config/packages/file.yaml

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
44
Q

does the name of the config file matter?

A

no just the root which is the key that is not indented t the start of the file as symfony automatically loads all files under packages directory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
45
Q

how to view a full list of the services in the container?

A

php bin/console debug:container –shiw-private

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
46
Q

what does a servidce have in the contjainer?

A

a unique id

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
47
Q

what class handles every request?

A

Kernel in Controller directory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
48
Q

what loads undles.php?

A

registerBundles() in kernel class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
49
Q

what is symfony composed of?

A

just routes and services

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
50
Q

what loads the configuration files?

A

configContainer() in kernel class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
51
Q

what is the hierarchy of the config files?

A

packages gets loaded first then the environment specific but the env overrides anything before it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
52
Q

what is telda in yaml (~)?

A

it means null

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
53
Q

what is the difference in cache between prod and env?

A

cache doesn’t get rebuilt in prod meaning when u change something in the front end it doesn’t take effect

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
54
Q

how to build the initial files in cache?

A

php bin/console cache:warmup which makes the first request much faster

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
55
Q

what should u do when u have a service that depends on other services?

A

don’t pass them as arguments but inject them in the constructor

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
56
Q

what happens when u inject services in the constructor?

A

they get autowired u can autowire anything in debug:autowiring

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
57
Q

how to find search for a service in the console?

A

php bin/console debug:container –show-private name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
58
Q

what library does symfony use for logging?

A

monolog

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
59
Q

what are the benefits of using monolog?

A

u can have different channels that doe different things like logging to different files

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
60
Q

how to manually tell symfony to pass a specific object while autowiring?

A

under services.yaml

services:
App\Services\MarkDownHelper:
arguments:
$logger: ‘@id for service’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
61
Q

how to pass the service and not the string in services.yaml?

A

use @ before like ‘@id’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
62
Q

what is the _defaults key in services.yaml?

A

it sets the default behavior of all services in this file?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
63
Q

what is autowire key in services.yaml?

A

services will be automatically injected

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
64
Q

what is the App\ key in services?

A

make all classes inside src available as services

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
65
Q

does the App\ mean that all the classes are instantiated?

A

no… symfony will not instantiate unless someone asked for the service

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
66
Q

how many instances do u have for a service?

A

only one per request

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
67
Q

what is the id of a service you create?

A

it’s equal to it’s name but mostly for bundles the have a snake naming like app.assets

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
68
Q

what does bind: key under _defaults: key in services .yaml do?

A

it says when u find an argument like this pass this service like:

_default:
bind:
$markdownLogger:
‘@monolog.logger.markdown’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
69
Q

why do u put bind key under _defualts key?

A

to make the config project wide

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
70
Q

what is the container?

A

it’s an object that holds all the services but it can also hold normal config values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
71
Q

how to define parameters for config?

A

under parameters key

parameters:
cache_adapter: ‘cache.apcu’

then u can reference it by :
‘%cache_adapter%’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
72
Q

where should u define your parameters?

A

u can do it anywhere but it’s better to make it centralized like in services.yaml

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
73
Q

when does services.yaml load?

A

after packages then environment specific

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
74
Q

how to fix that services.yaml loads last?

A

make a file called services_dev.yaml and override your parameters there

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
75
Q

can we autowire scalar types like bool?

A

no because symfony doesn’t know it’s value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
76
Q

how to print the parameters in the console?

A

php bin/console debug:container –parameters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
77
Q

what is the debug parameter?

A

kernel.debug

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
78
Q

where does autowiring happens?

A

the action of the controller or the constructor of the service and theconstructor is the place it’s meant to happen

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
79
Q

why does autowiring work for controller actions?

A

just for convenience but it was meant to only work for the constructor as it’s used to instantiate services

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
80
Q

what are public and private services?

A

in symfony 3 most services where public and u could get them using $this->get or use the container object to get the service but with symfony 4 in services.yaml we have public: false which means that most of the services we create are private and can’t use $this->get

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
81
Q

what is faster private or public services?

A

private

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
82
Q

what is dependency injection?

A

we pass objects and services through the parameters in the construction

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
83
Q

what should you do when you want to autowire a class that is not a service?

A
first you find it's id by using debug:container name
then u put it in the constructor
then u bind it by using the class name

Nexy\Client: ‘@id’

84
Q

what are the two ways of binding?

A

u can use a variable name or a class name or interface

85
Q

what happens when you put the class name: @id directly under services and not under bind?

A

a new service is registered with that name as an id

86
Q

how does symfony know which object to pass when u create ur own services?

A

it just looks up the type hint in the container with that exact id

87
Q

what are environment variables?

A

they are variables that are set in the operating system and then can be read by your code and we can get them by using getenv() or $_SERVER[]

88
Q

how can we read environment variables in yaml?

A

‘%env(NAME)%’

89
Q

how to print environment variables in the console?

A

php bin/console about

90
Q

where does environment variables live?

A

in .env during developmentand it doesn’t get commited

91
Q

what can we do when we don’t find .env during development?

A

we copy .env.dist and make a .env

92
Q

why should we use .env in production?

A

because it’s slow

93
Q

what is the limitation of an env variable?

A

they are only string values

94
Q

how can u fix the limitation of env variable?

A

by casting it like

‘%env(bool:NAME)%’

95
Q

what are some prefixes while setting env variables under parameters?

A

u can set a default env value under parameters

resolve: resolve parameters , like %foo% if they are inside environment variable
file: read the contents of a file
base64: base64_deode they are good with line breaks or special characters
constant: read php constants
json: json_decode

and u can chain all of these like:
json:file:

and u can write ur own environment variable

96
Q

what are setter injections?

A

it’s a function used to set an object that is optional to the class meaning that the class will work even if it doesn’t have that object
like a logger
setLogger()

if($this->logger)

97
Q

how to autowire a setter injection?

A

by using /**@required*/ above the setter will make symfony make an object of logger before the other object is passed

98
Q

how to make a command using maker bundle?

A

php bin/console make:command name:name

99
Q

how does symfony know that we added a new command?

A

thanks to autoconfigure all the services are registered and wehn we extend from command class symfony knows that it should register it as a command

100
Q

what does each command have?

A

arguments : which are strings passed after the command

options: prefixed with –

101
Q

does symfony have a database layer?

A

no it depends on doctrine

102
Q

what is a symfonystyle class?

A

it’s a class that helps with dealing with input and output to the console

103
Q

how to create database in console?

A

php bin/console doctrine:database:create

104
Q

what is doctrine?

A

an ORM

105
Q

what is an ORM?

A

Object Relational Mapper

106
Q

what is an Object relation mapper?

A

it means that each table in the database will have a corresponding class in our code which means if we want to create an article table we will have to create an article class

107
Q

what is an entity to doctrine?

A

it’s the name that doctrine gives to the classes that are saved in the database

108
Q

how how make an entity in the console?

A

php bin/console make:entity

109
Q

what is an entity?

A

it’s a normal php class that can be saved in the database

110
Q

what are field types in doctrine?

A

they are types that map the mysql data types like string to varchar

111
Q

what tells doctrine that this class is an entity?

A

the annotations above the class

112
Q

how to make a migration for the entity?

A

php bin/console make:migration

113
Q

where does maker look when it creates a migration?

A

it looks at the database and the entity

114
Q

how to run the migration?

A

php bin/console doctrine:migrations:migrate

115
Q

how to know the status of the migrations in the console?

A

php bin/console doctrine:migrations:status

116
Q

how does the migrations work?

A

it created a table in the database called migration_versions then the first time we ran doctrine:migrations:migrate it executed the migration and inserted a new row in the table with the version number which is the date and when we tried to run it a second time it looked at the table for that version in the code and it was already there so it knew that it shouldn’t run it again

117
Q

how to tell doctrine to save to the database?

A

just create an object from the entity u want to save and tell doctrine to save it

118
Q

why does entity setter methods return $this?

A

so u can be able to chain the function calls

119
Q

what is the service that saves to and gets from the database?

A

EntityManager from doctrine bundle or

EntityManagerInterface

120
Q

what are the two steps to saving to the database?

A

persist() and flush()

121
Q

what is the difference between persist and flush?

A

persist tells doctrine u just want to save it but the insert query is not done yet and then flush saves it to the data base

122
Q

what happens after u call flush?

A

the object is created and u have a new id u don’t need to go fetch the object from the database to get it’s id

123
Q

what is the first thing to do when u want to fetch from the database?

A

get the entity Repository

124
Q

what does doctrine return when u query for something?

A

an object not an array and this is the whole point of doctrine as we are saving and fetching objects not rows

125
Q

how to create a 404 in the controller?

A

throw $this->createNotFoundException

this is a trait and it’’s special because it generates 404

126
Q

what happens when u say article.title in twig?

A

it looks for a property and if it has a getter it will use the method

127
Q

what do u need to extend twig like make a filter?

A

a twig extension

128
Q

how to create a twig extension?

A

bin/console make:twig-extension

129
Q

how extensions should u make?

A

just one and put all your custom functions there

130
Q

what is the problem when u extend twig app extension?

A

services injected in the constructor will be instantiated even if you don’t use them because twig need to know about all of it’s functionality even if u don’t use them

131
Q

how to fix the problem of extending the app extension?

A

by implementing ServiceSubscriberInterface and inject ContainerInterface as when u implement that interface it get injected automatically so the constructor must have that type hint available and in the function of getSubscribedServices return the class that u want to autowire and symfony makes it public so u can get it by $this->container->get() so instead of having the object u have a container that has the object and only used it in the function that u need

132
Q

what is the mini container name?

A

ContainerInterface as it doesn’t hold all the services just a subset of them

133
Q

where should u use a service subscriber?

A

Twig Extensions
Event Subscribers
Security Voters

134
Q

what should we use to find something by order?

A

$repository->findBy( [] [name => DESC])

135
Q

what should we pass to findBy to get everything?

A

in the criteria pass an empty array

136
Q

how is the entity and repository connected?

A

by the annotation ORM\Entity(repositoryClass) above the entity

137
Q

what is the language of querying with doctrine?

A

Doctrine Query Language or DQL

138
Q

what are the way of writing DQL?

A

write a DQL string or use a QueryBuilder

139
Q

what is the query builder?

A

it’s an object oriented builder that helps write the DQL

140
Q

how should u order the functions of the query builder?

A

u can make them in any order it doesn’t matter

141
Q

what is the difference between where and andwhere in the query builder?

A

where will remove any other where clauses u may have added but andWhere is safe to use

142
Q

should u use where or andwhere?

A

andwhere

143
Q

what is a prepared statement?

A

that instead of hacking the value in the string by concatenation u use setParamets to se the value and the value is referenced by :val as that prevent SQL injection

144
Q

what is the parameter u give to the querybuilder?

A

just an alias to the entity u r querying for

145
Q

can u use Or in the andwhere statement?

A

yes

146
Q

what do u always call at the end of the querybuilder?

A

getQuery()

147
Q

what do u call to get an array of the objects?

A

getResult()

148
Q

what do u call in querybuilder to get only one result?

A

getOneOrNullResult()

149
Q

what happens when u make:entity on an existing one?

A

u update the existing one

150
Q

how to set a default value for a field in the database?

A

b y giving it a default value in php

private $heatCount = 0

151
Q

what is the concatenation operator in twig?

A

~

152
Q

should u use concatenation to concatenate images/imageFileName from database?

A

no create a method in the entity and use it

153
Q

how to inject an entity inside a controller action?

A

type hint it like Article $article and send the slug or an id and symfony will try to find an object that corresponds to what u send

154
Q

what is a race condition?

A

when there is a time when u fetch and save to the database that in this time the old value might change and 10 other might have saved to the same field

155
Q

how to update an object in the database?

A

flush

156
Q

do we call persist when we update an object?

A

no because when doctrine fetches the object it already knows to persist it and when u call flush it just updates it

157
Q

when should u put logic related to an entity?

A

when it’s simple just put ion the entity class but not the controller instead of a service

158
Q

should u keep all setter and getter methods in the entity?

A

no u should replace some of them with a more descriptive methods like instead setHeartCount replace it with incrementHeartCount

159
Q

how to make a fixture in the console?

A

php bin/console make:fixtures

160
Q

how many fixture classes should u make?

A

one per entity or a group of related entity

161
Q

what is the idea behind fixtures?

A

1 - we write code to create and save objects

2- run a fixture command to execute all of our fixture classes

162
Q

what is the command to load all fixtures?

A

php bin/console doctrine:fixtures:load

163
Q

what is the ObjectManager?

A

it’s an interface that implements entitymanager

164
Q

what is a good trick to use when u want to create a fixture?

A

create an abstract BaseFixture Class

and make an abstract method called loadData that takes ObjectManager implement two other methods load which must be implemented because it’s a fixture and make it call loadData and make a private instance for the ObjectManager and then make another method called callMany which takes 3 arguments $className , $count , callable $factory
make a for loop and inside it
$entity = new $className();
factory($entity , $i)
which is a method that gets called for every entity that we make
then persist the entity and add a reference to that entity

$this->addReference($className.’_‘$i , $entity);

this line helps us to reference one fixture class from another fixture class

after all that go extend from base fixture and implement it’s method loadData

165
Q

what is stofdoctrineextensionbundle?

A

it adds many features like sluggable or blameable or loggable or timestampable

166
Q

what are the types of repositories for any bundle?

A

contrib and main where contrib is not monitored by symfony and people can contribute to it

167
Q

how does sluggable feature work behind the scenes?

A

by creating an event subscriber?

168
Q

what else could u use event subscribers for like sluggable?

A

add an index in the database everytime u do a new insert

169
Q

what should u do when a migrations fails?

A

u should drop the database and start over as it’s now in an unstable state because if a migration has more than one sql statement and the second or third fail the first one now will run twice when u try to rerun the migration

170
Q

how to drop the database using console?

A

php bin/console doctrine:database:drop

171
Q

what should u do when u want timestampable?

A

u should use the trait timestampableentity and don’t create the fields yourself

172
Q

how to create a relationship between entities?

A

php bin/console make:entity and when asked for the field name write the other entity name like article and when asked for the type write relation

173
Q

what happens when u have an entity that relates to an array of another entity?

A

u must set the initial property in the constructor to be equal to a new ArrayCollection();

174
Q

are onetomany and manytoone relationships different?

A

no they are the same relationship but viewed from different sides

175
Q

why did we use the name of the entire entity as the field name of the relation?

A

because we are setting the entire object not just the id

176
Q

how to save a relation in the database?

A

u first create the object then relate it to the relation
comment = new comment();
comment->setArticle($article);

177
Q

what is an authentication system?

A

it’s a way for your users to login whether it’s a login form , an api authentication

178
Q

how to make a user entity from the console?

A

php bin/console make:user

179
Q

what does make:user need for it to work?

A

composer require security

180
Q

should ur app check for a user password?

A

if it’s an api then probably no

181
Q

what is the first step in creating an authentication system?

A

create a user class

182
Q

what is the one rule u should follow when u create a user class?

A

it must implement the UserInterface

183
Q

what are the two methods that the userinterface provide?

A

getUserName and getRoles

184
Q

what is getUserName used for in the user class?

A

to get the display name for the debug toolbar that’s all

185
Q

what is getRoles used for in the user class?

A

user permissions

186
Q

what does each user class have in security.yaml?

A

a user provider

187
Q

what is the type of the roles property in the user class?

A

it’s a json column and an array in phpbut mysql 5.6 or lower doesn’t have native json column type in mysql to it will use json_encode

188
Q

what yaml file contains the server version?

A

doctrine.yaml

189
Q

what is the job of the user provider?

A

it reloads user data from session and some additional jobs like remember me or impersonation which is to switch between users

190
Q

do u need to configure a user provider?

A

if ur user class is an entity u don’t need to do that but if the user class is just a normal class then make:user will make a user provider for u as well

191
Q

how does the user provider reload the user from session?

A

At the end of every request (unless your firewall is stateless), your User object is serialized to the session. At the beginning of the next request, it’s deserialized and then passed to your user provider to “refresh” it (e.g. Doctrine queries for a fresh user).

Then, the two User objects (the original from the session and the refreshed User object) are “compared” to see if they are “equal”. By default, the core AbstractToken class compares the return values of the getPassword(), getSalt() and getUsername() methods. If any of these are different, your user will be logged out. This is a security measure to make sure that malicious users can be de-authenticated if core user data changes.

However, in some cases, this process can cause unexpected authentication problems. If you’re having problems authenticating, it could be that you are authenticating successfully, but you immediately lose authentication after the first redirect.

In that case, review the serialization logic (e.g. SerializableInterface) if you have any, to make sure that all the fields necessary are serialized.

192
Q

what is a firewall?

A

it’s the authentication system

193
Q

how many firewalls can u have per request?

A

only one firewall can be active per request

194
Q

how does a firewall match your request?

A

by using the pattern: key in security.yaml
u can use host , path , HTTP methods or a service and u can leave the pattern: key and don’t write it to make the firewall match all requests

195
Q

what is the main firewall?

A

it’s the firewall that handles all the requests and doesn’t have a pattern key

196
Q

does not having a pattern: key in the firewall mean that we have no authentication?

A

no it just means it will match to any url but the anonymous : lazy key means that u can be authenticated as an anonymous user

197
Q

why does authentication in symfony feel a bit like magic?

A

because instead of building a route and a controller to handle login u will activate an authentication provider

198
Q

what is an authentication provider?

A

some code that runs automatically before your controller is called

199
Q

is it better to use the build in authentication provider or make a guard authenticator?

A

guard authenticator?

200
Q

what is a guard authenticator?

A

a class that allows you to control every part of the authentication proccess

201
Q

what is the guard authenticator used for?

A

login forms or api authentication

202
Q

how to make a registeration form in the bundle?

A

php bin/console make:registeration-form

203
Q

how to create a login form?

A

php bin/console make:auth

204
Q

what does make:auth for loginform create?

A

1- route and a controller
2- template to render the login form
3- a guard authenticator class that processes the login
4- updates to the main security file

205
Q

what are the steps u should do after u make a login form?

A

u allow access in securty.yaml to be accesses anonymously
- { path: ^/login$, roles: IS_AUTHENTICATED_ANONYMOUSLY }

add your authenticator under guard: authenticators:
- App\Security\LoginFormAuthenticator