SENIOR PHP DEVELOPER TASK DESCRIPTION
Solution:
- used
Composerfor auto loading classes - used
Dockerfor the php-cli container
-
##Folder structure
- app - main directory with the application sources
- Classes - directory with the application classes
- Commands - directory with the classes related to the
Command Pattern - Workers - directory with the classes which do some "job"
- Commands - directory with the classes related to the
- Interfaces - directory with the interfaces
- Resources - directory with the language/message files
- public
directory for the user/client related files - vendor
composer directory to store packages
-
##How it works
public/index.phpaccept 2 cli parameters:
a) command - available 2 commands: "thread" and "MCP"
b) process name - any varchar namethese 2 parameters transferred to the factory and depending on the command will be executed one of workers:
thread- execute WorkerLoop which will do 5 loops with the 60 secs pause.
When WorkerLoop start doing his job it sets the process title with the help ofcli_set_process_titlephp function.MCP- execute WorkerCheckStatus which looking for the process by process title with the help of system commandpidofand according to the search result shows related message. -
##How to test
- using docker
- start php_cli container by executing
start.shfrom the project root - then from the
publicfolder executeprocessscript which runindex.phpthough docker container and give it two params - command and process name described above
examples:
# ./process thread hello
# ./process MCP hello
- start php_cli container by executing
- using pure php
all you need just runindex.phpwith php cli.
examples:
# php index.php thread hello
# php index.php MCP hello
- using docker
-
##How to test
open in the browser
js.htmllocated in thepublicfolder. -
##Description
- I decided to create a class for each form element
- used kind of Value object for the form elements' attributes to keep persistence of received data so objects can rely on the data.
- Factory return form elements depending on the JSON
tkey. - depending on the JSON number of data sets will be drown appropriate number of buttons
- each dynamically created button assigned action to dynamically generate form elements and fill them with the data depending on JSON data format and values.
- JSON format:
t- type
v- value
ift=radiobutton orcheckbox thenvalue not a single string but set ofname:checked_flag
0= not checked
1= checked - if JSON is reliable i suppose that if
value is set of data then it isradiobutton orcheckbox so im just checking it for theinstanceof Object.
if JSON not reliable i would check every key and value if needed. in the task description not clarified if data is reliable or not.