示例#1
0
<?php

require_once 'output.php';
require_once 'square.php';
require_once 'cube.php';
require_once 'fourth.php';
$input = 10;
$output = new Output(new Square());
echo $output->display($input);
$output->setStrategy(new Cube());
echo $output->display($input);
$output->setStrategy(new Fourth());
echo $output->display($input);
示例#2
0
<?php

include_once 'output.php';
include_once 'square.php';
include_once 'cube.php';
include_once 'rectangle.php';
$inputA = 10;
$inputB = 20;
$output = new Output(new Square());
echo $output->display($inputA) . '<br>';
$output->setStrategy(new Cube());
echo $output->display($inputA) . '<br>';
$output->setStrategy(new Rectangle());
echo $output->display($inputA, $inputB) . '<br>';
示例#3
0
    }
    // instantiate the controller (and run its constructor)
    $class = Core::controller($class);
    // Call the remapping function if it's present in the controller
    if (method_exists($class, '_remap')) {
        call_user_func(array($class, '_remap'));
    } else {
        if (!method_exists($class, $method)) {
            Core::error404($uri);
        }
        // Call the requested method. Any URI segments present
        // (besides the controller/action) will be passed to the method for convenience
        call_user_func_array(array($class, $method), array_slice(Uri::routedsegments(), 2));
    }
    // send final output
    Output::display();
}
// -------------------------------------------------------------  Support Functions
function urlpath($url)
{
    return str_replace(URL, ROOT, $url);
}
function rmroot($path)
{
    return str_replace(ROOT, '', $path);
}
function error($msg)
{
    unlink(TMP . 'system.chk');
    die("<h1 style='color:#900'>{$msg}</h1>");
}
示例#4
0
    {
        $this->color = $color;
    }
    function setSize($size)
    {
        $this->size = $size;
    }
}
class Output
{
    var $lookandfeel;
    var $output;
    // Constructor takes LookAndFeel as its argument
    function Output($lookandfeel)
    {
        $this->lookandfeel = $lookandfeel;
    }
    function buildOutput()
    {
        $this->output = 'Color is ' . $this->lookandfeel->getColor() . ' and size is ' . $this->lookandfeel->getSize();
    }
    function display()
    {
        $this->buildOutput();
        return $this->output;
    }
}
$lookandfeel = new LookAndFeel();
$output = new Output($lookandfeel);
echo $output->display();