Example #1
0
 /**
  * Displays report or generates its files
  *
  * @param PHP_ConfigReport_Report $report Report
  * @return void
  */
 public function render(PHP_ConfigReport_Report $report)
 {
     $consoleOutput = new ezcConsoleOutput();
     $consoleOutput->formats->extensionName->style = array('bold');
     $consoleOutput->formats->columnTitle->style = array('bold');
     $consoleOutput->formats->error->bgcolor = 'red';
     $consoleOutput->formats->warning->bgcolor = 'yellow';
     $consoleOutput->outputLine('PHP version: ' . $report->getPhpVersion());
     $consoleOutput->outputLine('Environment: ' . $report->getEnvironment());
     $noIssue = true;
     foreach ($report->getSections() as $section) {
         if ($section->hasIssues()) {
             $noIssue = false;
             $consoleOutput->outputLine();
             $consoleOutput->outputLine($section->getExtensionName(), 'extensionName');
             $table = new ezcConsoleTable($consoleOutput, $this->_width);
             $table[0]->format = 'columnTitle';
             $table[0][0]->content = 'Directive';
             $table[0][1]->content = 'Level';
             $table[0][2]->content = 'Type';
             $table[0][3]->content = 'Value';
             $table[0][4]->content = 'Suggested value';
             $table[0][5]->content = 'Comments';
             foreach ($section->getIssues() as $index => $issue) {
                 $table[$index + 1]->format = $issue->getLevel();
                 $directiveName = $issue->getDirectiveName();
                 if (is_array($directiveName)) {
                     $directiveName = implode(' / ', $directiveName);
                 }
                 $table[$index + 1][0]->content = $directiveName;
                 $table[$index + 1][1]->content = $issue->getLevel();
                 $table[$index + 1][2]->content = $issue->getType();
                 $directiveActualValue = $issue->getDirectiveActualValue();
                 if (is_array($directiveActualValue)) {
                     $directiveActualValue = implode(' / ', $directiveActualValue);
                 }
                 $table[$index + 1][3]->content = $directiveActualValue;
                 $directiveSuggestedValue = $issue->getDirectiveSuggestedValue();
                 if (is_array($directiveSuggestedValue)) {
                     $directiveSuggestedValue = implode(' / ', $directiveSuggestedValue);
                 }
                 $table[$index + 1][4]->content = $directiveSuggestedValue;
                 $table[$index + 1][5]->content = $issue->getComments();
             }
             $table->outputTable();
             $consoleOutput->outputLine();
         }
     }
     if ($noIssue) {
         $consoleOutput->outputLine('No issue found.');
         $consoleOutput->outputLine();
     }
 }
Example #2
0
 /**
  * Prints the message of an occured error and exits the program.
  * This method is used to print an error message, as soon as an error
  * occurs end quit the program with return code -1. Optionally, the
  * method will trigger the help text to be printed after the error message.
  *
  * @param string $message The error message to print
  * @param bool $printHelp Whether to print the help after the error msg.
  */
 private function raiseError($message, $printHelp = false)
 {
     $this->output->outputLine($message, 'error');
     $this->output->outputLine();
     if ($printHelp === true) {
         $this->output->outputText($this->input->getHelpText(self::PROGRAM_DESCRIPTION), "help");
     }
     exit(-1);
 }
Example #3
0
 /**
  * Prints the message of an occured error and exits the program.
  * This method is used to print an error message, as soon as an error
  * occurs end quit the program with return code -1. Optionally, the
  * method will trigger the help text to be printed after the error message.
  * 
  * @param string $message The error message to print
  * @param bool $printHelp Whether to print the help after the error msg.
  */
 private function raiseError($message, $printHelp = false)
 {
     $this->output->outputLine($message, 'error');
     $this->output->outputLine();
     if ($printHelp === true) {
         $this->output->outputText($this->input->getHelpText(ezcPersistentObjectSchemaGenerator::PROGRAM_DESCRIPTION), "help");
     }
     exit(-1);
 }
Example #4
0
<?php

/**
 * @package JetFuelCore
 */
