What you need to know:
Prepare you computer for the lab:
php composer.phar
Briefly discuss following questions.
GitLab: N/A
Use following command to initialize a project. Create an empty project with psr-4 autoloading. Do not add any dependencies.
composer init
Create "{vendor-name}\{project-name}\User\UserManager" class in "./src/User/UserManager.php" file. Add "getUsers" method to the class. The method must return an array of users, for each user return an e-mail address. Create an instance of given class in "./index.php" file. Do not manually require or include the "UserManager.php" file.
Make sure it works by running the index.php file.
The openssl extension is required for SSL/TLS protection but is not available.
If you can not enable the openssl extension, you can disable this error, at your own risk, by setting the 'disable-tls' option to true.
You need to update "php.ini" file. Uncomment "extension_dir", "extension=openssl", and "extension=zip".
You can use php "-c" option to provide path to custom php.ini file.
Explore compose.json, try to change the namespace mapping. It wont work, as the mapping is stored in the "vendor" directory. You need to run following command to regenerate the "vendor" directory.
composer update
Briefly discuss following questions.
GitLab: N/A
Continue with the previous exercise. Install PHP implementation of dependency injection (PHP-DI) using following command.
composer require php-di/php-di
Check the tutorial. Create "{vendor-name}\{project-name}\Service\Mailer" class. The "Mailer" must implement "mail" method as in the tutorial.
Inject the "Mailer" into the "UserManager". Add method "notifyUsers($content)" that will send e-mail to all users using "Mailer". Use "getUsers" method to get list of all users.
Create instance of "UserManager" using the PHP-DI and call "notifyUsers('Hello world!')".
Briefly discuss following questions.
GitLab: ./practical-01/
Continue with the previous exercise. Add Monolog into your project. Add info level log "Notifying users." into "UserManager.notifyUsers" method. Add error level log "Can not send an e-mail." with e-mail into "Mailer.mail" method.
Use WebProcessor to add information to logs.
Log all messages in the default format into "./log/application.log" file.
Log warning and higher level messages into "./log/warning.html" file using HtmlFormatter.
Try to stick with best-practices for using libraries.
Hint: Keep in mind you can always create a sandbox on your own to test something, before you integrate the functionality into the main project.
Not sure how to add processor of formatter? Refer to Using Monolog documentation.
I found the section with "config.php" file creating Monolog for PHP-DI but how do I use it?
These are PHP definitions and there is a PHP definitions documentation.
PHP Fatal error:
Uncaught UnexpectedValueException: The stream or file "\practical-01\monolog./log/application.log" could not be opened in append mode:
Failed to open stream: Permission denied
Check you have a correct path, in the example above there is extra "." (dot).
When executing your application at webik, make sure you properly set ACL. You can do that using following command:
setfacl -m u:www-data:rwx ./log/
Start PHP server using command bellow.
php -S 127.0.0.1:8090
Visit your index.php and waring.html using a browser of choice.
Deploy your application at webik to your "public_html" folder.