Example #1
0
 /**
  * Finish testing of a particular class
  * @param  string    $exerciseErrorMessage Formatted error message related to what failed
  * @throws Exception Throws an exception to pass control back up a level
  */
 private function finishChapter($exerciseErrorMessage)
 {
     $terminal = new Terminal();
     $terminal->bold()->out("  Chapter " . $this->chapter->number . ": " . $this->chapter->name . "\n");
     $terminal->out($exerciseErrorMessage);
     $terminal->br();
     $terminal->out('  Chapter ' . $this->chapter->number . ' is ' . $this->percentComplete() . '% complete.');
     $terminal->br();
     throw new \Exception();
 }
Example #2
0
 public function setUp()
 {
     $this->argumentManager = $this->prophesize(Manager::class);
     $this->argumentManager->add(Argument::type('array'))->shouldBeCalled();
     $this->argumentManager->parse(Argument::type('array'))->shouldBeCalled();
     $this->climate = $this->prophesize(CLImate::class);
     $this->climate->arguments = $this->argumentManager->reveal();
     $this->climate->out(Argument::containingString('PHPAssumptions analyser'))->shouldBeCalled()->willReturn($this->climate);
     $this->climate->br()->shouldBeCalled();
     $this->cli = new Cli($this->climate->reveal());
 }
Example #3
0
 /**
  * Execute the command.
  *
  * @param \Symfony\Component\Console\Input\InputInterface $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  *
  * @return mixed
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $climate = new CLImate();
     $packages = $this->getPackages();
     if (count($packages) <= 0) {
         return $climate->br()->error('We couldn\'t find any required packages.')->br();
     }
     $versions = $this->getVersions($packages);
     if (count($versions) <= 0) {
         return $climate->br()->out('All dependencies match the latest package versions <green>:)</green>')->br();
     }
     return $climate->br()->columns($versions, 3)->br();
 }
Example #4
0
 /**
  * Execute the command.
  *
  * @param \Symfony\Component\Console\Input\InputInterface $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  *
  * @return mixed
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $climate = new CLImate();
     $climate->br();
     try {
         $packages = $this->ladder->getOutdatedPackages();
         if (!$packages) {
             $climate->write('All dependencies match the latest package versions <green>:)</green>')->br();
             return;
         }
         $outdated = [];
         $upgradable = [];
         foreach ($packages as $name => list($constraint, $version, $latest)) {
             if (Version::satisfies($latest, $constraint)) {
                 $latest = $this->diff($version, $latest);
                 $upgradable[] = [$name, $version, '→', $latest];
             } else {
                 $latest = $this->diff($version, $latest);
                 $outdated[] = [$name, $version, '→', $latest];
             }
         }
         if ($outdated) {
             $climate->columns($outdated, 3)->br();
         }
         if ($upgradable) {
             $climate->write('The following dependencies are satisfied by their declared version constraint, but the installed versions are behind. You can install the latest versions without modifying your composer.json file by using \'composer update\'.')->br();
             $climate->columns($upgradable, 3)->br();
         }
     } catch (ClimbException $exception) {
         $climate->error($exception->getMessage())->br();
     }
 }
 /**
  * The body of the command.
  *
  * @return void
  */
 public function mysqldumper()
 {
     if (!$this->mysqldumpExists()) {
         throw new \Exception('mysqldump command not found. Please check your path.');
     }
     $this->createArchiveFolder();
     // Get a list of the tables we are going to dump
     $table_list = $this->listTables();
     // Count tables
     $table_count = count($table_list);
     // Create a progress bar
     $progress = $this->cli->progress()->total($table_count);
     // Loop of tables and create dump
     for ($i = 0; $i < $table_count; $i++) {
         $table_name = $table_list[$i]['Tables_in_' . $this->config->db_name];
         $progress->advance(1, $this->parseString('(%s of %s) Dumping %s', [$i + 1, $table_count, $table_name], 'light_green'));
         $command = $this->buildCommand($table_name);
         exec($command);
     }
     $this->cli->br();
     $this->out('Dump complete', 'success');
     if (!$this->skip_remote) {
         $this->out('Uploading to remote', 'success');
         $this->deployToRemote();
     } else {
         $this->out('Skipping remote upload', 'warning');
     }
     // Clean up
     $this->cleanupLocal();
     $this->cleanupRemote();
 }
 /**
  * @param CLImate $cli
  * @param array $arguments
  * @return void
  */
 public function execute(CLImate $cli, $arguments)
 {
     if (!$arguments['trackingNumber']) {
         $cli->error('ERROR. No tracking number provided.');
         return null;
     }
     $chronopostAdapter = new ChronopostAdapter();
     $deliveryTracking = new DeliveryTracking($chronopostAdapter);
     $cli->br();
     try {
         $status = $deliveryTracking->getDeliveryStatus($arguments['trackingNumber']);
         $cli->out(sprintf('Delivery #%s is <green>%s</green>', $arguments['trackingNumber'], $status));
     } catch (\Exception $e) {
         $cli->error(sprintf('ERROR. %s', $e->getMessage()));
     }
     $cli->br();
 }
 /**
  * @param CLImate $cli
  * @param array $arguments
  * @return void
  */
 public function execute(CLImate $cli, $arguments)
 {
     if (!$arguments['reference']) {
         $cli->error('ERROR. No reference provided.');
         return null;
     }
     $cli->comment('Warning: this command may be slow. It may download and parse a lot of file.');
     $cli->comment('I you know the tracking number, you may want to use the `tracking:status [trackingNumber]` command');
     $chronopostAdapter = new ChronopostFtpAdapter(['host' => 'ftpserv.chronopost.fr', 'username' => 'arconseil', 'password' => '!arcnsl$']);
     $deliveryTracking = new DeliveryTracking($chronopostAdapter);
     $cli->br();
     try {
         $status = $deliveryTracking->getDeliveryStatusByInternalReference($arguments['reference']);
         $cli->out(sprintf('Delivery #%s is <green>%s</green>', $arguments['reference'], $status));
         $trackingNumber = $deliveryTracking->getTrackingNumberByInternalReference($arguments['reference']);
         $cli->whisper(sprintf('The associated tracking Number is %s.', $trackingNumber));
     } catch (\Exception $e) {
         $cli->error(sprintf('ERROR. %s', $e->getMessage()));
     }
     $cli->br();
 }
