Symfony Demo Application

repository·main·Indexed 25 days ago

https://github.com/symfony/demo

A reference implementation demonstrating development following Symfony Best Practices. It includes a complete project structure with entities for Users, Posts, Tags, and Comments, as well as custom CLI commands for user management (app:add-user, app:delete-user, app:list-users) and repository methods for searching and retrieving posts.

Tokens
1.8K
Snippets
6
Records
18
Agent score
83%

What's inside symfony-demo

  1. Use Bootswatch Flatly theme with custom fonts

    main
    The Bootswatch Flatly theme is included in this project with modifications to prevent it from automatically loading Google Fonts. Instead of using the standard CSS, the project uses the embedded Sass source and overrides the font imports using Sass variables. This allows you to use the Flatly theme while maintaining control over your font assets.
  2. Install the Symfony Demo Application

    main

    You can install the Symfony Demo project using either the Symfony CLI or Composer.

    Using Symfony CLI

    Run the following command to create a new project based on the demo:

    symfony new --demo my_project

    Using Composer

    To create a new project via Composer:

    composer create-project symfony/symfony-demo my_project

    Alternatively, you can clone the repository and install dependencies manually:

    git clone https://github.com/symfony/demo.git my_project
    cd my_project/
    composer install
  3. Run the Symfony Demo Application

    main

    The application requires no prior configuration. You can run it using the Symfony CLI, a standard web server (Nginx/Apache), or the built-in PHP web server.

    Using Symfony CLI

    cd my_project/
    symfony serve

    By default, the application will be accessible at https://localhost:8000.

    Using the built-in PHP web server

    cd my_project/
    php -S localhost:8000 -t public/
  4. Install dependencies for the Symfony Demo project

    main

    If you encounter errors indicating that dependencies are missing when running the application, ensure you have installed the project dependencies using Composer.

    Run the following command in the project root:

    composer install
  5. Install Symfony Runtime if missing

    main

    If the application fails with an error stating that the Symfony Runtime is missing, you need to require the symfony/runtime package via Composer.

    composer require symfony/runtime
  6. Retrieve latest posts with `PostRepository::findLatest()`

    main
    Use findLatest() to fetch a paginated list of published posts. You can optionally filter the results by a specific Tag object. The method automatically filters for posts where publishedAt is less than or equal to the current time and orders them by publication date in descending order.
  7. Search for posts with `PostRepository::findBySearchQuery()`

    main
    Use findBySearchQuery() to search for posts by their title. The method splits the provided string into individual terms (ignoring terms shorter than 2 characters) and performs an OR search across the titles. Results are ordered by publishedAt descending.
  8. User entity role constants

    main

    The App\u005cEntity\u005cUser class defines constants for user roles to ensure consistency across the application and prevent typos when performing security checks.

    final public const ROLE_USER = 'ROLE_USER';
    final public const ROLE_ADMIN = 'ROLE_ADMIN';
  9. Delete a user via the CLI

    main

    The app:delete-user command allows you to remove a user from the database by providing their username.

    Usage Modes:

    1. Direct Argument: Provide the username directly in the command.
    2. Interactive Mode: If you omit the username argument, the command will launch an interactive wizard and prompt you to enter the username.

    If the specified username does not exist in the database, the command will throw a RuntimeException stating: User with username "<username>" not found.