Skip to content

pawelryznar/php-ddd-cargo-sample

 
 

Repository files navigation

php-ddd-cargo-sample

PHP 5.4+ port of the cargo sample used in Eric Evans Domain-Driven Design book

Scrutinizer Quality Score Build Status

CQRS & ES?

The original cargo sample is not based on CQRS and EventSourcing. However, you may have read something about it in relation to Domain-Driven Design. The php-ddd-cargo-sample shows you the original approach using application services, a combined write and read model and an ORM (Doctrine in our case) to hide the persistence layer. This is still a very good and valid approach but CQRS and EventSourcing gets a lot of attention these days because it offers a great way to tackle complex problems.

Our suggestion is that you have a look at the cargo example and also at proophessor-do.

Proophessor-do demonstrates CQRS and ES using prooph components and it is different then other example applications.

Proophessor-do is incomplete and you are ask to get the job done. This is a great way to learn more about CQRS and EventSourcing. Don't worry, the prooph community is available in a chat to help you with your task. See the HALL OF FAME. The first tasks are already done and the next ones in progress. So what are you waiting for? Go pick up a task, too!

Ok, you would like to explore the cargo sample first? Just read on. It starts with the next heading.

Goal of the Project

We want to show the PHP way of implementing Domain-Driven Design with the help of the original Cargo sample used in Eric Evans book Domain-Driven Design: Tackling Complexity in the Heart of Software. This has already been done using java and a C# version is also available.

It is not the one way to apply DDD, but should help you understand the theory and gives you a starting point. Also see the Caveats of the java implementation. The same applies for our version.

The PHP port is work in progress. Your welcome to fork the repo and help finishing the cargo sample application.

The application layer is based on ZF2 and we use Doctrine2 to persist our aggregates. This would be a common combination in a large PHP project but both frameworks are not required. They just make our life easier and let us focus on the Domain-Driven Design implementation. Both can be replaced with any other PHP based components.

Iterative Implementation

To go with you when you read the book, our sample has a release of each chapter. So you can simply git checkout ChapterOne and you only get the starting view of the domain with just to entities Cargo and Voyage. Our application evolves chapter by chapter the more knowledge we get about the domain. Each chapter ships with it's own review, where you can find additional information about the implementation, tips and tricks and many more.

Installation

See the Installation file.

Useful DDD tools

Check our collection of DDD Tools and Libs.

Become a member

If you want to share your experience with other DDD enthusiasts or want to ask a question about DDD then the DDDinPHP google group is good place to do so.

You can find more DDD stuff like interesting articles and related libraries on the PhpFriendsOfDdd/state-of-the-union project.

Project Structure

There is no problem if you don't know the structure of a ZF2 application. All the important parts like the domain and the infrastructure implementation can be found in the namespace of the CargoBackend module.

Note: Project structure has changed in ChapterFour. In ChapterOne - ChapterThree the domain and infrastructure classes were included in the Application module!

Behavior Driven Design

All features of the application are described in feature files. You can find them in the features folder of the project. We make use of Behat and Mink to test our business expectations.

You can run the feature tests by navigating to the project root and start the selenium server shipped with the sample app: java -jar bin/selenium-server-standalone-2.37.0.jar After the server started successfully open another console, navigate to project root again and run Behat with the command php bin/behat.

*Note: If it does not work, check that the behat file is executable.

Unit Tests

Unit Tests are of course also available. You can find them in module/CargoBackend/tests. Got to the directory and simply run phpunit.

Note: Project structure has changed in ChapterFour. In ChapterOne - ChapterThree the test classes were included in the Application module!

Support

If you have any problems with the application please let me know and send me an email kontakt[at]codeliner[dot]ws or open a GitHub issue. Same applies if you have a question or a feature wish. Maybe I've missed a concept that you hoped to find in the example.

Chapter Overview

The chapter overview has moved to the PHP DDD Cargo Sample project page

Contributing

See the CONTRIBUTING file.

TODO

  • Provide vagrant support for simple application set up [not started]
  • Improve project pages (include reviews, DDD tools, ...) [not started]
  • Review of ChapterFour [in progress]
  • Implement ChapterFive [not started]
    • Switch to ValueObjects and use VOs whenever possible
    • Add reroute Cargo use case
    • Add HandlingEvents
    • Add delivery progress use cases

About

PHP Version of the cargo sample used in Eric Evans DDD book

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 82.7%
  • HTML 15.9%
  • Other 1.4%