Example #1
0
 public function goToHome(Vehicle $vehicle)
 {
     while ($this->currentPosition != $this->brain->locate($vehicle)) {
         if (is_null($this->currentForwardLeg)) {
             $this->rightLeg->moveForward();
             $this->currentForwardLeg = $this->rightLeg;
             $this->currentPosition++;
             break;
         } elseif ($this->currentForwardLeg === $this->rightLeg) {
             $this->leftLeg->moveForward();
             $this->currentForwardLeg = $this->leftLeg;
             $this->currentPosition++;
             break;
         } else {
             $this->rightLeg->moveForward();
             $this->currentForwardLeg = $this->rightLeg;
             $this->currentPosition++;
             break;
         }
     }
     //Now we can get in to the vehicle
     if ($vehicle instanceof VehicleWithDoor) {
         $vehicle->openDoor();
     }
     //This is supposedly takes us in the vehicle
     //We already know the $this->currentForwardLeg is not null
     if ($this->currentForwardLeg === $this->rightLeg) {
         $this->leftLeg->moveForward();
         $this->currentForwardLeg = $this->leftLeg;
         $this->currentPosition++;
     } else {
         $this->rightLeg->moveForward();
         $this->currentForwardLeg = $this->rightLeg;
         $this->currentPosition++;
     }
     if ($vehicle instanceof VehicleWithDoor) {
         $vehicle->closeDoor();
     }
     $vehicle->driveTo(HOME_POSITION, function (Vehicle $vehicle, $position) {
         $this->currentPosition = $position;
         //Now we can get in to the vehicle
         if ($vehicle instanceof VehicleWithDoor) {
             $vehicle->openDoor();
         }
         //Go out of the vehicle
         if ($this->currentForwardLeg === $this->rightLeg) {
             $this->leftLeg->moveForward();
             $this->currentForwardLeg = $this->leftLeg;
             $this->currentPosition++;
         } else {
             $this->rightLeg->moveForward();
             $this->currentForwardLeg = $this->rightLeg;
             $this->currentPosition++;
         }
     });
 }
 public static function totalScaleMoodTypeAndFeeling($moodTypeID, $feelingID)
 {
     $brain = Brain::getInstance();
     $result = $brain->think("SELECT sum(scale) FROM " . self::$area . " WHERE mood_type_id = {$moodTypeID} AND feeling_id = {$feelingID}");
     $row = mysqli_fetch_row($result);
     return $row[0];
 }
 public static function getInstance()
 {
     if (!self::$singleDB) {
         self::$singleDB = new Brain();
     }
     return self::$singleDB;
 }
 function test1()
 {
     $brain = new Brain();
     $this->assertEquals('mr cool', $brain->load('name'));
 }
 public static function moodTypeIDArray()
 {
     $brain = Brain::getInstance();
     return $brain->selectArray("id", "SELECT id FROM mood_types ORDER BY name");
 }
 public static function mostCommonFeelingID()
 {
     $brain = Brain::getInstance();
     return $brain->selectWhere("id", self::$area, "id > 0", " ORDER BY count DESC LIMIT 0,1");
 }
Example #7
0
<?php

require_once __DIR__ . '/../vendor/autoload.php';
use MartinLindhe\Traits\DiskCacheTrait;
class Brain
{
    use DiskCacheTrait;
    public function __construct()
    {
        $this->cacheTtlSeconds(1);
        $this->store('name', 'mr cool');
    }
}
$brain = new Brain();
$res = $brain->load('name');
nfo("got " . $res);
sleep(2);
$res = $brain->load('name');
nfo("got " . $res);