示例#1
0
<?php

require_once dirname(__DIR__) . '/vendor/autoload.php';
class Kolor extends Colors\Color
{
    function __invoke($string = null)
    {
        $obj = new Colors\Color($string);
        return $obj;
    }
}
$c = new Kolor();
$c = new Colors\Color();
function color($string)
{
    return new Colors\Color($string);
}
echo color('Hello World!')->red()->white() . color("some other text 1 ")->green() . color("some other text 2 ")->blue() . color("some other text 3 ")->yellow() . color("some other text 4 ")->white() . PHP_EOL;
exit;
print "we r here \n";
print $c->red("this is red") . "\n";
print $c->bold($c->red("this is red and bold")) . "\n";
print $c("also this is red and bold")->red->bold . "\n";
$c("this is some text");
var_dump($c);
print "===============================================================\n";
$c("this is some text")->red();
var_dump($c);
print "===============================================================\n";
$c("different text");
var_dump($c);
示例#2
0
 function run()
 {
     $config = $this->config;
     $context = $this->context;
     /* @var $context ExecutionContext */
     $write = function ($s) {
         echo $s;
     };
     $writeln = function ($s) {
         $d = new \DateTime();
         echo $d->format(\DateTime::ISO8601) . ' ' . $s . "\n";
     };
     $c = $color = new \Colors\Color();
     /* @var $c \Colors\Color */
     $writeln($c('Running agent `' . $this->name)->bold() . '`');
     // generate an array with handlers
     $writeln('Loading handlers');
     $handlers = [];
     $handlersDir = $config->handlers_dir;
     if ($handlersDir) {
         $finder = new \Symfony\Component\Finder\Finder();
         foreach ($finder->in($handlersDir)->name('*.php')->sortByName() as $file) {
             /* @var $file \SplFileInfo */
             $handlerId = $file->getBasename('.php');
             $handler = (include $file);
             $handlers[$handlerId] = $handler;
             $writeln('  setting up handler ' . $color($handlerId)->bold() . $color->yellow(' (in ' . $file . ')'));
             $eventName = SqsEvents::generateEventForAgentId(SqsEvents::EVENT_SQSAGENT_SQSMESSAGERECEIVED, $this->getId());
             $context->getEventDispatcher()->addListener($eventName, function (\T24\Event\SqsMessageReceivedEvent $event) use($write, $writeln, $color, $handler, $handlerId, $eventName) {
                 $writeln($color->bg('blue', $color->white('invoking handler ' . $handlerId . ' for event ' . $eventName)));
                 /* @var Callable $handler */
                 $result = $handler($event);
                 // write comments
                 $comments = $event->getComments();
                 foreach ($comments as $comment) {
                     $writeln($color('  comment: ')->yellow() . $comment);
                 }
                 $writeln('  - handler ' . $handlerId . ' had been invoked.');
                 if ($event->isPropagationStopped()) {
                     $writeln('  - ' . $color->red('the event was stopped from further propagation.'));
                 } else {
                     $writeln('  - the event was not stopped. proceed to next handler');
                 }
                 return $result;
             });
         }
         $writeln('Loaded ' . count($handlers) . '  handlers.');
     } else {
         $writeln('default handlers dir not specified, no handlers defined..');
     }
     // @todo: get aws params.
     $region = '';
     $sqsQueueUrl = '';
     $sqs = SqsClient::factory(['region' => $config->aws_region, 'version' => '2012-11-05', 'credentials' => ['key' => $config->aws_key, 'secret' => $config->aws_secret]]);
     // start the process
     $ttl = (int) $config->ttl;
     $ttl = min($ttl, 300);
     $ttl = max($ttl, 5);
     $sleep = (int) $config->sleep;
     $sleep = min($sleep, $ttl - 5);
     $sleep = max($sleep, 0);
     $stopwatch = new \Symfony\Component\Stopwatch\Stopwatch();
     $b = $stopwatch->start('loop');
     while ($b->getDuration() < $ttl * 1000) {
         // get an sqs message from the queue
         $writeln($c('Polling Sqs for messages'));
         $result = $sqs->receiveMessage(['QueueUrl' => $config->sqs_queue_url, 'AttributeNames' => ['All'], 'MessageAttributeNames' => ['All'], 'MaxNumberOfMessages' => 1]);
         /* @var $result \Aws\Result */
         if (!$result['Messages'] || $result['Messages'] == 0) {
             $writeln($c('no messages found in sqs queue'));
         } else {
             $writeln($c(sprintf('%d message(s) retrieved from queue.', count($result['Messages']))));
             foreach ($result['Messages'] as $message) {
                 // set up an event that the message is received.
                 // the default subscriber will pass the event to the event handlers in the handlers dir
                 $event = new SqsMessageReceivedEvent($context, $message);
                 $context->getEventDispatcher()->dispatch(SqsEvents::EVENT_SQSAGENT_SQSMESSAGERECEIVED, $event);
                 $context->getEventDispatcher()->dispatch(SqsEvents::generateEventForAgentId(SqsEvents::EVENT_SQSAGENT_SQSMESSAGERECEIVED, $this->getId()), $event);
                 /*
                 $context->getEventDispatcher()->dispatch(SqsEvents::EVENT_SQSAGENT_SQSMESSAGEHANDLED, $event2);
                 if ($event->isProcessed()) {
                     $context->getEventDispatcher()->dispatch(SqsEvents::EVENT_SQSAGENT_SQSMESSAGEPROCESSED, $event2);
                 }
                 */
                 if ($event->getRemoveFromQueue()) {
                     $writeln('  - the event handlers indicate the sqs message should  be removed from the queue.');
                     // remove from sqs
                     $sqsMessage = $event->getSqsMessage();
                     $removed = $sqs->deleteMessage(['QueueUrl' => $config->sqs_queue_url, 'ReceiptHandle' => $sqsMessage['ReceiptHandle']]);
                     $writeln('  - ' . ($removed ? $c->green('succesfully removed the message from SQS') : $c->red('failed to remove the message from SQS')));
                 } else {
                     $writeln('  - the event handlers indicate the sqs messageshould not be removed from the queue.');
                 }
             }
         }
         $writeln($color->cyan('sleeping for ' . $sleep . ' seconds'));
         sleep($sleep);
     }
     // end stopwatch while loop
     $writeln('Stopped after ' . (int) ($b->getDuration() / 1000) . ' secs.');
     // send the finish event.
     $event = new \T24\Event\AgentEvent($context);
     $context->getEventDispatcher()->dispatch(SqsEvents::EVENT_SQSAGENT_FINISH, $event);
     $context->getEventDispatcher()->dispatch(SqsEvents::generateEventForAgentId(SqsEvents::EVENT_SQSAGENT_FINISH, $this->getId()), $event);
 }
