Skip to content

backslashphp/demo

Repository files navigation

Backslash Demo Application

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

Domain rules

  • 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.

Getting started

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.

Usage

Commands in these examples must be run from the bin folder.

Register a student

php register-student.php

--id: The student ID (integer)
--name: The student name

Create a course

php create-course.php

--id: The student ID (integer)
--name: The course name
--capacity: How many students can enroll in this course (integer)

Change course capacity

php create-course.php

--id: The course ID (integer)
--capacity: The new capacity (integer)

Open enrollment period

Enrollment period must be open for student to enroll in courses.

php open-enrollment-period.php

Close enrollment period

php close-enrollment-period.php

Enroll a student in a course

php enroll.php

--student: The student ID (integer)
--course: The course ID (integer)

Withdraw a student from a course

php withdraw.php

--student: The student ID (integer)
--course: The course ID (integer)

Cancel a course

Students enrolled in this course will be withdrawn.

php cancel-course.php

--id: The course ID (integer)

Management scripts

Show the content of event store

php events.php

Delete events and projections

php reset.php

Restart demo

php demo.php

Rebuild projections

This script deletes all projections and rebuilds them by replaying events.

php rebuild-projections.php

Testing

Some tests can be found in the tests folder. They use on the Scenario component.

vendor/bin/phpunit

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages