Example PHP REST API application built with Expressive using Doctrine ORM, complete with associations, pagination, and DB connectivity inside Docker containers. Used in #Beachcasts videos on YouTube.
Example PHP REST API application spread across 2 Docker containers. (1=Apache, 2=MySQL) I used Zend Expressive with Doctrine ORM in an effort to help document usage of both in a typical scenario. The application leveraged the zend-expressive-skeleton as a starting point, and was installed set up for Modules using FastRoute, zend-servicemanager, and no template engine (since it is a REST API responding with Json).
The Doctrine Entities also include example usage of Associations between Entities (see the OneToMany association in Bank using ArrayCollection to ManyToOne association in Branch) as well as parent-child relationships within the same Entity (See the Bank associations - ManyToOne $parent and OneToMany $children using ArrayCollection).
cd /new/cloned/location
docker-compose up -d
docker-compose down
At this point the REST API should work. (The following REST endpoints return a listing from the DB.)
Each of these can be called as an HTTP GET, or an HTTP POST with Json fields payload. (See example body content in docblocks of Create and Update Handlers. Sample Json data for requests can be found in /data.)
In addition to these endpoints the hypermedia in each response provides information to additional endpoints.
Also, the Zend Expressive, Doctrine DBAL, and Doctrine CLI commands are available by gaining the terminal from Docker.
docker ps
will provide the container ids to use in the following command.docker exec -i -t {container-id} bash
Replace {container-id} with the Docker container ID from the docker ps
for the web container.
Then from the root prompt the CLI tools are available. Example commands are:
php vendor/bin/doctrine list
php vendor/bin/doctrine-dbal list
php vendor/bin/expressive
php vendor/doctrine/bin/doctrine list
This code is an example, but any advice to help make this a more awesome teaching tool is welcome. Please submit a ticket with details, or better yet, submit a pull request. Thank you.
coming soon