public function test_it_throws_exception_if_context_fails_to_resolve()
 {
     $this->setExpectedException('StateMachine\\Exceptions\\ContextNotResolvable');
     $light = new Light();
     $light->context = "InvalidLightContext";
     $light->flipSwitch();
     $this->assertInstanceOf('StateMachine\\AnotherLightContext', $light->context);
 }
Beispiel #2
0
function light_notification($call = true)
{
    $lights = Light::allLights();
    $pattern = $lights->isOn();
    if ($call) {
        $number = 2;
    } else {
        $number = 3;
    }
    for ($i = 0; $i < $number; $i++) {
        $lights->on(true);
        sleep(1);
        $lights->on(false);
        sleep(1);
    }
    $lights->status($pattern);
}
}


//猪八戒类

class Pig{
	public function display(){
		echo '猪八戒下凡,哼哼坠地! <br/>';
	}
}

//main

//打开蓝灯
$light = new Light();
$blueglass = new BlueGlass();
$light->TrunOn($blueglass);


//打开绿灯
$greenglass = new GreenGlass();
$light->TrunOn($greenglass);

//坏了猪八戒从手电筒里面出生了, 现在做了类型限制

$pig = new Pig(); 
$light->TrunOn($pig);  //Catchable fatal error: Argument 1 passed to Light::TrunOn() must be an instance of BlueGlass

