This is a simple console-based application designed to manage students, courses and enrollments.
Its goal is to demonstrate how Backslash components work together in order to power event-sourced systems in PHP.
The application is interacted with through a few scripts located in the bin
folder. It relies solely on Backslash for
simplicity in learning, without using any additional libraries.
Featured Backslash components are:
- State and domain events
- Commands and command dispatcher
- Projectors and projections
- Projection rebuilding
- Stream enrichment
- Testing scenarios
- Middlewares
- A student cannot be enrolled in more than 3 courses.
- A course cannot take more students than its capacity.
- Enrollments cannot occur outside the enrollment period.
Start by installing dependencies with Composer:
composer install
Move to the bin
folder and run the demo.php
script:
cd bin
php demo.php
It initializes the SQLite database in data/demo.sqlite
where events and projections are persisted. It also runs some
commands to create students and courses.
As you play with the app, you may open the SQLite database in your favourite IDE to inspect its content.
Commands in these examples must be run from the
bin
folder.
php register-student.php
--id: The student ID (integer)
--name: The student name
php create-course.php
--id: The student ID (integer)
--name: The course name
--capacity: How many students can enroll in this course (integer)
php create-course.php
--id: The course ID (integer)
--capacity: The new capacity (integer)
Enrollment period must be open for student to enroll in courses.
php open-enrollment-period.php
php close-enrollment-period.php
php enroll.php
--student: The student ID (integer)
--course: The course ID (integer)
php withdraw.php
--student: The student ID (integer)
--course: The course ID (integer)
Students enrolled in this course will be withdrawn.
php cancel-course.php
--id: The course ID (integer)
php events.php
php reset.php
php demo.php
This script deletes all projections and rebuilds them by replaying events.
php rebuild-projections.php
Some tests can be found in the tests
folder. They use on the Scenario
component.
vendor/bin/phpunit