Implementation of Registry Functionalities
Learn about the implementation of different functions written in the actions.php file for our phonebook registry.
Registry functions in actions.php
It’s impossible to complete the application without factoring in the registry-related functionalities that correspond to the other more sophisticated patterns in the table, that is, interaction with a registry and, therefore, the filesystem. Working with a flat-file registry, or any file for that matter, means that many of the actions performed on the said entity are some variation of read and write operations, or sometimes a mix of both.
Read and write are impure operations, much like printing to a standard output device (a console) and, as such, warrant the usage of the IO monad. The mostly empty bodies of the functions defined in the snippet below are imperative to realizing a fully functioning phonebook.
<?phpfunction writeRegistry(callable $action): IO{// write changes to registry}function create(string $name, string $phone): IO{// create a contact}function delete(string $name): IO{// delete a contact}function search(string $search): IO{// search registry}function readRegistry(): IO{// read registry contents}function registry(): string{return f\filePath(0, REGISTRY_FILE);}
The readRegistry
and writeRegistry
functions are especially useful. The former makes it possible to read from the registry, and the ...