public static function main(array $args = array())
 {
     $remoteControl = new RemoteControl();
     $light = new Light("Living Room");
     $tv = new TV("Living Room");
     $stereo = new Stereo("Living Room");
     $hottub = new Hottub();
     $lightOn = new LightOnCommand($light);
     $stereoOn = new StereoOnCommand($stereo);
     $tvOn = new TVOnCommand($tv);
     $hottubOn = new HottubOnCommand($hottub);
     $lightOff = new LightOffCommand($light);
     $stereoOff = new StereoOffCommand($stereo);
     $tvOff = new TVOffCommand($tv);
     $hottubOff = new HottubOffCommand($hottub);
     $partyOn = array($lightOn, $stereoOn, $tvOn, $hottubOn);
     $partyOff = array($lightOff, $stereoOff, $tvOff, $hottubOff);
     $partyOnMacro = new MacroCommand($partyOn);
     $partyOffMacro = new MacroCommand($partyOff);
     $remoteControl->setCommand(0, $partyOnMacro, $partyOffMacro);
     println($remoteControl);
     println("--- Pushing Macro On---");
     $remoteControl->onButtonWasPushed(0);
     println("--- Pushing Macro Off---");
     $remoteControl->offButtonWasPushed(0);
 }
Exemplo n.º 2
0
 function test_deploy($app)
 {
     print PHP_EOL . 'Starting deploy test on ' . $this->public_dns . '...' . PHP_EOL;
     $options = $app['server_options'];
     $this->run('cd ../;' . 'cp xlite/src/etc/config.php xlite/.dev/build/config.local.php;' . 'cp xlite_cms/sites/default/settings.php xlite_cms/sites/default/settings.old.php;' . 'cp xlite_cms/sites/default/default.settings.php xlite_cms/sites/default/settings.php;' . 'mkdir xlite_cms/modules/lc_connector/litecommerce;' . 'cp -r xlite/src/* xlite_cms/modules/lc_connector/litecommerce;' . 'rm xlite_cms/modules/lc_connector/litecommerce/etc/config.php;' . 'sudo chmod -R 777 .', $options);
     $code = $this->run('cd xlite/.dev; sudo ./phpunit.sh DEPLOY_DRUPAL', $options);
     RemoteControl::get_screenshots($app);
     $this->run('cd ../;' . 'sudo rm -rf xlite_cms/modules/lc_connector/litecommerce;' . 'cp xlite_cms/sites/default/settings.old.php xlite_cms/sites/default/settings.php;' . 'sudo chmod -R 777 .', $options);
     $this->setup($app);
 }
 public static function main(array $args = array())
 {
     $remoteControl = new RemoteControl();
     $livingRoomLight = new Light("Living Room");
     $kitchenLight = new Light("Kitchen");
     $ceilingFan = new CeilingFan("Living Room");
     $garageDoor = new GarageDoor("");
     $stereo = new Stereo("Living Room");
     $livingRoomLightOn = new LightOnCommand($livingRoomLight);
     $livingRoomLightOff = new LightOffCommand($livingRoomLight);
     $kitchenLightOn = new LightOnCommand($kitchenLight);
     $kitchenLightOff = new LightOffCommand($kitchenLight);
     $ceilingFanOn = new CeilingFanOnCommand($ceilingFan);
     $ceilingFanOff = new CeilingFanOffCommand($ceilingFan);
     $garageDoorUp = new GarageDoorUpCommand($garageDoor);
     $garageDoorDown = new GarageDoorDownCommand($garageDoor);
     $stereoOnWithCD = new StereoOnWithCDCommand($stereo);
     $stereoOff = new StereoOffCommand($stereo);
     $remoteControl->setCommand(0, $livingRoomLightOn, $livingRoomLightOff);
     $remoteControl->setCommand(1, $kitchenLightOn, $kitchenLightOff);
     $remoteControl->setCommand(2, $ceilingFanOn, $ceilingFanOff);
     $remoteControl->setCommand(3, $stereoOnWithCD, $stereoOff);
     println($remoteControl);
     $remoteControl->onButtonWasPushed(0);
     $remoteControl->offButtonWasPushed(0);
     $remoteControl->onButtonWasPushed(1);
     $remoteControl->offButtonWasPushed(1);
     $remoteControl->onButtonWasPushed(2);
     $remoteControl->offButtonWasPushed(2);
     $remoteControl->onButtonWasPushed(3);
     $remoteControl->offButtonWasPushed(3);
 }
