Please read this section at least one day prior to the seminar. This section outlines what you are expected to know, be able to do, or prepare in advance. Following these instructions will help you get the most out of the seminar and ensure smooth participation.
This is a remote practical. There is no on-site activity. Instead, you are expected to solve the assignments in the time and place of your choosing. Unless stated otherwise, you are expected to work alone. You are not allowed to share your solution with your colleagues. Each assignment has a specific deadline and submission conditions.
Before the start of the practical, you should be able to:
In this practical you will continue with the code from the last week practical. Please completely finish the previous assignment before starting this practical.
You are not allowed to collaborate with your colleagues!
On the other hand, you are allowed to use AI in any way you see fit. You are free to use AI for autocomplete, generating scaffolding, functions, and more. You can try to use AI as a driver or even let it generate a whole solution for you. Just make sure you understand the code.
You are expected to note your use of AI in the "./practical-04/README.md" file in the "## Use of AI" section.
You are required to finish all the assignments, commit, and push your solution prior to 21.3.2026 AOE. You do not have to deploy it to webik, just be sure it would work should your try it.
Keep in mind: JSON + HTTP != REST API.
GitLab: ./practical-04/
Continue with your code from previous practical. Your application already expose following API.
Your objective is to add support of users (/api/v1/users), libraries (/api/v1/libraries), and borrowing (/api/v1/borrowings). You can find details about the new API on following slides. You can still mock all data and data storage operations.
Continue to the next slide once you are done >>>
For each user, you need to store an identifier, a name, and an e-mail. You are free to add additional attributes. If a request / response body is not empty, you must use JSON format.
Handle missing data and invalid queries in the same way for the book's API.
Continue to the next slide once you are done >>>
For each library, you need to store an identifier, a name, and an address. You are free to add additional attributes. If a request / response body is not empty, you must use JSON format.
Handle missing data and invalid queries in the same way for the book's API.
Continue to the next slide once you are done >>>
The API must support borrowing of a book by a user. For each borrowing, you need to store the start and end times. You are free to add additional attributes. If a request / response body is not empty, you must use JSON format.
Handle missing data and invalid queries in the same way for the book's API.
Congratulations, if you have followed the instructions, you have just reached the end of this exercise.
Doctrine is an ORM implementation for PHP.
You are free to design your own database schema. Yet, the schema must contain the following tables.
You are expected to introduce columns and additional tables as needed. If you do not have your own SQL database you can use webik. You can connect to MySQL at webik using phpMyAdmin, or Adminer.
You can connect to the database using SSH tunel from your computer.
ssh {user-name}@webik.ms.mff.cuni.cz -p 42222 -L 3306:localhost:3306
This will open the shell as well. You can use "-N" to not execute a remote command.
Continue to the next slide once you are done >>>
GitLab: ./practical-04/
Your objective is to connect your application to the database using Doctrine.
First, you need to install dependencies. See Project setup. Think about what you are installing and why; do not just copy and paste. Do you need all the listed dependencies?
Next, continue with Obtaining the EntityManager. Keep in mind what database and driver you are using. You also need to enable the driver (mysqli extension) in your PHP installation. For the purpose of this project, please use mysqli driver.
Continue to the next slide once you are done >>>
The next step is to create your entities. Those will be mapped to database tables. You can draw inspiration from the tutorial section Product Entity, Bug, and User entity.
Try to utilize PHP-DI to inject repositories (EntityManager.getRepository) not the EntityManager. You should have one repository per table.
Congratulations, if you have followed the instructions, you have just reached the end of this exercise.
Your objective is to continue with the code from the previous exercise and improve its quality.
GitLab: ./practical-04/
Your application needs to load the configuration from somewhere. The configuration includes: database connection details and base path.
Use parse_ini_file to parse and load configuration from "./practical-04/.env" file. Your application must be able to load files of the following structure:
DATABASE_NAME = skoda
DATABASE_USER = skoda
DATABASE_PASSWORD = heslo1234
DATABASE_HOST = localhost
DATABASE_DRIVER = mysqli
BASE_URL = /~skoda/nswi153/practical-03
Continue to the next slide once you are done >>>
Employ PHP_CodeSniffer to check the quality of your code. Make sure it does not produce any errors.
Continue to the next slide once you are done >>>
GitLab: ./practical-04/README.md
Create a representative README.md file for your project. Do not forget to include information about the use of AI.
Continue to the next slide once you are done >>>
When running using WSL, you may have problem connecting to the database, error "database not found". Please make sure you are not running the database locally. Try connecting using the "mysql" client.
In past some of your colleagues have encountered an issue, where port specified in mysqli::connect/mysqli_connect was ignored. A solution is to include the port directly as a part of the hostname.
Congratulations, if you have followed the instructions, you have just reached the end of this exercise.