require_once 'core/common.php';
$output = new ezcConsoleOutput();
$output->formats->info->color = 'blue';
// create a database schema from a database connection:
$db = ezcDbFactory::create(DB_DSN);
$dbSchema = ezcDbSchema::createFromDb($db);
// save a database schema to an XML file:
$dbSchema->writeToFile('xml', 'saved-schema.xml');
$messages = ezcDbSchemaValidator::validate($dbSchema);
foreach ($messages as $message) {
    $output->outputLine($message, 'info');
}
$readerClass = ezcDbSchemaHandlerManager::getReaderByFormat('xml');
$reader = new $readerClass();
$schema = ezcDbSchema::createFromFile('xml', 'saved-schema.xml');
$writer = new ezcDbSchemaPersistentWriter(true, null);
$writer->saveToFile('app/model/definitions', $schema);
$output->outputLine("Class files successfully written to app/model/definitions.", 'info');
<?php

require_once 'tutorial_autoload.php';
$output = new ezcConsoleOutput();
$output->formats->error->color = 'red';
$output->formats->error->style = array('bold');
$output->formats->error->target = ezcConsoleOutput::TARGET_STDERR;
$output->outputLine('Unable to connect to database', 'error');
 /**
  * Print a status entry.
  * Prints a new status entry to the console and updates the internal counter.
  *
  * @param string $tag  The tag to print (second argument in the 
  *                     formatString).
  * @param string $data The data to be printed in the status entry (third 
  *                     argument in the format string).
  * @return void
  */
 public function addEntry($tag, $data)
 {
     $this->counter++;
     $percentage = $this->counter / $this->max * 100;
     $this->outputHandler->outputLine(sprintf($this->options['formatString'], $percentage, $tag, $data));
 }
Example #7
0
 /**
  * Displays version informations
  *
  * @return void
  */
 public static function displayVersion()
 {
     self::$consoleOutput->outputLine('vcsstats 0.1-dev by Jean-Marc Fontaine', 'version');
 }
/**
 * Autoload ezc classes 
 * 
 * @param string $className 
 */
function __autoload($className)
{
    ezcBase::autoload($className);
}
$out = new ezcConsoleOutput();
// Create a progress monitor
$status = new ezcConsoleProgressMonitor($out, 7);
// Perform actions
$i = 0;
while ($i++ < 7) {
    // Do whatever you want to indicate progress for
    usleep(mt_rand(20000, 2000000));
    // Advance the statusbar by one step
    $status->addEntry('ACTION', "Performed action #{$i}.");
}
$out->outputLine();
/*
OUTPUT:
    14.3% ACTION Performed action #1.
    28.6% ACTION Performed action #2.
    42.9% ACTION Performed action #3.
    57.1% ACTION Performed action #4.
    71.4% ACTION Performed action #5.
    85.7% ACTION Performed action #6.
   100.0% ACTION Performed action #7.
*/
<?php

