/** * 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(); }
/** * Deploy (or list) changed files. */ public function deploy() { if ($this->listFiles) { $this->cli->lightYellow('LIST mode: No remote files will be modified.'); } $this->checkSubmodules($this->repo); $this->prepareServers(); // Exit with an error if the specified server does not exist in phploy.ini if ($this->server != '' && !array_key_exists($this->server, $this->servers)) { throw new \Exception("The server \"{$this->server}\" is not defined in {$this->iniFilename}."); } // Loop through all the servers in phploy.ini foreach ($this->servers as $name => $server) { $this->currentlyDeploying = $name; // If a server is specified, it's deployed only to that if ($this->server != '' && $this->server != $name) { continue; } elseif ($this->server == '' && $this->defaultServer == true && $name != 'default' && $this->deployAll == false) { continue; } $connection = new \Banago\PHPloy\Connection($server); $this->connection = $connection->server; if ($this->sync) { $this->dotRevision = $this->dotRevisionFilename; $this->setRevision(); continue; } $files = $this->compare($this->revision); $this->cli->bold()->white()->out("\r\nSERVER: " . $name); if ($this->listFiles) { $this->listFiles($files[$this->currentlyDeploying]); } else { // Pre Deploy if (isset($this->preDeploy[$name]) && count($this->preDeploy[$name]) > 0) { $this->preDeploy($this->preDeploy[$name]); } // Pre Deploy Remote if (isset($this->preDeployRemote[$name]) && count($this->preDeployRemote[$name]) > 0) { $this->preDeployRemote($this->preDeployRemote[$name]); } // Push repository $this->push($files[$this->currentlyDeploying]); // Push Submodules if ($this->scanSubmodules && count($this->submodules) > 0) { foreach ($this->submodules as $submodule) { $this->repo = $submodule['path']; $this->currentSubmoduleName = $submodule['name']; $this->cli->gray()->out("\r\nSUBMODULE: " . $this->currentSubmoduleName); $files = $this->compare($submodule['revision']); if ($this->listFiles === true) { $this->listFiles($files[$this->currentlyDeploying]); } else { $this->push($files[$this->currentlyDeploying], $submodule['revision']); } } // We've finished deploying submodules, reset settings for the next server $this->repo = $this->mainRepo; $this->currentSubmoduleName = ''; } // Copy if (isset($this->copyDirs[$name]) && count($this->copyDirs[$name]) > 0) { $this->copy($this->copyDirs[$name]); } // Purge if (isset($this->purgeDirs[$name]) && count($this->purgeDirs[$name]) > 0) { $this->purge($this->purgeDirs[$name]); } // Post Deploy if (isset($this->postDeploy[$name]) && count($this->postDeploy[$name]) > 0) { $this->postDeploy($this->postDeploy[$name]); } // Post Deploy Remote if (isset($this->postDeployRemote[$name]) && count($this->postDeployRemote[$name]) > 0) { $this->postDeployRemote($this->postDeployRemote[$name]); } } // Done if (!$this->listFiles) { $this->cli->bold()->lightGreen("\r\n|---------------[ " . $this->humanFilesize($this->deploymentSize) . ' Deployed ]---------------|'); $this->deploymentSize = 0; } } }
use League\CLImate\CLImate; // Generate the pathinfo by getting the first argument of the script array_shift($argv); // Discard the filename $pathinfo = array_shift($argv); if (empty($pathinfo)) { $pathinfo = '--help'; } // Create our app instance $app = new SlimController\Slim(['debug' => false, 'controller.class_prefix' => '', 'controller.class_suffix' => '', 'controller.method_suffix' => 'Action', 'controller.template_suffix' => '']); // Set up the environment so that Slim can route $app->environment = Slim\Environment::mock(['PATH_INFO' => $pathinfo]); // Define the help command. If it doesn't have a name it won't include itself $app->get('--help', function () use($app) { $writer = new CLImate(); $writer->bold()->out('Available commands:'); foreach ($app->router()->getNamedRoutes() as $route) { $writer->green()->out(' ' . $route->getPattern()); } }); // CLI-compatible not found error handler $app->notFound(function () use($app) { $writer = new CLImate(); $command = $app->environment['PATH_INFO']; $writer->red()->bold()->out(sprintf('Error: Cannot route to command "%s"', $command)); $helpRoute = $app->router()->getMatchedRoutes('GET', '--help', true); $helpRoute[0]->dispatch(); $app->stop(); }); // Format errors for CLI $app->error(function (\Exception $e) use($app) {