Exemplo n.º 4
0
 static function boot_farms($app)
 {
     $cloud = $app['cloud'];
     for ($i = 0; $i < $app['farms_count']; $i++) {
         print PHP_EOL . "Starting a new EC2 Instance...";
         try {
             $farm = RemoteControl::boot_and_acquire_dns($app['hub_ami'], array('keypair_name' => $app['keypair_name'], 'type' => $app['grid_instance_type']));
             $cloud->farms[] = $farm;
             $cloud->save();
             print PHP_EOL . "Started new Remote Control farm at " . $farm->public_dns . PHP_EOL;
         } catch (Exception $e) {
             print PHP_EOL . "Failed to boot new Remote Control farm.";
         }
     }
     Ec2Client::authorize_port(5900);
     Ec2Client::authorize_port(6000);
 }
Exemplo n.º 5
0
    }
    public function undoButton($input)
    {
        if (isset($this->commands[$input])) {
            $this->commands[$input]->undo();
        }
    }
    public function setCommandForButton($buttonId, $cmd)
    {
        $this->commands[$buttonId] = $cmd;
    }
    public function __toString()
    {
        $str = 'Выберете вариант ниже:' . '<br />';
        foreach ($this->commands as $key => $command) {
            $str = $str . $key . ' - ' . (string) $command . '<br />';
        }
        return $str;
    }
}
$control = new RemoteControl();
$control->setCommandForButton('1', new LightsCommand(new Light()));
$control->setCommandForButton('2', new TvCommand(new Tv()));
$control->setCommandForButton('3', new MusicCommand(new Misic()));
$control->setCommandForButton('4', new TeapotCommand(new Teapot()));
echo (string) $control;
echo '<br />';
echo '<br />';
$control->pushButton('4');
echo '<br />';
$control->undoButton('4');
Exemplo n.º 6
0
require_once "devices/Light.php";
require_once "devices/GarageDoor.php";
require_once "devices/TV.php";
require_once "Command.php";
require_once "NoCommand.php";
require_once "LightOnCommand.php";
require_once "TVOffCommand.php";
require_once "TVOnCommand.php";
require_once "CloseDoorCommand.php";
require_once "OpenDoorCommand.php";
require_once "LightOffCommand.php";
require_once "RemoteControl.php";
//--------------------------------------------------------
//Создаём пульт управления
$remoteControl = new RemoteControl();
echo "<b>Start remote control.</b><hr>";
//Создаём команды для освещения
$light = new Light();
$lightOn = new LightOnCommand($light);
$lightOff = new LightOffCommand($light);
//Создаём команды для двери
$door = new GarageDoor();
$doorOpen = new OpenDoorCommand($door);
$doorClose = new CloseDoorCommand($door);
//Создаём команды для телевизора
$tv = new TV();
$tvOn = new TVOnCommand($tv);
$tvOff = new TVOffCommand($tv);
//Назначаем команды
$remoteControl->setCommand(0, $doorOpen, $doorClose);
Exemplo n.º 7
0
require_once "devices/CeilingFan.php";
require_once "Command.php";
require_once "NoCommand.php";
require_once "LightOnCommand.php";
require_once "TVOffCommand.php";
require_once "TVOnCommand.php";
require_once "MacroCommand.php";
require_once "LightOffCommand.php";
require_once "CeilingFanOffCommand.php";
require_once "CeilingFanLowCommand.php";
require_once "CeilingFanMediumCommand.php";
require_once "CeilingFanHighCommand.php";
require_once "RemoteControl.php";
//--------------------------------------------------------
//Создаём пульт управления
$remoteControl = new RemoteControl();
echo "<b>Start remote control.</b><hr>";
//Создаём команды для вентилятора
$fan = new CeilingFan("GuestRoom");
$fanHigh = new CeilingFanHighCommand($fan);
$fanOff = new CeilingFanOffCommand($fan);
//Создаём команды для освещения
$light = new Light();
$lightOn = new LightOnCommand($light);
$lightOff = new LightOffCommand($light);
//Создаём команды для телевизора
$tv = new TV();
$tvOn = new TVOnCommand($tv);
$tvOff = new TVOffCommand($tv);
//Создаём Макрокоманду - начать вечеринку
$startParty = new MacroCommand(array($fanHigh, $lightOff, $tvOn));
Exemplo n.º 8
0
    {
        $this->_television = $device;
    }
    public function execute()
    {
        $this->_television->volumeDown();
    }
}
// let's try it all out
// our application will need some reveiver object
$device = new Television();
// our application will need an invoker object, which
// in turns relies on concrete command objects:
$on = new OnCommand($device);
// command to switch device on
$off = new OffCommand($device);
// command to switch device off
$up = new UpCommand($device);
// command to turn volume up
$down = new DownCommand($device);
// command to turn volume down
// now we are ready to create our invoker object which
// we should think of as some sort of application menu.
$menu = new RemoteControl($on, $off, $up, $down);
// client code is now able to access the invoker object
$menu->switchPowerOn();
$menu->raiseVolume();
$menu->raiseVolume();
$menu->raiseVolume();
$menu->lowerVolume();
$menu->switchPowerOff();
Exemplo n.º 9
0
Arquivo: Hub.php Projeto: kingsj/core
 function shutdown()
 {
     print PHP_EOL . "Shutting down EC2 Instance " . $this->micro_farm->public_dns . "...";
     $this->micro_farm->shutdown();
     parent::shutdown();
 }
