コード例 #1
0
ファイル: example_statusbar.php プロジェクト: bmdevel/ezc
 * @copyright Copyright (C) 2005-2010 eZ Systems AS. All rights reserved.
 * @license http://ez.no/licenses/new_bsd New BSD License
 */
require_once 'Base/src/base.php';
/**
 * Autoload ezc classes 
 * 
 * @param string $className 
 */
function __autoload($className)
{
    ezcBase::autoload($className);
}
$out = new ezcConsoleOutput();
// Create status bar itself
$status = new ezcConsoleStatusbar($out);
// Perform actions
$i = 0;
while ($i++ < 20) {
    // Do whatever you want to indicate progress for
    usleep(mt_rand(20000, 2000000));
    // Indicate success or failure
    $status->add((bool) mt_rand(0, 1));
}
$out->outputLine();
// Print statistics
$out->outputLine($status->getSuccessCount() . ' operations succeeded, ' . $status->getFailureCount() . ' failed.');
/*
OUTPUT:
+-++++-++++-++-+--+-
13 operations succeeded, 7 failed.
コード例 #2
0
 public function testAddIncorrectStatus()
 {
     $out = new ezcConsoleOutput();
     $status = new ezcConsoleStatusbar($out);
     set_error_handler(array($this, "catchWarning"), E_USER_WARNING);
     ob_start();
     $status->add("foo");
     ob_end_clean();
     restore_error_handler();
     $this->assertTrue($this->errorCaught, "Warning not caught on invalid status 'foo'.");
 }
コード例 #3
0
<?php

require_once 'tutorial_autoload.php';
$output = new ezcConsoleOutput();
$output->formats->success->color = 'green';
$output->formats->failure->color = 'red';
$options = array('successChar' => $output->formatText('+', 'success'), 'failureChar' => $output->formatText('-', 'failure'));
$status = new ezcConsoleStatusbar($output, $options);
for ($i = 0; $i < 120; $i++) {
    $nextStatus = (bool) mt_rand(0, 1);
    $status->add($nextStatus);
    usleep(mt_rand(200, 2000));
}
$output->outputLine();
$output->outputLine('Successes: ' . $status->getSuccessCount() . ', Failures: ' . $status->getFailureCount());