You are on page 1of 12

mcq interview laravel

----------------------------------------------------------

The complexity of merge sort algorithm is


O(n)
O(log n)
O(n2)
O(n log n) CCC
--------------------
-------------------------------------------------------------------------

----------------------------------------------------------------------------

The elements of an array are stored successively in memory cells because


By this way computer can keep track only the address of the first element and the
addresses of other elements can be calculated CC
the architecture of computer memory does not allow arrays to store other than
serially
Both of above
None of above
----------------------------------------------------------------

----------------------------------------------------------------

----------------------------------------------------------------

----------------------------------------------------------------

----------------------------------------------------------------

----------------------------------------------------------------

----------------------------------------------------------------

----------------------------------------------------------------

----------------------------------------------------------------

----------------------------------------------------------------

----------------------------------------------------------------

Create QCM from this about symfony


https://trello.com/c/aHnP3WUI/1-learn-for-symfony-certification

***************************************** Symfony
****************************************
Structure de symfony

Dossier public ou www

1- what's the main directory (the directory to be copied on the web server for
deployment)

The web root of a Symfony2 app is the 'web' directory, but when you push to
production the entire symfony2 project should be pushed not just the web root.

app/: This directory contains the application configuration;


src/: All the project PHP code is stored under this directory;
vendor/: Any vendor libraries are placed here by convention;
web/: This is the web root directory and contains any publicly accessible files;

The main directory contains the app folder.


-----------------------------------------------------------------------------------
-------------------------------------------------

2- where assets (css, javascript) should be placed

web/
app/
A l'int�rieur du bundle
Dans la racine du projet

The assets should be kept in the bundles 'Resources/public/[css/js/images]'


folders. From here you would have to copy or symlink those directories into the web
root to make them accessible. Symfony2 comes with a command line utility located in
the 'app' directory. app/console assets:install web --symlink command executed from
the command line of your symfony2 project root will install all of the bundle's
assets for you.

The assets should be placed in the bundles folder they're related to. This folder
is named "public".
-----------------------------------------------------------------------------------
-------------------------------------------------

3- if (and how) environment should be changed when publishing my website


To change environments and you are using Apache you would use a .htaccess file and
mod_rewrite to select which environment you would want to use

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /app.php [QSA,L]

using /app.php puts me into production mode and using /app_dev.php would put me in
development mode.

All you need to do is remove the app_dev.php file.


-----------------------------------------------------------------------------------
-------------------------------------------------

Quel est l'objectif du routage(routing ) dans Symfony2?


The goal of the Symfony2 routing system is to parse a URL and determine which
controller should be executed.
-----------------------------------------------------------------------------------
-------------------------------------------------
When Symfony denies the user access, what happens?

When Symfony denies the user access, the user sees an error screen and receives a
403 HTTP status code
-----------------------------------------------------------------------------------
-------------------------------------------------

In Symfony, the most basic way to secure part of your application is to secure an
entire URL pattern. Is this true/false?

True

-----------------------------------------------------------------------------------
-------------------------------------------------

Queolle est le format standard d'un fichier de configuration YAML


.yml
.yaml

the standard .yaml extension instead of the current .yml one.


https://stackoverflow.com/questions/21059124/is-it-yaml-or-yml
-----------------------------------------------------------------------------------
-------------------------------------------------

Ou se trouve la classe Kernel?


src/
bin/
var/
etc/

The Kernel class has been moved to src/


-----------------------------------------------------------------------------------
-------------------------------------------------

The Kernel class implements the logic to load the bundles from ______
container.yaml
bundles.php
parameters.yml
config.php

One file per bundle and bundles.php are the two core concepts that enables Symfony
to automatically manage your bundles and their configurations.
-----------------------------------------------------------------------------------
-------------------------------------------------

Le cache est stocker dans quelle r�pertoir ______?


src/
bin/
var/
etc/

var/cache/ should now only be used to store long term cached contents like compiled
container files, compiled translations, or Doctrine proxies. No temporary files.
Basically, anything stored under var/cache should have a warmup class able to
generate the cache files. Files that should never be updated after deployment to
allow for read-only filesystems.
-----------------------------------------------------------------------------------
-------------------------------------------------

/var/cache directory must be read-only?


True
False

we will be able to guarantee a read-only /var/cache directory at some point. Having