Exemplo n.º 10
0
    }
    public function off()
    {
        println('stereo off');
    }
    public function setCD()
    {
        println('put in CD');
    }
    public function setVolume($volume)
    {
        println('set volume=' . $volume);
    }
}
println();
$control1 = new RemoteControl();
#电灯
$light1 = new Light1();
$light_on_command = new LightOnCommand1($light1);
$light_off_command = new LightOffCommand1($light1);
#音响
$steteo = new Stereo();
$steteo_on_command = new StereoOnCommand($steteo);
$stereo_off_command = new StereoOffCommand($steteo);
#设置插槽控制xx
$control1->setCommand(0, $light_on_command, $light_off_command);
$control1->setCommand(1, $steteo_on_command, $stereo_off_command);
echo $control1;
$control1->bottonOnWasPressed(0);
$control1->bottonOffWasPressed(0);
echo $control1;
Exemplo n.º 11
0
<?php

include_once __DIR__ . "/remoteControl.php";
include_once __DIR__ . "/devices/light.php";
include_once __DIR__ . "/commands/lightOnCommand.php";
include_once __DIR__ . "/commands/lightOffCommand.php";
$device = new RemoteControl();
$light = new Light("Bathroom");
$lightOnCommand = new lightOnCommand($light);
$lightOffCommand = new lightOffCommand($light);
$device->setCommand(1, $lightOnCommand, $lightOffCommand);
$light = new Light("Kitchen");
$lightOnCommand = new lightOnCommand($light);
$lightOffCommand = new lightOffCommand($light);
$device->setCommand(2, $lightOnCommand, $lightOffCommand);
$device->onButtonWasPushed(1);
$device->onButtonWasPushed(2);
$device->undoButtonWasPushed();
$device->undoButtonWasPushed();
Exemplo n.º 12
0
 public function start_rc($app)
 {
     RemoteControl::boot_farms($app);
     RemoteControl::start_farms($app);
 }
Exemplo n.º 13
0
<?php