Example #8
0
 /**
  * Print out the argument list
  *
  * @param array $arguments
  * @param string $type
  */
 protected function outputArguments($arguments, $type)
 {
     if (count($arguments) == 0) {
         return;
     }
     $this->climate->br()->out(ucwords($type) . ' Arguments:');
     foreach ($arguments as $argument) {
         $this->climate->tab()->out($this->argument($argument));
         if ($argument->description()) {
             $this->climate->tab(2)->out($argument->description());
         }
     }
 }
Example #9
0
 /**
  * Cli method
  *
  * @param CLImate $climate
  *
  * @throws \Rad\Core\Exception\MissingBundleException
  */
 public function cliMethod(CLImate $climate)
 {
     $sqlDir = VAR_DIR . DS . 'cake_orm' . DS . 'sql';
     if (!is_dir($sqlDir)) {
         mkdir($sqlDir, 0777, true);
     }
     $sql = [];
     foreach (Bundles::getLoaded() as $bundle) {
         $climate->backgroundLightGray()->info(sprintf('Bundle %s ...', $bundle));
         $path = Bundles::getPath($bundle);
         $sqlFilename = Inflection::underscore($bundle) . '.sql';
         $schemaPath = $path . DS . 'Resource' . DS . 'config' . DS . 'schema.xml';
         if (!is_file($schemaPath)) {
             $climate->lightRed(sprintf('File "%s" does not exists.', $schemaPath));
             $climate->br(2);
             continue;
         }
         $domDocument = new DOMDocument();
         $domDocument->load($schemaPath);
         $xpath = new DOMXPath($domDocument);
         $tables = $xpath->query('/database/table');
         /** @var DOMElement $table */
         foreach ($tables as $table) {
             $schemaTable = new Table($table->getAttribute('name'));
             $this->prepareTableRegistry($table, $bundle);
             $this->prepareColumn($table, $xpath, $schemaTable);
             $this->prepareForeignConstraint($table, $xpath, $schemaTable);
             $this->prepareUniqueConstraint($table, $xpath, $schemaTable);
             $this->preparePrimaryConstraint($table, $xpath, $schemaTable);
             $this->prepareIndex($table, $xpath, $schemaTable);
             $sql[$sqlDir . DS . $sqlFilename][] = $schemaTable->createSql(ConnectionManager::get('default'));
         }
         foreach ($sql as $file => $tablesSql) {
             $tmpSql = '';
             foreach ($tablesSql as $tableSql) {
                 $tmpSql .= implode(";\n", $tableSql);
                 $tmpSql .= "\n\n";
             }
             file_put_contents($file, $tmpSql);
             $climate->lightGray(sprintf('Create SQL file "%s".', $file));
         }
         $sql = [];
         $climate->info('Dump table registry config ...');
         $this->dumpTableRegistry($climate, $bundle);
         $climate->info('Dump model classes ...');
         $this->dumpModelClasses($climate, $bundle);
         $climate->br(2);
     }
 }
 /**
  * Receives the messages and pass them to sender
  */
 public function handle()
 {
     $this->channel->basic_consume($this->listenQueue, '', false, true, false, false, function ($msg) {
         $this->climate->br();
         $this->climate->info('Received: ' . $msg->body);
         $input = json_decode($msg->body, true);
         try {
             $output = $this->interestCalculator->caculateInterest($input);
             $output['token'] = $this->token;
             $output = json_encode($output);
             $this->climate->out('Sending back: ' . $output);
             $this->channel->basic_publish($this->amqpFactory->buildMessage($output), '', $this->broadcastQueue);
         } catch (Exception $e) {
             $this->climate->error('Unable to handle the message: ' . $e->getMessage());
             return false;
         }
         return true;
     });
     while (count($this->channel->callbacks)) {
         $this->channel->wait();
     }
     $this->channel->close();
     $this->connection->close();
 }
 /**
  * Output the validate results to console.
  *
  * @param array|string $results
  * @param int $tab
  * @param int $recursive
  */
 protected function outputToConsole($results, $tab = 0, $recursive = 0)
 {
     if (!is_array($results)) {
         $this->tab($tab)->out($results);
     } else {
         foreach ($results as $key => $value) {
             if (is_array($value) && 0 === count($value)) {
                 return;
             } elseif (is_int($key) && !is_array($value)) {
                 $this->tab($tab)->out($value);
             } else {
                 $this->tab($tab)->out($key);
                 $this->outputToConsole($value, $tab + 1, $recursive + 1);
                 if (0 === $recursive) {
                     $this->console->br();
                 }
             }
         }
     }
 }
