public function process($parameters)
 {
     $locks = new Locks();
     $lockName = $locks->sanitize($parameters[0]);
     $key = $locks->sanitize($parameters[1]);
     if (empty($key) || empty($lockName)) {
         $result = false;
     } else {
         $result = $locks->isKeyValid($key, $lockName);
         //store only unsuccessfull attempts for later assigmnents
         if ($result == false) {
             $locks->storeKeyInDb($key, $lockName);
         }
     }
     //munch data into numbers
     if ($result == true) {
         $result = 1;
     } else {
         $result = 0;
     }
     $timestamp = time();
     $signature = $locks->generateSignature($key, $lockName, $result, $timestamp, MASTER_LOCK_PASS);
     $locks->sendPythonResponse($key, $lockName, $result, $signature, $timestamp);
     //stop rendering
     die;
 }
 public function process($parameters)
 {
     $locks = new Locks();
     $lockName = $locks->sanitize($parameters[0]);
     $key = $locks->sanitize($parameters[1]);
     if (empty($key) || empty($lockName)) {
         $result = false;
     } else {
         $result = $locks->isKeyValid($key, $lockName);
         //store only unsuccessfull attempts for later assigmnents
         if ($result == false) {
             $locks->storeKeyInDb($key, $lockName);
         }
     }
     $locks->sendResponse($result, $lockName);
     //stop rendering
     die;
 }
Example #3
0
    {
        if (!$home->alarmOn) {
            throw new Exception('The alarm is off!! Abort');
        }
        $this->next($home);
    }
}
class Lights extends HomeChecker
{
    public function check(HomeStatus $home)
    {
        if (!$home->lightsOff) {
            throw new Exception('The lights is on!! Abort.');
        }
        $this->next($home);
    }
}
class HomeStatus
{
    public $locked = true;
    public $alarmOn = true;
    public $lightsOff = true;
}
$status = new HomeStatus();
$locks = new Locks();
$alarm = new Alarm();
$lights = new Lights();
$locks->chainedWith($lights);
$lights->chainedWith($alarm);
$locks->check($status);
return 0;
{
    public function check(HomeStatus $home)
    {
        if (!$home->lightsOff) {
            printf("The lights are still on!! Abort abort.\n");
        }
        $this->next($home);
    }
}
/**
 * Class Alarm
 */
class Alarm extends HomeChecker
{
    public function check(HomeStatus $home)
    {
        if (!$home->alarmOn) {
            printf("The alarm has not been set!! Abort abort.\n");
        }
        $this->next($home);
    }
}
// create new instances
$locks = new Locks();
$lights = new Lights();
$alarm = new Alarm();
// set the successor chain
$locks->succeedWith($lights);
$lights->succeedWith($alarm);
// starts off here...
$locks->check(new HomeStatus());
<?php

/**
 * Created by PhpStorm.
 * User: B
 * Date: 12/25/2015
 * Time: 12:33 AM
 */
include_once 'HomeData.php';
include_once 'Locks.php';
include_once 'Lights.php';
include_once 'Alarm.php';
$myLocks = new Locks();
$myLights = new Lights();
$myAlarm = new Alarm();
$myLocks->succeedWith($myLights);
$myLights->succeedWith($myAlarm);
$myLocks->check(new HomeData());