Symfony Documentation

repository·7.4·Indexed 25 days ago

https://github.com/symfony/symfony-docs

Official documentation for the Symfony framework, featuring guides, component references, tutorials, and best practices for application structure, service configuration, and controller implementation.

Tokens
285.3K
Snippets
819
Records
1.2K
Agent score
78%

What's inside symfony-docs

  1. Overview of Symfony Twig Extensions

    7.4
    Symfony uses the Twig template engine. While Twig provides its own set of default filters and functions, Symfony provides additional extensions (filters, functions, and tags) specifically designed to integrate Symfony components directly into your Twig templates. If the built-in Symfony extensions do not meet your needs, you can create a custom Twig extension.
  2. Overview of the Form Component

    7.4
    The Form component provides a way to create, process, and reuse forms. It is designed to handle data interaction between your client and your application. While traditionally used with HTML forms, the component is data-agnostic and can process data from standard form posts or from APIs.
  3. Overview of Symfony project structure

    7.4

    A standard Symfony project contains the following key directories:

    • bin/: Contains executable files like bin/console.
    • config/: Contains configuration for routes, services, and packages.
    • public/: The document root for the project; contains publicly accessible files.
    • src/: Contains all your PHP application code.
    • templates/: Contains Twig templates.
    • var/: Stores automatically-created files like var/cache/ and var/log/.
    • vendor/: Contains third-party libraries installed via Composer.
  4. Overview of the TypeInfo component

    7.4

    The TypeInfo component is used to extract type information from PHP elements. It supports:

    • Type Definition: A powerful Type definition capable of handling unions, intersections, and generics.
    • Element Extraction: Methods to retrieve types from PHP properties, method arguments, return types, and raw strings.
  5. Benefits of migrating from flat PHP to Symfony

    7.4

    Migrating from a custom 'flat PHP' architecture to Symfony provides several architectural advantages:

    • Code Organization: Promotes clear, consistent, and reusable code structures that improve developer productivity.
    • Reduced Boilerplate: You no longer need to maintain low-level utilities like autoloading, routing, or controller rendering; Symfony handles these core concerns.
    • Component Ecosystem: Immediate access to high-quality open-source tools including:
      • Doctrine (ORM)
      • Twig (Templating engine)
      • Security component
      • Form component
      • Validator component
      • Translation component
    • Flexible Routing: The Routing component enables fully-flexible URL structures.
    • HTTP-Centric Architecture: Built-in support for HTTP caching (via Symfony's internal HTTP cache) and compatibility with external tools like Varnish.
  6. Understand the Symfony configuration directory structure

    7.4

    Symfony applications use the config/ directory to manage application settings. The default structure includes:

    • config/bundles.php: Enables or disables packages (bundles) in your application.
    • config/packages/: Stores configuration for every installed package (e.g., api_platform.yaml).
    • config/routes.yaml or config/routes/: Defines the application routing configuration.
    • config/services.yaml: Configures the service container.
    • config/preload.php: Defines classes for OPcache preloading.
    • config/reference.php: (Introduced in Symfony 7.4) An autogenerated file containing definitions to improve IDE autocompletion and static analysis when using PHP for configuration.

    When using Symfony Flex, installing a package automatically updates bundles.php and creates new configuration files in config/packages/.

  7. What is a Controller in Symfony

    7.4
    A controller is a PHP callable (typically a method within a class) that processes a Request and returns a Response. The Response can be HTML, JSON, XML, a file download, a redirect, or an error. The controller contains the application logic required to render the content of a page.
  8. What is the Service Container

    7.4
    In Symfony, useful objects (like a Mailer or a database saver) are called services. All these services live inside a central object called the service container. The container centralizes object construction, promotes strong architecture, and optimizes performance by managing how these objects are instantiated and shared.
  9. Overview of available Lock Stores

    7.4

    Locks are managed by Stores, which implement PersistingStoreInterface. Stores can be local or remote, and may or may not support blocking, expiration, sharing, or serialization. If a store does not support blocking, the Lock class will automatically retry to acquire the lock in a non-blocking way until successful.

    Special Testing Stores

    • InMemoryStore (LOCK_DSN=in-memory): Saves locks in memory during a process.
    • NullStore (LOCK_DSN=null): Does not persist anything (introduced in Symfony 7.2).
  10. What is a Gateway Cache?

    7.4

    A gateway cache (also known as a reverse proxy cache, surrogate cache, or HTTP accelerator) sits between your application and the client.

    Its workflow is:

    1. Accept requests from the client.
    2. Pass requests to your application.
    3. Receive responses from your application.
    4. Store responses deemed "cacheable".
    5. If the same resource is requested again, the cache sends the stored response directly to the client, bypassing your application.
  11. Map form fields to object properties using property_path

    7.4

    By default, a form field named fieldName maps to the fieldName property of the underlying object using the PropertyAccess component (supporting get*, set*, is*, and has* methods).

    You can customize this mapping using the property_path option:

    • Different Property Name: Map a field named deadline to the dueDate property.
    • Nested Properties: Use dot notation to map to nested objects, e.g., category.name to access the name property of a Category object returned by getCategory().
    // Mapping to a different property
    $builder->add('deadline', DateType::class, [
        'property_path' => 'dueDate',
    ]);
    
    // Mapping to nested properties
    $builder->add('categoryName', TextType::class, [
        'property_path' => 'category.name',
    ]);
  12. Use Entity Value Resolvers for Doctrine entities

    7.4
    If using Doctrine, you can use the EntityValueResolver to automatically query for an entity based on a route variable and pass it directly to your controller action. If the entity is not found, it automatically triggers a 404 error. For more complex retrieval logic, perform the query manually using a Doctrine repository method inside the controller.