/****
如果按PHP本身特点,不检测类型,
}


//猪八戒类

class Pig{
	public function display(){
		echo '猪八戒下凡,哼哼坠地! <br/>';
	}
}

//main

//打开红灯
$light = new Light();
$redglass = new RedGlass();
$light->TrunOn($redglass);


//打开绿灯
$greenglass = new GreenGlass();
$light->TrunOn($greenglass);


//坏了猪八戒从手电筒里面出生了

$pig = new Pig();
$light->TrunOn($pig);
/*****
分析 与java那段出错程序相比
 public function undo()
 {
     $this->light->off();
 }
 public function execute()
 {
     $this->light->on();
 }
Beispiel #7
0
class Glass
{
}
class redGlass extends Glass
{
    public function display()
    {
        echo "发射红光<br/>";
    }
}
class blueGlass extends Glass
{
    public function display()
    {
        echo "发射蓝光<br/>";
    }
}
class Pig
{
    public function display()
    {
        echo "猪八戒<br/>";
    }
}
$light = new Light();
$red = new redGlass();
$blue = new blueGlass();
$pig = new Pig();
$light->ons($red);
$light->ons($blue);
//$light->ons($pig);
 public function undo()
 {
     $this->light->dim($this->prevLevel);
 }
function PageContent()
{
    ?>
    
            <div class="layout center-flex">

                <?php 
    $aLabels = array();
    $aLinks = array();
    $aLabels[0] = 'Home';
    $aLinks[0] = 'mainpage.php';
    $aLabels[1] = 'Category List';
    $aLinks[1] = 'category_list.php';
    $aLabels[2] = 'Light';
    $aLinks[2] = '';
    echo Helpers::CreateBreadCrumbs($aLabels, $aLinks);
    ?>

                <div class="bigbotspace flex-container space-between">
                    <p class="larger auto heading">Light</p>
                    <!--
                    <a href="category_admin.php" class="button_link"><button class="">Add New Light</button></a>
                    -->
                </div>
            </div>
    
            <div class="layout">
    
                <table class="tablestyle" id="list_table">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>Overview Text</th>
                            <th>Images</th>
                            <th>Tests</th>
                            <th class="mid">Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php 
    $objLight = new Light();
    $oLight = $objLight->GetAllLightByCategoryId($_REQUEST['cat']);
    $objLightImage = new LightImage();
    $objLightTest = new LightTest();
    foreach ($oLight as $light) {
        echo '<tr id="img_' . $light->Id . '">' . PHP_EOL;
        echo '<td>' . $light->Id . '</td>' . PHP_EOL;
        echo '<td>' . substr($light->OverviewText, 0, 200) . '</td>' . PHP_EOL;
        echo '<td>(<a href="lightimage_list.php?cat=' . $_REQUEST['cat'] . '&light=' . $light->Id . '">' . $objLightImage->getCountLightImageByLightId($light->Id) . '</a>)</td>' . PHP_EOL;
        echo '<td>(<a href="lighttest_list.php?cat=' . $_REQUEST['cat'] . '&light=' . $light->Id . '">' . $objLightTest->getCountLightTestByLightId($light->Id) . '</a>)</td>' . PHP_EOL;
        echo '<td class="mid"><a href="light_admin.php?cat=' . $_REQUEST['cat'] . '&id=' . $light->Id . '"><img src="img/edit-icon.png" /></a></td>' . PHP_EOL;
        echo '</tr>' . PHP_EOL;
    }
    ?>
                    </tbody>
                </table>
    
            </div> <!-- layout -->
    
<?php 
}
Beispiel #10
0
 public function untilAge($name, $closure, $max, $args = [])
 {
     $row = Light::Until()->firstOrCreate(['name' => $name]);
     $when = $row->when;
     $value = $row->value;
     if ($when && $value) {
         $age = time() - (int) $when;
         if ($age > $max) {
             $data = call_user_func_array($closure, $args);
             $row->setWhen(time())->setValue(serialize($data))->save();
         } else {
             return unserialize($value);
         }
     }
     $data = call_user_func_array($closure, $args);
     $row->setWhen(time())->setValue(serialize($data))->save();
     return $data;
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = Light::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Beispiel #12
0
 public function say(Light $l)
 {
     //强制类型为Light类的
     echo $l->getColor();
     echo '<br/>';
 }
<?php

session_start();
if (!isset($_SESSION['sessCategory'])) {
    header('Location: index.php');
    exit;
}
include_once 'inc/classes/Light.php';
include_once 'inc/classes/LightImage.php';
include_once 'inc/classes/LightTest.php';
include_once 'inc/classes/Technology.php';
include_once 'inc/classes/Category.php';
$objLight = new Light();
$oLight = $objLight->getAllLightByCategoryId($_SESSION['sessCategory']);
$objTechnology = new Technology(3);
$objLightImage = new LightImage();
$oLightImage = $objLightImage->getAllLightImageByLightId($oLight[0]->Id);
$objLightTest = new LightTest();
$oLightTest = $objLightTest->getAllLightTestByLightId($oLight[0]->Id);
$objCategory = new Category($_SESSION['sessCategory']);
$bgcolor = "#F40000";
// Coke red default
if ($objCategory->BackgroundColor != "") {
    $bgcolor = $objCategory->BackgroundColor;
}
$background = $bgcolor . " none repeat scroll 0% 0%";
// this is used in single-product-template.php
?>
<!DOCTYPE html>
<html lang="en">
<head>
if ($_POST['commit'] == "Cancel") {
    header("Location:light_list.php?cat=" . $_REQUEST['cat']);
    exit;
}
if ($_POST['commit'] == "Save Light") {
    if ($id == 0) {
        // insert
        $obj = new Light();
        $obj->OverviewText = $_REQUEST["overview_text"];
        $obj->create();
        // redirect to listing list
        header("Location:light_list.php?cat=" . $_REQUEST['cat']);
        exit;
    } else {
        // update
        $obj = new Light($_REQUEST["id"]);
        $obj->OverviewText = $_REQUEST["overview_text"];
        $obj->update();
        // redirect to listing list
        header("Location:light_list.php?cat=" . $_REQUEST['cat']);
        exit;
    }
} else {
    if ($_REQUEST['mode'] == 'e') {
        //listing
        $objLight = new Light($id);
        $overview_text = $objLight->OverviewText;
    }
}
include "includes/pagetemplate.php";
function PageContent()