read-only directories is a requirement of some hosting platforms like Heroku or
SensioCloud and helps scale an application. Probably not for Symfony 4.0 though.

-----------------------------------------------------------------------------------
-------------------------------------------------
http://fabien.potencier.org/symfony4-directory-structure.html
-----------------------------------------------------------------------------------
-------------------------------------------------

Dans symfony4 le repertoir web/ est renomm� � _____ ?


www/
public/
html/
Aucune de ces r�ponse

-----------------------------------------------------------------------------------
-------------------------------------------------
Quelle(s) commande(s) utils�e(s) pour ex�cuter les test phpUnit ?
$ phpunit.php
$ phar.php
$ phpunit -c app/phpunit.xml
$ phpunit

phpunit can be run from the project root without having to explicitly specify the
path of the configuration file.
# Symfony2
phpunit -c app/phpunit.xml

# Symfony3 (no need to specify the configuration file location)


phpunit
-----------------------------------------------------------------------------------
-------------------------------------------------

Dans sf3 ou se trouve le fichier console?


src/
bin/ XXXX
app/
var/

-----------------------------------------------------------------------------------
-------------------------------------------------

Dans sf2 ou se trouve le fichier console?


src/
bin/
app/ XXXXX
var/

The file app/console was moved to bin/console in Symfony 3.


-----------------------------------------------------------------------------------
-------------------------------------------------
The entire /var directory should be writable by your webserver?
True
False

-----------------------------------------------------------------------------------
-------------------------------------------------
Les fichiers logs sont stocker dans quelle r�pertoir?
/public/log/
/app/log/
/var/log/
/etc/log/

-----------------------------------------------------------------------------------
-------------------------------------------------

Quelle commande utilis� pour ajouter le bundle FOSUserBundle

$ composer require friendsofsymfony/user-bundle


$ php composer.phar install friendsofsymfony/user-bundle
$ composer install friendsofsymfony/user-bundle
$ composer update friendsofsymfony/user-bundle

Require the bundle with composer:


$ composer require friendsofsymfony/user-bundle "~1.3"
Composer will install the bundle to your project's vendor/friendsofsymfony/user-
bundle directory.

==> See the difference between composer install and composer require?

https://getcomposer.org/doc/01-basic-usage.md
-------------------------------------------------------------------------

When Composer has finished installing, it writes all of the packages and the exact
versions of them that it downloaded to _____?
composer.json
composer.phar
composer.lock
composer

When Composer has finished installing, it writes all of the packages and the exact
versions of them that it downloaded to the composer.lock file, locking the project
to those specific versions. You should commit the composer.lock file to your
project repo so that all people working on the project are locked to the same
versions of dependencies
-----------------------------------------------------------------------------------
-------------------------------------------------
Le ficher composer.json se trouve dans _____?
/var
La racine de votre projet XXXXXX
Les deux a et b
Aucune de ces reponses

-----------------------------------------------------------------------------------
----------------------------

Composer charge les bundel install� dans quelle r�pertoir _____?


/var/
/vendor/ XXXXX
/var/cache/
Aucune de ces reponses

Composer simply resolves all dependencies listed in your composer.json file and
downloads the latest version of their files into the vendor directory in your
project. (The vendor directory is the conventional location for all third-party
code in a project).

-----------------------------------------------------------------------------------
----------------------------

Le d�p�t principal de Composer est ______?


PEAR
RPM
Packagist XXXXX
GIT

