SENIOR PHP DEVELOPER TASK DESCRIPTION
Solution:
- used
Composer
for auto loading classes - used
Docker
for 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.php
accept 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_title
php function.MCP
- execute WorkerCheckStatus which looking for the process by process title with the help of system commandpidof
and according to the search result shows related message. -
##How to test
- using docker
- start php_cli container by executing
start.sh
from the project root - then from the
public
folder executeprocess
script which runindex.php
though 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.php
with php cli.
examples:
# php index.php thread hello
# php index.php MCP hello
- using docker
-
##How to test
open in the browser
js.html
located in thepublic
folder. -
##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
t
key. - 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
=radio
button orcheck
box thenv
alue not a single string but set ofname:checked_flag
0
= not checked
1
= checked - if JSON is reliable i suppose that if
v
alue is set of data then it isradio
button orcheck
box 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.