示例#1
0
文件: menu.php 项目: fbone/mediboard4
function task3()
{
    echo "##################################\n";
    echo "# Update and rsync Mediboard SVN #\n";
    echo "##################################\n\n";
    echo "Action to perform:\n\n";
    echo "[1] Show the update log\n";
    echo "[2] Perform the actual update\n";
    echo "[3] No update, only rsync\n";
    echo "--------------------------------\n";
    echo "[0] Return to main menu\n";
    echo "\nSelected action: ";
    $action = trim(fgets(STDIN));
    switch ($action) {
        case "1":
            $action = "info";
            break;
        case "2":
            $action = "real";
            break;
        case "3":
            $action = "noup";
            break;
        case "0":
            echo exec("clear") . "\n";
            menu();
            break;
        default:
            echo exec("clear") . "\n";
            echo "Incorrect input\n";
            task3();
    }
    echo "\nRevision number [default HEAD]: ";
    $revision = trim(fgets(STDIN));
    switch ($revision) {
        case "":
            echo shell_exec("sh " . $GLOBALS['currentDir'] . "/rsyncupdate.sh " . $action) . "\n\n";
            menu();
            break;
        default:
            echo shell_exec("sh " . $GLOBALS['currentDir'] . "/rsyncupdate.sh " . $action . " -r " . $revision) . "\n\n";
            menu();
    }
}
{
    for ($i = 1; $i <= 6; $i++) {
        $data = yield;
        echo '<p>Tâche 2, itération ' . $i . ', valeur envoyée : ' . $data . '</p>';
    }
}
function task3()
{
    for ($i = 1; $i <= 4; $i++) {
        $data = yield;
        echo '<p>Tâche 3, itération ' . $i . ', valeur envoyée : ' . $data . '</p>';
    }
}
$taskRunner->addTask(task1());
$taskRunner->addTask(task2());
$taskRunner->addTask(task3());
$taskRunner->run();
?>
  
                </p>
                
                
                <h2>La méthode throw()</h2>
                <p><strong>Lancer une exception à l'emplacement du <code>yield</code> dans le générateur - accepte un seul argument</strong></p>
                <p class="col-sm-12">
                <?php 
// Génére une fatal error - normal - une exception est lancée par PHP
//                function generator3() {
//                    echo "<p>Début</p>";
//                    yield;
//                    echo "<p>Fin</p>";