示例#3
0
 /**
  * @return string
  */
 public function getHelp()
 {
     $color = new \Colors\Color();
     $help = '';
     $isNamed = $this->type & self::TYPE_NAMED;
     if ($isNamed) {
         $help .= PHP_EOL . (mb_strlen($this->name, 'UTF-8') === 1 ? '-' : '--') . $this->name;
         if (!empty($this->aliases)) {
             foreach ($this->aliases as $alias) {
                 $help .= (mb_strlen($alias, 'UTF-8') === 1 ? '/-' : '/--') . $alias;
             }
         }
         if (!$this->isBoolean()) {
             $help .= ' ' . $color->underline('<argument>');
         }
         $help .= PHP_EOL;
     } else {
         $help .= (empty($this->title) ? "arg {$this->name}" : $this->title) . PHP_EOL;
     }
     // bold what has been displayed so far
     $help = $color->bold($help);
     $titleLine = '';
     if ($isNamed && $this->title) {
         $titleLine .= $this->title . '.';
         if ($this->isRequired()) {
             $titleLine .= ' ';
         }
     }
     if ($this->isRequired()) {
         $titleLine .= $color->red('Required.');
     }
     if ($titleLine) {
         $titleLine .= ' ';
     }
     $description = $titleLine . $this->description;
     if (!empty($description)) {
         $descriptionArray = explode(PHP_EOL, trim($description));
         foreach ($descriptionArray as $descriptionLine) {
             $help .= Terminal::wrap($descriptionLine, 5, 1) . PHP_EOL;
         }
     }
     return $help;
 }