require_once 'tutorial_autoload.php';
$output = new ezcConsoleOutput();
$output->formats->info->color = 'blue';
$output->formats->error->color = 'red';
$output->formats->error->style = array('bold');
$output->formats->fatal->color = 'red';
$output->formats->fatal->style = array('bold', 'underlined');
$output->formats->fatal->bgcolor = 'black';
$output->outputText('This is some standard text ');
$output->outputText('including some error', 'error');
$output->outputText(' wrapped in standard text.');
$output->outputText("\n");
$output->outputLine('This is a fatal error message.', 'fatal');
$output->outputText('Test');
Example #10
0
$input->argumentDefinition[0]->shorthelp = "The artist to search for";
$output = new ezcConsoleOutput();
$output->formats->info->color = 'blue';
$output->formats->error->color = 'red';
$output->formats->error->style = array('bold');
$output->formats->fatal->color = 'red';
$output->formats->fatal->style = array('bold', 'underlined');
$output->formats->fatal->bgcolor = 'black';
try {
    $input->process();
} catch (ezcConsoleArgumentMandatoryViolationException $e) {
    if ($helpOption->value === true) {
        $output->outputText($input->getHelpText("Auto-link by artist name"));
        exit;
    } else {
        $output->outputLine("No arguments given", "fatal");
        $output->outputText($input->getHelpText("Auto-link by artist name"));
        exit(1);
    }
} catch (ezcConsoleException $e) {
    die($e->getMessage());
}
if ($input->argumentDefinition["artist"]->value === null) {
    $output->outputLine("The <artist> argument is mandatory", 'fatal');
    $output->outputText($input->getHelpText("Auto-link by artist name"), 'fatal');
    exit;
}
var_dump($verboseOption->value);
$it = new FOFSongIterator('/home/xbmc/fof/songs/Packs');
$it->addFilter('artist', $input->argumentDefinition["artist"]->value);
foreach ($it as $song) {
Example #11
0
}
$input = new ezcConsoleInput();
$output = new ezcConsoleOutput();
$helpOption = $input->registerOption(new ezcConsoleOption('h', 'help'));
$helpOption->isHelpOption = true;
$helpOption->shorthelp = 'Display current help information.';
$extensionOption = $input->registerOption(new ezcConsoleOption('e', 'extension', ezcConsoleInput::TYPE_STRING));
$extensionOption->mandatory = true;
$extensionOption->shorthelp = 'Full path to the eZ Publish extension e.g \'/home/ls/public_html/ezp/extension/myextension\'';
$extensionNameOption = $input->registerOption(new ezcConsoleOption('n', 'extension-name', ezcConsoleInput::TYPE_STRING));
$extensionNameOption->mandatory = true;
$extensionNameOption->shorthelp = 'Extension name. e.g \'myextension\'';
try {
    $input->process();
} catch (ezcConsoleOptionException $e) {
    $output->outputLine($e->getMessage());
    exit;
}
if ($helpOption->value === true) {
    $output->outputText($input->getHelpText('This script generate an XML definition for eZ Publish extension package type.'));
    exit;
}
$sourceDir = $extensionOption->value;
$extensionName = $extensionNameOption->value;
$fileList = array();
recursiveList($sourceDir, '', $fileList);
$doc = new DOMDocument('1.0', 'utf-8');
$doc->formatOutput = true;
$packageRoot = $doc->createElement('extension');
$packageRoot->setAttribute('name', $extensionName);
foreach ($fileList as $file) {
<?php

require_once 'tutorial_autoload.php';
$output = new ezcConsoleOutput();
$output->formats->info->color = 'blue';
$output->formats->info->style = array('bold');
$output->setOptions(array('autobreak' => 78, 'verbosityLevel' => 3));
$output->outputLine('This is a very very long info text. It has so much information in ' . 'it, that it will definitly not fit into 1 line. Therefore, ' . 'ezcConsoleOutput will automatically wrap the line for us.', 'info');
$output->outputLine();
$output->outputLine('This verbose information will currently not be displayed.', 'info', 10);
$output->outputLine('But this verbose information will be displayed.', 'info', 2);
<?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());
Example #14
0
$helpOpt->isHelpOption = true;
$helpOpt->shorthelp = 'Print help information.';
$helpOpt->longhelp = 'Display this help information about the program.';
$suiteOpt = $in->registerOption(new ezcConsoleOption('s', 'suite', ezcConsoleInput::TYPE_STRING, '*'));
$suiteOpt->shorthelp = 'Path pattern defining the client test suites to display data for.';
$suiteOpt->longhelp = 'This option may contain a path pattern as understood by glob(), defining the client test suites to display data for. An example would be "rfc" to only see the rfc tests or "r*" to see all suites starting with "r".';
$testOpt = $in->registerOption(new ezcConsoleOption('t', 'test', ezcConsoleInput::TYPE_STRING, '*'));
$testOpt->shorthelp = 'Path pattern defining the test cases to display data for.';
$testOpt->longhelp = 'This option may contain a path pattern as understood by glob(), defining the test cases to display data for. An example would be "get_*" to only see all test cases that start with "get_".';
$noColorOpt = $in->registerOption(new ezcConsoleOption('n', 'no-color'));
$noColorOpt->shorthelp = 'Switch of use of format codes (for logging).';
$noColorOpt->longhelp = 'Switches of the use of shell formatting codes, like color and style. This is particularly useful if you want to log the generated output.';
try {
    $in->process();
} catch (ezcConsoleException $e) {
    $out->outputLine($e->getMessage(), 'error');
    $out->outputLine($in->getHelpText('Webdav client test viewer'), 'error');
    exit(-1);
}
if ($helpOpt->value === true) {
    $out->outputLine($in->getHelpText('Webdav client test viewer', 80, true));
    exit(0);
}
if ($noColorOpt->value === true) {
    $out->options->useFormats = false;
}
$suites = glob(dirname(__FILE__) . "/../clients/{$suiteOpt->value}", GLOB_ONLYDIR);
foreach ($suites as $suite) {
    $tests = glob("{$suite}/{$testOpt->value}", GLOB_ONLYDIR);
    foreach ($tests as $test) {
        $requestInfos = loadFiles(glob("{$test}/request/*"));
Example #15
0
#!/usr/bin/php
<?php 
include 'lib/autoload.php';
$out = new ezcConsoleOutput();
try {
    $song = new FOFSong(getcwd());
} catch (Exception $e) {
    echo "Exception: " . $e->getMessage() . "\n";
    exit(1);
}
$out->outputLine($song->name . " by " . $song->artist);
$out->outputLine("Played count: {$song->count}");
$out->outputLine();
$out->outputLine("Scores: ");
foreach (array('easy', 'medium', 'hard', 'amazing') as $difficulty) {
    if (isset($song->scores->{$difficulty})) {
        $scores = $song->scores->{$difficulty};
        $out->outputLine("* " . $scores->difficultyName);
        foreach ($scores->scores as $idx => $score) {
            $rank = $idx + 1;
            $out->outputLine("{$rank}. {$score->player}: {$score->score} ({$score->stars}*, {$score->percentage}% - {$score->notesOk}/{$score->notesTotal})");
        }
    }
}
Example #16
0
 /**
  * Generate table output
  *
  * @param VcsStats_Table $table Table
  * @return void
  */
 public function renderTable(VcsStats_Report_Element_Table $table)
 {
     $result = '';
     $output = new ezcConsoleOutput();
     $output->formats->title->style = array('bold');
     $alignments = array('center' => ezcConsoleTable::ALIGN_CENTER, 'left' => ezcConsoleTable::ALIGN_LEFT, 'right' => ezcConsoleTable::ALIGN_RIGHT);
     $consoleTable = new ezcConsoleTable($output, 78);
     // Display header
     $consoleTable[0]->align = ezcConsoleTable::ALIGN_CENTER;
     foreach ($table->getColumns() as $column) {
         $consoleTable[0][]->content = $column->getTitle();
     }
     // Display values
     foreach ($table->getRows() as $i => $row) {
         $j = 0;
         foreach ($row as $code => $value) {
             $alignment = $table->getColumn($code)->getAlignment();
             $consoleTable[$i + 1][$j]->align = $alignments[$alignment];
             $consoleTable[$i + 1][$j]->content = $value;
             $j++;
         }
     }
     ob_start();
     $output->outputLine();
     $output->outputLine($table->getTitle(), 'title');
     $consoleTable->outputTable();
     $output->outputLine();
     $output->outputLine();
     $result .= ob_get_clean();
     echo $result;
 }
<?php

require_once 'tutorial_autoload.php';
$data = array(array('Name', 'Nationality', 'Birthday'), array('Derick Rethans', 'Dutch', '1978-12-22'), array('Frederik Holljen', 'Canadian / Norwegian', '1978-11-15'), array('Jan Borsodi', 'Norwegian', '1977-10-13'), array('Raymond Bosman', 'Dutch', '1979-07-24'), array('Tobias Schlitt', 'German', '1980-05-19'));
$output = new ezcConsoleOutput();
$output->formats->headBorder->color = 'blue';
$output->formats->normalBorder->color = 'gray';
$output->formats->headContent->color = 'blue';
$output->formats->headContent->style = array('bold');
$table = new ezcConsoleTable($output, 78);
$table->options->defaultBorderFormat = 'normalBorder';
$table[0]->borderFormat = 'headBorder';
$table[0]->format = 'headContent';
$table[0]->align = ezcConsoleTable::ALIGN_CENTER;
foreach ($data as $row => $cells) {
    foreach ($cells as $cell) {
        $table[$row][]->content = $cell;
    }
}
$output->outputLine('eZ components team:');
$table->outputTable();
$output->outputLine();
Example #18
0
 /**
  * Returns the instance of the class
  *
  * @param boolean $isCliMode
  * @return CjwNewsletterLog
  */
 public static function getInstance($isCliMode = false)
 {
     try {
         if (is_null(self::$instance)) {
             self::$instance = new self($isCliMode);
             ezcBaseInit::fetchConfig('cjwNewsletterInitLog', self::$instance);
         }
         return self::$instance;
     } catch (ezcBaseFilePermissionException $e) {
         eZDebug::writeError($e->getMessage(), 'CjwNewsletterLog::getInstance()');
         if ($isCliMode) {
             $output = new ezcConsoleOutput();
             $output->formats->error->color = 'red';
             $output->formats->error->style = array('bold');
             $output->outputLine($e->getMessage(), 'error');
             exit;
         }
     }
 }
 /**
  * Clears view cache for imported content objects.
  * ObjectIDs are stored in 'ezpending_actions' table, with {@link SQLIContent::ACTION_CLEAR_CACHE} action
  */
 public static function viewCacheClear()
 {
     $db = eZDB::instance();
     $isCli = isset($_SERVER['argv']);
     $output = null;
     $progressBar = null;
     $i = 0;
     $conds = array('action' => SQLIContent::ACTION_CLEAR_CACHE);
     $limit = array('offset' => 0, 'length' => 50);
     $count = (int) eZPersistentObject::count(eZPendingActions::definition(), $conds);
     if ($isCli && $count > 0) {
         // Progress bar implementation
         $output = new ezcConsoleOutput();
         $output->outputLine('Starting to clear view cache for imported objects...');
         $progressBarOptions = array('emptyChar' => ' ', 'barChar' => '=');
         $progressBar = new ezcConsoleProgressbar($output, $count, $progressBarOptions);
         $progressBar->start();
     }
     /*
      * To avoid fatal errors due to memory exhaustion, pending actions are fetched by packets
      */
     do {
         $aObjectsToClear = eZPendingActions::fetchObjectList(eZPendingActions::definition(), null, $conds, null, $limit);
         $jMax = count($aObjectsToClear);
         if ($jMax > 0) {
             for ($j = 0; $j < $jMax; ++$j) {
                 if ($isCli) {
                     $progressBar->advance();
                 }
                 $db->begin();
                 eZContentCacheManager::clearContentCacheIfNeeded((int) $aObjectsToClear[$j]->attribute('param'));
                 $aObjectsToClear[$j]->remove();
                 $db->commit();
                 $i++;
             }
         }
         unset($aObjectsToClear);
         eZContentObject::clearCache();
         if (eZINI::instance('site.ini')->variable('ContentSettings', 'StaticCache') == 'enabled') {
             $optionArray = array('iniFile' => 'site.ini', 'iniSection' => 'ContentSettings', 'iniVariable' => 'StaticCacheHandler');
             $options = new ezpExtensionOptions($optionArray);
             $staticCacheHandler = eZExtension::getHandlerClass($options);
             $staticCacheHandler::executeActions();
         }
     } while ($i < $count);
     if ($isCli && $count > 0) {
         $progressBar->finish();
         $output->outputLine();
     }
 }
                                     'use-extensions' => true ) );