Packagist [https://packagist.org/] est le d�p�t principal de Composer.

A Composer repository is basically a package source: a place where you can get
packages from. Packagist aims to be the central repository that everybody uses.
This means that you can automatically require any package that is available there,
without further specifying where Composer should look for the package.
-----------------------------------------------------------------------------------
----------------------------

Dans Symfony le fichier "autoload.php" se trouve dans le r�pertoir ______?


/bin/
/app/
/var/
Aucune de ces reponses XXXXXX

Il se trouve dans le r�pertoir /vendor/.


Autoloading nous permet de ne charger que les classes n�cessaires et non pas toutes
les classes,

-----------------------------------------------------------------------------------
----------------------------

Pour r�cup�rer une session et l'intialiser dans Symfony on utilise le code


suivant :

$session = $request->getSession();

// store an attribute for reuse during a later user request


$session->set('foo', 'bar');

Pour acc�der � la session dans TWIG on utilise ______?

{{ app.session.getRequest('foo', 'bar'); }}
{{ app.getSession('foo', 'bar'); }}
{{ app.session.get('foo', 'bar'); }} XXXXX
Aucune de ces reponses

-----------------------------------------------------------------------------------
----------------------------

Pour r�cup�rer une session et l'intialiser dans Symfony on utilise le code


suivant :

$session = $request->getSession();

// store an attribute for reuse during a later user request


$session->set('foo', 'bar');

Pour acc�der � la session dans un autre controlleur on utilise ______?

$request->getSession('foo');
$session->get('foo'); XXXXXX
Request::getSession('foo');
Aucune de ces reponses

-----------------------------------------------------------------------------------
----------------------------

How to increase the session timeout in Symfony2 ?

Soulution :

framework:
session:
cookie_lifetime: 43200 #time in seconds

-----------------------------------------------------------------------------------
----------------------------

Quelle directive est utilis� pour restreindre l'acc�es � /admin dans le fichier
"security.yaml"?
allow_if:
access_control: XXXXXXX
deny_access:
is_granted:

access_control in security.yaml allows you to protect URL patterns (e.g. /admin/*).

# config/packages/security.yaml
security:
# ...
access_control:
# require ROLE_ADMIN for /admin*
- { path: ^/admin, roles: ROLE_ADMIN }

-----------------------------------------------------------------------------------
----------------------------

Comment v�rifier si un utilisateur a un r�le sp�cifique pour exc�cuter une action


dans Twig?
denyAccess()
is_granted() XXXXX
is_authenticated_fully
isGranted()

If you want to check if the current access inside a template, use the built-in
is_granted() helper function:

Exemple : Ici seul l'admin peut voire le bouton supprimer:


{% if is_granted('ROLE_ADMIN') %}
<button type="submit">Delete</button>
{% endif %}

-----------------------------------------------------------------------------------
----------------------------

Quelle annotation utilis� pour restrict access prevent access to a specific actions
on controller ?
(A) @Security
(B) @IsAuthenticated
(C) @IsGranted
les deux A et C sont vrais. XXXXXXXXX
Aucune de ces r�ponses n'est vraie.

The @Security and @IsGranted annotations restrict access on controllers:

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;

class CheckController extends Controller


{
/**
* @IsGranted("ROLE_ADMIN")
* or
* @Security("is_granted('ROLE_ADMIN')
*/
public function addAction()
{
// ...
}
}

-----------------------------------------------------------------------------------
----------------------------

Dans ________ nous activons/desactivons l'utilisation d'un bundle?

/vendor/autoload.php
/src/Kernel.php XXXXXXX
/config/services.yaml
/app/config/parameters.yml
/app/config/config.yml

Enable the bundle in the kernel:

-----------------------------------------------------------------------------------
----------------------------

Comment verifier si un utilisateur a un role specific dans une action de Symfony?

(A)
// BAD - $user->getRoles() will not know about the role hierarchy
$hasAccess = in_array('ROLE_ADMIN', $user->getRoles());

(B)
// GOOD - use of the normal security methods
$hasAccess = $this->isGranted('ROLE_ADMIN'); XXXXXXX

(C)
$hasAccess = $this->container->isGranted('ROLE_ADMIN');

(D)
$hasAccess = $user->hasRole('ROLE_ADMIN')

-----------------------------------------------------------------------------------
----------------------------

This settings bellow allow you to ________?

access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/, roles: ROLE_ADMIN }

protect URL patterns "/login"


protect all pages of your site except "/login"
allow login just for Admin
Aucune de ces r�ponses n'est vraie.

The login page must be accessible by anonymous users


-----------------------------------------------------------------------------------
----------------------------

Dans Symfony4, le r�pertoir "/public/" contient le(s) fichier(s)________?


config.php
.htaccess
favicon.ico
robots.txt
Aucune de ces r�ponses n'est vraie. XXXXX

Not all projects need those files.

-----------------------------------------------------------------------------------
----------------------------

Dans Symfony3 le fichier "app/phpunit.xml.dist" est d�placer vers _____?


bin/
app/
var/
La racine XXXXXX