示例#4
0
 public function arg_parse($argv)
 {
     $short_opts = 'hvq';
     $long_opts = array("sqlformat::", "xml::", "oldxml::", "newxml::", "pgdataxml::", "xmldatainsert::", "outputfile::", "dbschemadump::", "slonikconvert::", "slonycompare::", "slonydiffold::", "slonydiffnew::", "slonyidin::", "slonyidout::", "slonyidstartvalue::", "slonyidsetvalue::", "oldsql::", "newsql::", "dbhost::", "dbport::", "dbname::", "dbuser::", "dbpassword::", "requireslonyid::", "requireslonysetid::", "generateslonik::", "quoteschemanames::", "quotetablenames::", "quotecolumnnames::", "quoteallnames::", "quoteillegalnames::", "quotereservednames::", "onlyschemasql::", "onlydatasql::", "onlytable::", "singlestageupgrade::", "maxstatementsperfile::", "ignoreoldnames::", "ignorecustomroles::", "ignoreprimarykeyerrors::", "dbdatadiff::", "xmlsort::", "xmlconvert::", "xmlcollectdataaddendums::", "useautoincrementoptions::", "useschemaprefix::", "outputdir::", "outputfileprefix::", "debug");
     $options = getopt($short_opts, $long_opts);
     self::set_verbosity($options);
     if (count($argv) == 1 || isset($options['help']) || isset($options['h'])) {
         $c = new Colors\Color();
         $c->setTheme(array('header' => array('underline', 'dark_gray'), 'keyword' => array('green'), 'value' => array('yellow')));
         echo $c->colorize(self::usage()) . PHP_EOL;
         exit(1);
     }
     $files = array('old' => array(), 'new' => array(), 'pgdata' => array());
     ///// XML file parameter sanity checks
     if (isset($options['xml'])) {
         if (count($options['xml']) > 0 && isset($options['oldxml']) && count($options['oldxml']) > 0) {
             dbsteward::error("Parameter error: xml and oldxml options are not to be mixed. Did you mean newxml?");
             exit(1);
         }
         if (count($options['xml']) > 0 && isset($options['newxml']) && count($options['newxml']) > 0) {
             dbsteward::error("Parameter error: xml and newxml options are not to be mixed. Did you mean oldxml?");
             exit(1);
         }
     }
     if (isset($options['oldxml']) && count($options['oldxml']) > 0 && (!isset($options['newxml']) || count($options['newxml']) == 0)) {
         dbsteward::error("Parameter error: oldxml needs newxml specified for differencing to occur");
         exit(1);
     }
     if ((!isset($options['oldxml']) || count($options['oldxml']) == 0) && (isset($options['newxml']) && count($options['newxml']) > 0)) {
         dbsteward::error("Parameter error: oldxml needs newxml specified for differencing to occur");
         exit(1);
     }
     ///// database connectivity values
     $dbhost = FALSE;
     if (isset($options["dbhost"]) && strlen($options["dbhost"]) > 0) {
         $dbhost = $options["dbhost"];
     }
     // $dbport set in sql_format defaults section
     $dbport = NULL;
     if (isset($options["dbport"]) && strlen($options["dbport"]) > 0) {
         $dbport = $options["dbport"];
     }
     $dbname = FALSE;
     if (isset($options["dbname"]) && strlen($options["dbname"]) > 0) {
         $dbname = $options["dbname"];
     }
     $dbuser = FALSE;
     if (isset($options["dbuser"]) && strlen($options["dbuser"]) > 0) {
         $dbuser = $options["dbuser"];
     }
     if (isset($options['dbpassword'])) {
         if ($options['dbpassword'] === false) {
             // treat --dbpassword as the empty password, because
             // --dbpassword='' doesn't show up in $options
             $this->cli_dbpassword = '';
         } else {
             $this->cli_dbpassword = $options['dbpassword'];
         }
     }
     ///// SQL DDL DML DCL output flags
     if (isset($options["onlyschemasql"])) {
         dbsteward::$only_schema_sql = TRUE;
     }
     if (isset($options["onlydatasql"])) {
         dbsteward::$only_data_sql = TRUE;
     }
     if (isset($options['onlytable'])) {
         $onlytables = $options['onlytable'];
         if (!is_array($onlytables)) {
             $onlytables = array($onlytables);
         }
         foreach ($onlytables as $onlytable) {
             $onlytable_schema = 'public';
             $onlytable_table = $onlytable;
             if (strpos($onlytable_table, '.') !== FALSE) {
                 $chunks = explode('.', $onlytable_table);
                 $onlytable_schema = $chunks[0];
                 $onlytable_table = $chunks[1];
             }
             if (!isset(dbsteward::$limit_to_tables[$onlytable_schema])) {
                 dbsteward::$limit_to_tables[$onlytable_schema] = array();
             }
             dbsteward::$limit_to_tables[$onlytable_schema][] = $onlytable_table;
         }
     }
     ///// common parameter for output file for converter functions
     // for modes that can do it, omitting this parameter will cause output to be directed to stdout
     $output_file = FALSE;
     if (isset($options["outputfile"]) && strlen($options["outputfile"]) > 0) {
         $output_file = $options["outputfile"];
     }
     if (isset($options["maxstatementsperfile"])) {
         if (!is_numeric($options["maxstatementsperfile"])) {
             throw new exception("maxstatementsperfile passed is not a number");
         }
         dbsteward::$output_file_statement_limit = $options["maxstatementsperfile"];
     }
     ///// XML parsing switches
     if (isset($options["singlestageupgrade"])) {
         dbsteward::$single_stage_upgrade = TRUE;
         // don't recreate views when in single stage upgrade mode
         // @TODO: make view diffing smart enough that this doesn't need to be done
         dbsteward::$always_recreate_views = FALSE;
     }
     if (isset($options["ignoreoldnames"])) {
         dbsteward::$ignore_oldnames = TRUE;
     }
     if (isset($options["ignorecustomroles"])) {
         dbsteward::$ignore_custom_roles = TRUE;
     }
     if (isset($options["ignoreprimarykeyerrors"])) {
         dbsteward::$ignore_primary_key_errors = TRUE;
     }
     if (isset($options["requireslonyid"])) {
         dbsteward::$require_slony_id = TRUE;
     }
     if (isset($options["requireslonysetid"])) {
         dbsteward::$require_slony_set_id = TRUE;
     }
     if (isset($options["generateslonik"])) {
         dbsteward::$generate_slonik = TRUE;
     }
     if (isset($options["slonyidstartvalue"])) {
         if ($options["slonyidstartvalue"] < 1) {
             throw new exception("slonyidstartvalue must be greater than 0");
         }
         dbsteward::$slonyid_start_value = $options["slonyidstartvalue"];
     }
     if (isset($options["slonyidsetvalue"])) {
         if ($options["slonyidsetvalue"] < 1) {
             throw new exception("slonyidsetvalue must be greater than 0");
         }
         dbsteward::$slonyid_set_value = $options["slonyidsetvalue"];
     }
     ///// determine the operation and check arguments for each
     $mode = dbsteward::MODE_UNKNOWN;
     if (isset($options['xmldatainsert'])) {
         if (!isset($options['xml'])) {
             throw new exception("xmldatainsert needs xml parameter defined");
         }
         $mode = dbsteward::MODE_XML_DATA_INSERT;
     } elseif (isset($options["xmlsort"])) {
         $mode = dbsteward::MODE_XML_SORT;
     } elseif (isset($options["xmlconvert"])) {
         $mode = dbsteward::MODE_XML_CONVERT;
     } elseif (isset($options['xml']) && count($options['xml']) > 0) {
         $mode = dbsteward::MODE_BUILD;
     } elseif (isset($options['newxml']) && count($options['newxml']) > 0) {
         $mode = dbsteward::MODE_DIFF;
     } elseif (isset($options["dbschemadump"])) {
         if (strlen($dbhost) === FALSE) {
             throw new exception("dbschemadump error: dbhost not specified");
         } elseif (strlen($dbname) === FALSE) {
             throw new exception("dbschemadump error: dbname not specified");
         } elseif (strlen($dbuser) === FALSE) {
             throw new exception("dbschemadump error: dbuser not specified");
         } elseif ($output_file === FALSE) {
             throw new exception("dbschemadump error: outputfile not specified");
         }
         $mode = dbsteward::MODE_EXTRACT;
     } elseif (isset($options['dbdatadiff'])) {
         if (strlen($dbhost) === FALSE) {
             throw new exception("dbdatadiff error: dbhost not specified");
         } elseif (strlen($dbname) === FALSE) {
             throw new exception("dbdatadiff error: dbname not specified");
         } elseif (strlen($dbuser) === FALSE) {
             throw new exception("dbdatadiff error: dbuser not specified");
         }
         $mode = dbsteward::MODE_DB_DATA_DIFF;
     } elseif (isset($options["oldsql"]) || isset($options["newsql"])) {
         if ($output_file === FALSE) {
             throw new exception("sql diff error: you must specify an outputfile for this mode");
         }
         $mode = dbsteward::MODE_SQL_DIFF;
     } elseif (isset($options["slonikconvert"])) {
         $mode = dbsteward::MODE_SLONIK_CONVERT;
     } elseif (isset($options["slonycompare"])) {
         $mode = dbsteward::MODE_SLONY_COMPARE;
     } elseif (isset($options["slonydiffold"])) {
         $mode = dbsteward::MODE_SLONY_DIFF;
     } elseif (isset($options["slonyidin"])) {
         // check to make sure output is not same as input
         if (isset($options["slonyidout"])) {
             if (strcmp($options["slonyidin"], $options["slonyidout"]) == 0) {
                 throw new exception("slonyidin and slonyidout file paths should not be the same");
             }
         }
         $mode = dbsteward::MODE_XML_SLONY_ID;
     }
     ///// File output location specificity
     if (isset($options['outputdir'])) {
         if (strlen($options['outputdir']) == 0) {
             throw new exception("outputdir is blank, must specify a value for this option");
         }
         if (!is_dir($options['outputdir'])) {
             throw new exception("outputdir is not a directory; this must be a writable directory");
         }
         dbsteward::$file_output_directory = $options['outputdir'];
     }
     if (isset($options['outputfileprefix'])) {
         if (strlen($options['outputfileprefix']) == 0) {
             throw new exception("outputfileprefix is blank, must specify a value for this option");
         }
         dbsteward::$file_output_prefix = $options['outputfileprefix'];
     }
     ///// For the appropriate modes, composite the input XML
     ///// and figure out the SQL format of it
     $force_sql_format = FALSE;
     if (isset($options['sqlformat'])) {
         $force_sql_format = $options['sqlformat'];
     }
     $target_sql_format = FALSE;
     switch ($mode) {
         case dbsteward::MODE_BUILD:
             $files = (array) $options['xml'];
             $target_sql_format = xml_parser::get_sql_format($files);
             break;
         case dbsteward::MODE_DIFF:
             $old_files = (array) $options['oldxml'];
             $new_files = (array) $options['newxml'];
             $old_target = xml_parser::get_sql_format($old_files);
             $new_target = xml_parser::get_sql_format($new_files);
             // prefer the new sql_format
             $target_sql_format = $new_target ?: $old_target;
             break;
     }
     $xml_collect_data_addendums = 0;
     if (isset($options["xmlcollectdataaddendums"]) && $options["xmlcollectdataaddendums"] > 0) {
         $xml_collect_data_addendums = (int) $options["xmlcollectdataaddendums"];
         if ($mode != dbsteward::MODE_BUILD) {
             throw new Exception("--xmlcollectdataaddendums is only supported for fresh builds");
         }
         if ($xml_collect_data_addendums > count($files)) {
             throw new Exception("Cannot collect more data addendums then files provided");
         }
     }
     // announce our defined version before doing any configuration announcements or tasks
     dbsteward::notice("DBSteward Version " . self::VERSION);
     ///// set the global SQL format
     $sql_format = dbsteward::reconcile_sql_format($target_sql_format, $force_sql_format);
     dbsteward::notice("Using sqlformat={$sql_format}");
     dbsteward::set_sql_format($sql_format);
     if (is_null($dbport)) {
         $dbport = dbsteward::define_sql_format_default_values($sql_format, $options);
     }
     // user-specified overrides for identifier quoting
     if (isset($options["quoteschemanames"])) {
         dbsteward::$quote_schema_names = TRUE;
     }
     if (isset($options["quotetablenames"])) {
         dbsteward::$quote_table_names = TRUE;
     }
     if (isset($options["quotecolumnnames"])) {
         dbsteward::$quote_column_names = TRUE;
     }
     if (isset($options["quoteallnames"])) {
         dbsteward::$quote_all_names = TRUE;
     }
     if (isset($options["quoteillegalnames"])) {
         dbsteward::$quote_illegal_identifiers = TRUE;
     }
     if (isset($options["quotereservednames"])) {
         dbsteward::$quote_reserved_identifiers = TRUE;
     }
     switch ($mode) {
         case dbsteward::MODE_XML_DATA_INSERT:
             dbsteward::xml_data_insert($options['xml'], $options['xmldatainsert']);
             break;
         case dbsteward::MODE_XML_SORT:
             dbsteward::xml_sort($options['xmlsort']);
             break;
         case dbsteward::MODE_XML_CONVERT:
             dbsteward::xml_convert($options['xmlconvert']);
             break;
         case dbsteward::MODE_XML_SLONY_ID:
             dbsteward::info("Compositing XML file for Slony ID processing..");
             $files = (array) $options['slonyidin'];
             $db_doc = xml_parser::xml_composite($files);
             dbsteward::info("XML files " . implode(' ', $files) . " composited");
             $output_prefix = dbsteward::calculate_file_output_prefix($files);
             $composite_file = $output_prefix . '_composite.xml';
             $db_doc = xml_parser::sql_format_convert($db_doc);
             xml_parser::vendor_parse($db_doc);
             dbsteward::notice("Saving composite as " . $composite_file);
             xml_parser::save_doc($composite_file, $db_doc);
             dbsteward::notice("Slony ID numbering any missing attributes");
             dbsteward::info("slonyidstartvalue = " . dbsteward::$slonyid_start_value);
             dbsteward::info("slonyidsetvalue = " . dbsteward::$slonyid_set_value);
             $slonyid_doc = xml_parser::slonyid_number($db_doc);
             $slonyid_numbered_file = $output_prefix . '_slonyid_numbered.xml';
             // if specified, use output file value instead of auto suffix
             if (isset($options["slonyidout"])) {
                 $slonyid_numbered_file = $options["slonyidout"];
             }
             dbsteward::notice("Saving Slony ID numbered XML as " . $slonyid_numbered_file);
             xml_parser::save_doc($slonyid_numbered_file, $slonyid_doc);
             break;
         case dbsteward::MODE_BUILD:
             dbsteward::info("Compositing XML files..");
             $addendums_doc = NULL;
             if ($xml_collect_data_addendums > 0) {
                 dbsteward::info("Collecting {$xml_collect_data_addendums} data addendums");
             }
             $db_doc = xml_parser::xml_composite($files, $xml_collect_data_addendums, $addendums_doc);
             if (isset($options['pgdataxml']) && count($options['pgdataxml'])) {
                 $pg_data_files = (array) $options['pgdataxml'];
                 dbsteward::info("Compositing pgdata XML files on top of XML composite..");
                 xml_parser::xml_composite_pgdata($db_doc, $pg_data_files);
                 dbsteward::info("postgres data XML files [" . implode(' ', $pg_data_files) . "] composited.");
             }
             dbsteward::info("XML files " . implode(' ', $files) . " composited");
             $output_prefix = dbsteward::calculate_file_output_prefix($files);
             $composite_file = $output_prefix . '_composite.xml';
             $db_doc = xml_parser::sql_format_convert($db_doc);
             xml_parser::vendor_parse($db_doc);
             dbsteward::notice("Saving composite as " . $composite_file);
             xml_parser::save_doc($composite_file, $db_doc);
             if ($addendums_doc !== NULL) {
                 $addendums_file = $output_prefix . '_addendums.xml';
                 dbsteward::notice("Saving addendums as {$addendums_file}");
                 xml_parser::save_doc($addendums_file, $addendums_doc);
             }
             format::build($output_prefix, $db_doc);
             break;
         case dbsteward::MODE_DIFF:
             dbsteward::info("Compositing old XML files..");
             $old_db_doc = xml_parser::xml_composite($old_files);
             dbsteward::info("Old XML files " . implode(' ', $old_files) . " composited");
             dbsteward::info("Compositing new XML files..");
             $new_db_doc = xml_parser::xml_composite($new_files);
             if (isset($options['pgdataxml']) && count($options['pgdataxml'])) {
                 $pg_data_files = (array) $options['pgdataxml'];
                 dbsteward::info("Compositing pgdata XML files on top of new XML composite..");
                 xml_parser::xml_composite_pgdata($new_db_doc, $pg_data_files);
                 dbsteward::info("postgres data XML files [" . implode(' ', $pg_data_files) . "] composited");
             }
             dbsteward::info("New XML files " . implode(' ', $new_files) . " composited");
             $old_output_prefix = dbsteward::calculate_file_output_prefix($old_files);
             $old_composite_file = $old_output_prefix . '_composite.xml';
             $old_db_doc = xml_parser::sql_format_convert($old_db_doc);
             xml_parser::vendor_parse($old_db_doc);
             dbsteward::notice("Saving oldxml composite as " . $old_composite_file);
             xml_parser::save_doc($old_composite_file, $old_db_doc);
             $new_output_prefix = dbsteward::calculate_file_output_prefix($new_files);
             $new_composite_file = $new_output_prefix . '_composite.xml';
             $new_db_doc = xml_parser::sql_format_convert($new_db_doc);
             xml_parser::vendor_parse($new_db_doc);
             dbsteward::notice("Saving newxml composite as " . $new_composite_file);
             xml_parser::save_doc($new_composite_file, $new_db_doc);
             format::build_upgrade($old_output_prefix, $old_composite_file, $old_db_doc, $old_files, $new_output_prefix, $new_composite_file, $new_db_doc, $new_files);
             break;
         case dbsteward::MODE_EXTRACT:
             $output = format::extract_schema($dbhost, $dbport, $dbname, $dbuser, $this->cli_dbpassword);
             dbsteward::notice("Saving extracted database schema to " . $output_file);
             if (!file_put_contents($output_file, $output)) {
                 throw new exception("Failed to save extracted database schema to " . $output_file);
             }
             break;
         case dbsteward::MODE_DB_DATA_DIFF:
             // dbdatadiff files are defined with --dbdatadiff not --xml
             $dbdatadiff_files = (array) $options['dbdatadiff'];
             dbsteward::info("Compositing XML files..");
             $addendums_doc = NULL;
             if ($xml_collect_data_addendums > 0) {
                 dbsteward::info("Collecting {$xml_collect_data_addendums} data addendums");
             }
             $db_doc = xml_parser::xml_composite($dbdatadiff_files, $xml_collect_data_addendums, $addendums_doc);
             if (isset($options['pgdataxml']) && count($options['pgdataxml'])) {
                 $pg_data_files = (array) $options['pgdataxml'];
                 dbsteward::info("Compositing pgdata XML files on top of XML composite..");
                 xml_parser::xml_composite_pgdata($db_doc, $pg_data_files);
                 dbsteward::info("postgres data XML files [" . implode(' ', $pg_data_files) . "] composited.");
             }
             dbsteward::info("XML files " . implode(' ', $dbdatadiff_files) . " composited");
             $output_prefix = dbsteward::calculate_file_output_prefix($dbdatadiff_files);
             $composite_file = $output_prefix . '_composite.xml';
             $db_doc = xml_parser::sql_format_convert($db_doc);
             xml_parser::vendor_parse($db_doc);
             dbsteward::notice("Saving composite as " . $composite_file);
             xml_parser::save_doc($composite_file, $db_doc);
             $output = format::compare_db_data($db_doc, $dbhost, $dbport, $dbname, $dbuser, $this->cli_dbpassword);
             if (!file_put_contents($output_file, $output)) {
                 throw new exception("Failed to save extracted database schema to " . $output_file);
             }
             break;
         case dbsteward::MODE_SQL_DIFF:
             format::sql_diff($options["oldsql"], $options["newsql"], $output_file);
             break;
         case dbsteward::MODE_SLONIK_CONVERT:
             $output = slony1_slonik::convert($options["slonikconvert"]);
             if ($output_file !== FALSE) {
                 dbsteward::notice("Saving slonikconvert output to " . $output_file);
                 if (!file_put_contents($output, $output_file)) {
                     throw new exception("Failed to save slonikconvert output to " . $output_file);
                 }
             } else {
                 echo $output;
             }
             break;
         case dbsteward::MODE_SLONY_COMPARE:
             pgsql8::slony_compare($options["slonycompare"]);
             break;
         case dbsteward::MODE_SLONY_DIFF:
             pgsql8::slony_diff($options["slonydiffold"], $options["slonydiffnew"]);
             break;
         case dbsteward::MODE_UNKNOWN:
         default:
             throw new Exception("No operation specified!");
     }
 }
示例#5
0
#!/usr/bin/env php
<?php 
require_once './lib/Colors/Exception.php';
require_once './lib/Colors/InvalidArgumentException.php';
require_once './lib/Colors/Color.php';
$c = new \Colors\Color();
// highlight('green') === bg('green') === bg_green()
// white() === fg('white')
echo $c('Hello World!')->white()->bold()->highlight('green') . PHP_EOL;
// using some magic
echo $c('Hello World!')->white->bold->bg_green . PHP_EOL;
// create your own theme
$c->setTheme(array('welcome' => array('white', 'bg_green'), 'bye' => 'blue'));
echo $c('Hello World!')->welcome->bold . PHP_EOL;
echo $c('Bye!')->bye . PHP_EOL;
// use style tags
$text = <<<EOF
1 : <welcome>Hello <bold>World!</bold></welcome>
2 : <bye>Bye!</bye>
EOF;
echo $c($text)->colorize() . PHP_EOL;
// use standard API
$message = $c->apply('bold', $c->white('Hello World!'));
echo $message . PHP_EOL;
echo $c->clean($message) . PHP_EOL;