$script->startup();

$options = $script->getOptions( "[n]",
                                "",
                                array( 'n' => 'Do not wait the 10 safety seconds before starting' ) );
$script->initialize();

$output = new ezcConsoleOutput();
$output->formats->error->style = array( 'bold' );
$output->formats->error->color = 'red';

if ( !isset( $options['n'] ) )
{
    $output->outputLine( 'This script will delete images that look orphan' );
    $output->outputLine( 'Press ctrl-c in the next 10 seconds to prevent the script from starting...' );
    sleep( 10 );
}

try
{
    $output->outputLine( 'Looking for obsolete image files...' );

    // Fetch all image files in ezimagefile table
    $aImageFiles = eZPersistentObject::fetchObjectList( eZImageFile::definition() );
    $nbImageFiles = count( $aImageFiles );

    if( $nbImageFiles > 0 )
    {
        // Progress bar initialization
Example #21
0
 * @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.
*/
Example #22
0
 /**
  * Finishes progress output for class search phase.
  *
  * Also inserts some extra newlines to make the output clearer.
  *
  * @return void
  */
 public function finishPhase2()
 {
     $this->tokenizerProgress->finish();
     $this->output->outputLine();
     $this->output->outputLine();
 }
Example #23
0
#!/usr/bin/php
<?php 
include 'lib/autoload.php';
$out = new ezcConsoleOutput();
try {
    $songs = new FOFSongIterator(getcwd());
} catch (Exception $e) {
    echo "Exception: " . $e->getMessage() . "\n";
}
$out->outputLine("MOST PLAYED SONGS");
$songs->addFilter('count', array('>=', 5));
foreach ($songs as $idx => $song) {
    $rang = $idx + 1;
    echo "{$rang}. {$song} ({$song->count})\n";
}