Vocabulary

FQCN

The FQCN (Fully Qualified Class Name) is the full name of a class, which includes all of its namespaces.

Example: Symfony\Component\HttpFoundation\Request

Here, Request is the class name. The entire thing is an FQCN.

MVC

MVC means Model View Controller.

It is a way of organizing an application by splitting it into 3 main layers:

  • Model, for the data (DB)
  • View, for the display (templates)
  • Controllers, containing the business logic (code)

Type-hint

In a Symfony application, a type-hint is written into a controller’s parameters, or into a class constructor’s parameters.

It is then analyzed by Symfony to find the correct service and provide an instance to the controller or the service.

Controller

For instance, in a controller:

#[Route('/new', name: 'app_article_crud_new', methods: ['GET', 'POST'])]
public function new(
    Request $request, // <-- Special type-hint: provides the incoming request as an object
    EntityManagerInterface $entityManager, // <-- Type-hint
    SluggerInterface $slugger // <-- Type-hint
): Response
{
    //...
}

Service

class NewsletterService
{
    public function __construct(
        private MailerInterface $mailer, // <-- Type-hint
        private string $adminEmail
    ) {
    }

    //...
}

Autowired types can be type-hinted

Slug

A slug is a string with no spaces, accents, special characters, etc…making it more convenient to use into a URL or a filename.

For example, if an article has the following title:

Découvrez l'injection de dépendances dans Symfony

Then the corresponding slug may be :

decouvrez-l-injection-de-dependances-dans-symfony

The article could then be visited at the following URL:

https://domain.com/articles/decouvrez-l-injection-de-dependances-dans-symfony

Recipe

A recipe helps configuring a package or a bundle when installing it in an existing Symfony application. It’s executed by the Symfony Flex tool.

Symfony Flex is a Composer plugin: when using composer require XXX to install a package, Symfony Flex will verify if a recipe is available for this package. A recipe will contain, for example, configuration files, or files that will be created at a determined location into the project. The goal is to facilitate the integration of a package into a Symfony application.

Interface

In OOP, an interface is an abstraction: it only contains method signatures. So every class implementing an interface must provide a definition for each method of the interface.

Example

I’d like to write an alert system. For instance, when something happens, I want to alert a user, or an administrator.

But sending alerts can be done in many ways: SMS, emails, push alert on the phone, etc…

First, I’m going to define an interface, an abstraction, so that I can define how an alert system must behave:

<?php

interface AlertInterface
{
    /**
     * Send alert notification
     */
    public function sendAlert();
}

Then, if I want to implement how to send SMS alerts, I can create a class and make it implement AlertInterface:

<?php

class SmsAlert implements AlertInterface
{
    public function sendAlert()
    {
        // Sending SMS
    }
}

But I can also write the email one:

<?php

class EmailAlert implements AlertInterface
{
    public function sendAlert()
    {
        // Sending email
    }
}

In conclusion, in AlertInterface, I only write how an alert system must behave. Then, I can write classes that implement this interface, so that they implement the system, but using different ways.

Polyfill

A polyfill, in a specific version, can allow one to use features from a more recent version, by emulating them.

For instance, if I’m using PHP 7, I can’t use features from PHP 8.

But if I install the Symfony PHP 8.0 Polyfill package, I can then use functions like str_contains (reference), which was introduced in PHP 8.0, because a polyfill of this function was written inside this Symfony package.