public function prepareIngredient()
    {
        echo "準備「吐司」、「生菜」、「小黃瓜」、「蛋」、「肉」\n";
    }
    // 烹煮食材
    public function cooking()
    {
        echo "將蛋及肉煎熟、生菜及小黃瓜切絲,平均放在烤好的土司上夾起來\n";
    }
    // 上菜
    public function serve()
    {
        echo "吐司對切放在盤子上即可\n";
    }
}
$sandwich = new Sandwich();
$sandwich->prepareIngredient();
$sandwich->cooking();
$sandwich->serve();
/**
 * 廚師工廠
 */
class ChefFactory
{
    /**
     * 聘請廚師
     */
    public static function hireChef($meal)
    {
        switch ($meal) {
            // 咖哩廚師
 public function __construct()
 {
     // Create a new Lunch
     $Lunch = new Sandwich();
     // Print a description of this Lunch
     print $Lunch->getDescription() . " \$" . $Lunch->price() . "\n";
     // Create another Lunch
     $Lunch2 = new Burrito();
     // Add Cheese
     $Lunch2 = new Cheese($Lunch2);
     // Add Veggies
     $Lunch2 = new Veggies($Lunch2);
     // Print a description of this Lunch
     print $Lunch2->getDescription() . " \$" . $Lunch2->price() . "\n";
     // Create a third Lunch
     $Lunch3 = new PadThai();
     // Add Tofu
     $Lunch3 = new Tofu($Lunch3);
     // Add Cheese
     $Lunch3 = new Cheese($Lunch3);
     // Add Veggies
     $Lunch3 = new Veggies($Lunch3);
     // Print a description of this Lunch
     print $Lunch3->getDescription() . " \$" . $Lunch3->price() . "\n";
 }
Example #3
0
<?php

require_once realpath(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'TRest' . DIRECTORY_SEPARATOR . 'trest_init.php');
require_once realpath(__DIR__ . DIRECTORY_SEPARATOR . 'models' . DIRECTORY_SEPARATOR . 'Sandwich.php');
require_once realpath(__DIR__ . DIRECTORY_SEPARATOR . 'models' . DIRECTORY_SEPARATOR . 'Ingredient.php');
header('Content-Type: application/json');
$id = @$_GET['id'];
$id = (int) $id;
if ($id) {
    $result = Sandwich::findOne($id);
    $result->ingredients[0]->name = 'jamon';
    $result->title = "el mio";
    $result->price = 9200;
    $result->save();
    $result = Sandwich::find()->setCacheTtl(00)->findOne($id);
} else {
    $result = Sandwich::find()->all();
}
echo json_encode($result);
Example #4
0
    {
        echo 'Ingredientes:' . "\n";
        foreach ($this->getIngredients() as $ingredient) {
            echo get_class($ingredient) . "\n";
        }
    }
    public function bite($grams)
    {
        $bite = $this->weigth - $grams;
        if ($bite > 0) {
            $this->setWeigth($bite);
        } else {
            $this->setWeigth(0);
        }
        return $grams;
    }
}
$snd = new Sandwich($ingredients = null, $breadType = 'Miga');
echo 'Sandwich Basico' . "\n";
$snd->getDescription();
$snd->addIngredient('Butter');
$snd->addIngredient('Cheese');
$snd->addIngredient('RawHam');
echo 'Sandwich Con Tres Ingredientes' . "\n";
$snd->getDescription();
echo 'Luego de una mordida de 30 gr' . "\n";
$snd->bite(30);
$snd->getDescription();
echo 'Luego de una mordida de 50 gr' . "\n";
$snd->bite(50);
$snd->getDescription();