demo-event-subscriber

Symfony : triggering SQL Filter on events from Symfony Demo Application

The “Symfony Demo Application” is a reference application created to show how to develop applications following the Symfony Best Practices.

You can also learn about these practices in the official Symfony Book.

This extension aims to be a POC on how to trigger SQL Filters when a condition is met. Users might have a country. Idem for posts, I added a simple property for country. If the connected user have a defined country, the filter aims to restrict visible posts on this one.

Differences from the original symfony/demo

Visit the blog connected as the french user, you’ll see only french posts.
Visit the blog connected as the english user, you’ll see only english posts.
Visit the blog anonymously, or connected as an admin, or connected as a user whom language is unknown, and you’ll see all posts.

Requirements

Installation

Download Composer and use the composer binary installed on your computer to run these commands:

# clone the code repository and install its dependencies
$ git clone https://github.com/atierant/demo-event-subscriber.git my_project
$ cd my_project/
$ composer install
$ npm install

Usage

There’s no need to configure anything before running the application. There are 2 different ways of running this application depending on your needs:

Option 1. Download Symfony CLI and run this command:

$ cd my_project/
$ symfony serve

Then access the application in your browser at the given URL (https://localhost:8000 by default).

Option 2. Use a web server like Nginx or Apache to run the application (read the documentation about configuring a web server for Symfony).

On your local machine, you can run this command to use the built-in PHP web server:

$ cd my_project/
$ php -S localhost:8000 -t public/

Tests

Execute this command to run tests:

$ cd my_project/
$ ./bin/phpunit