-----------------------------------------------------------------------------------
----------------------------

Dans Symfony3 le r�pertoir app/cache et app/logs ont �t� d�plac�s vers ______
var/dev/
var/ XXXXXXX
/var/www
Aucune de ces r�ponses n'est vraie.

-----------------------------------------------------------------------------------
----------------------------

Dans Symfony3, Quelle commande utiliser pour vider le cache dans l'environement de
production?
$ php app/console cache:warmup --env=prod
$ php app/console cache:clear --env=prod
$ php bin/console cache:clear --env=prod XXXXXXXXX
$ php app/console cache:clear --environment=prod

-----------------------------------------------------------------------------------
----------------------------
Quelle commande pour valider le mapping entre les entit�s et les tables ?

php bin/console orm:schema:validate


php bin/console doctrine:schema:validate XXXXX
php bin/console doctrine:schema:validate --entity
php bin/console orm:schema-tool:update

-----------------------------------------------------------------------------------
----------------------------

Comment acc�der au service de doctrine et au gestionnaire d'entit�s?


$em = $this->getDoctrine()->getManager();
$em = $this->get('doctrine')->getEntityManager();
$em = $this->container->get('doctrine.orm.entity_manager');
Tout les r�ponses sont vrais XXXXXXXXXXXXX

Exemple:

// R�cup�ration de l'entity manager


$entityManager = $this->getDoctrine()->getManager();

// Cr�e l'article et persister le dans la BD.


$page = new Page;
$page->setTitre('Ma Premi�re Page');
$entityManager->persist($page);
-----------------------------------------------------------------------------------
----------------------------

Quelle commande utiliser pour cr�er un contr�leur pour l'objet "Page"


$ php app/console create:controller Page
$ php app/console create:controller PageController
$ php app/console generate:controller PageController XXXXXXX
$ php app/console generate:controller Page

-----------------------------------------------------------------------------------
----------------------------

Comment int�grer des contr�leurs dans Twig?


{{ render(app.request.baseUrl ~ '/pathto/action', {'var': value} ) }}
{% include 'YourBundle:YourController:action.html.twig' with {'var': value} only %}
{% render controller("YourBundle:YourController:yourAction", {''var': value}) %}
Tout les r�ponses sont vrais XXXXXXXXXXXXX

-----------------------------------------------------------------------------------
----------------------------

Supposone que vous avez le Form Type suivant


"Acme\ProductBundle\Form\Type\ProductType"
Comment d�finissez votre formulaire en tant que service, compl�tez les lignes
suivants?

# src/Acme/TaskBundle/Resources/config/services.yml
services:
acme_demo.form.type.product:
class: Acme\ProductBundle\Form\Type\ProductType
tags:
- { name: form.type, alias: product }

define your form class as a service allow you to re-use the form in several places.

-----------------------------------------------------------------------------------
----------------------------

-----------------------------------------------------------------------------------
----------------------------

Comment d�clencher un �v�nement apr�s l�insertion d�un enregistrement?

D'abord, nous enregistrons le service en tant que "Doctrine Event Listeners" dans
le fichier "app/config.yml":

services:
my.listener:
class: Vendor\AcmeBundle\ProductClass
tags:
- { name: doctrine.event_listener, event: ..................,
method: .................... }

Pr�ciser l'evenement sur lequel nous devons �couter, et quelle m�thode sera
utiliser lorsque l'�v�nement est d�clench�?

services:
foo.listener:
class: Vendor\FooBundle\BarClass
tags:
- { name: doctrine.event_listener, event: postPersist, method:
onPostPersist }

l'evenement "postPersist" a lieu juste apr�s persist.


-----------------------------------------------------------------------------------
----------------------------

-----------------------------------------------------------------------------------
----------------------------

-----------------------------------------------------------------------------------
----------------------------

-----------------------------------------------------------------------------------
----------------------------

-----------------------------------------------------------------------------------
----------------------------

-----------------------------------------------------------------------------------
----------------------------
Comment d�truire l'�lement 'blog.pages_count' dans le cache de Symfony?
$ php app/console doctrine:cache:clear blog.pages_count
$cache->delete('blog.pages_count'); XXXXXX
$cache->drop('blog.pages_count);
$cache->set('blog.pages_count', null);
-----------------------------------------------------------------------------------
----------------------------