Example #12
0
 /**
  * Returns CLImate new line
  * @see http://climate.thephpleague.com/terminal-objects/br/
  *
  * @param  int $count Number of new line
  * @return mixed
  */
 public function br($count = 1)
 {
     return $this->climate->br($count);
 }
Example #13
0
 */
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once __DIR__ . '/vendor/autoload.php';
define('ALEXLVCOM_TASK_RUNNER_VERSION', '0.0.2');
define('TASK_PATH', __DIR__ . '/app/tasks');
define('TASK_LOG_PATH', __DIR__ . '/app/logs');
define('ROOTPATH', __DIR__ . '/');
use League\CLImate\CLImate;
use alexlvcom\TaskRunner\CommandContext;
use alexlvcom\TaskRunner\ParamValidator;
use alexlvcom\ServiceContainer\Container as ServiceContainer;
$climate = new CLImate();
$container = new ServiceContainer();
$climate->out('<green>Task Runner by AlexLV. (c) 2015 .</green> <white>Version <yellow>' . ALEXLVCOM_TASK_RUNNER_VERSION . '</yellow>');
$climate->br();
$climate->arguments->add(['name' => ['longPrefix' => 'name', 'description' => 'Task Name', 'required' => true]]);
try {
    $climate->arguments->parse();
} catch (Exception $e) {
    $climate->error($e->getMessage())->br()->usage();
    $climate->br();
    exit;
}
if ($climate->arguments->defined('name') === false || $climate->arguments->get('name') === '') {
    $climate->usage();
    exit;
}
$time_start = microtime(true);
$taskName = $climate->arguments->get('name');
if (substr($taskName, 0, 1) === '\\') {