function __autoload($class_name)
{
    $parts = explode("\\", $class_name);
    require_once implode(DIRECTORY_SEPARATOR, $parts) . '.php';
}
//Simple Remote
$remote = new SimpleRemoteControl();
$light = new Machine\Light("Corridor Light");
$lightOn = new Command\LightOnCommand($light);
$remote->setCommand($lightOn);
$remote->buttonWasPressed();
//Remote Control
$re = new RemoteControl();
$livingRoom = new Machine\Light('Living Room');
$kitchenLight = new Machine\Light('Kitchen');
$ceilingFan = new Machine\CeilingFan('Living Room');
$garageDoor = new Machine\GarageDoor('Main');
$stereo = new Machine\Stereo('My Room');
$re->setCommand(0, new Command\LightOnCommand($livingRoom), new Command\LightOffCommand($livingRoom));
$re->setCommand(1, new Command\LightOnCommand($kitchenLight), new Command\LightOffCommand($kitchenLight));
$re->setCommand(2, new Command\CeilingFanHighCommand($ceilingFan), new Command\CeilingFanOffCommand($ceilingFan));
$re->setCommand(3, new Command\GarageDoorOnCommand($garageDoor), new Command\GarageDoorOffCommand($garageDoor));
$re->setCommand(4, new Command\StereoOnWithCDCommand($stereo), new Command\StereoOffCommand($stereo));
echo $re;
$re->onButtonWasPushed(0);
$re->offButtonWasPushed(0);
$re->onButtonWasPushed(1);
$re->undoButtonWasPushed();
$re->offButtonWasPushed(1);
Exemplo n.º 14
0
require_once "Command.php";
require_once "NoCommand.php";
require_once "LightOnCommand.php";
require_once "TVOffCommand.php";
require_once "TVOnCommand.php";
require_once "CloseDoorCommand.php";
require_once "OpenDoorCommand.php";
require_once "LightOffCommand.php";
require_once "CeilingFanOffCommand.php";
require_once "CeilingFanLowCommand.php";
require_once "CeilingFanMediumCommand.php";
require_once "CeilingFanHighCommand.php";
require_once "RemoteControl.php";
//--------------------------------------------------------
//Создаём пульт управления
$remoteControl = new RemoteControl();
echo "<b>Start remote control.</b><hr>";
//Создаём команды для вентилятора
$fan = new CeilingFan("GuestRoom");
$fanLow = new CeilingFanLowCommand($fan);
$fanMedium = new CeilingFanMediumCommand($fan);
$fanHigh = new CeilingFanHighCommand($fan);
$fanOff = new CeilingFanOffCommand($fan);
//Назначаем команды
$remoteControl->setCommand(0, $fanLow, $fanOff);
$remoteControl->setCommand(1, $fanMedium, $fanOff);
$remoteControl->setCommand(2, $fanHigh, $fanOff);
echo "<b>Remote control initialized.</b><hr>";
//----- тестируем пульт
echo "<b>Test remote control.</b><hr>";
echo "<i>All device online:<br></i>";
Exemplo n.º 15
0
<?php

include_once '../../class/pattern/command.php';
$remoteControl = new RemoteControl();
$car = new Car();
$carPowerOn = new PowerOnCommand($car);
$carPowerOff = new PowerOffCommand($car);
$carTurnLeft = new TurnLeftCommand($car);
$carTurnRight = new TurnRightCommand($car);
$remoteControl->setCommand(0, $carPowerOn);
// 將按鈕0號設為發動汽車引擎
$remoteControl->setCommand(1, $carPowerOff);
// 將按鈕1號設為關閉汽車引擎
$remoteControl->setCommand(2, $carTurnLeft);
// 將按鈕2號設為汽車左轉
$remoteControl->setCommand(3, $carTurnRight);
// 將按鈕3號設為汽車右轉
/*
$remoteControl->execute(0);     // 按下按鈕0號
$remoteControl->execute(1);     // 按下按鈕1號
$remoteControl->execute(2);     // 按下按鈕2號
$remoteControl->execute(3);     // 按下按鈕3號
*/
// 設定蛇行巨集, 開啟引擎、左轉、右轉、關閉引擎
$macroCmd = new MarcoCommand(array($carPowerOn, $carTurnLeft, $carTurnRight, $carPowerOff));
// 將按鈕4號設為蛇行指令
$remoteControl->setCommand(4, $macroCmd);
// 執行按鈕4號
$remoteControl->execute(4);
/*
$boat = new Boat();