Beispiel #1
0
 /**
  * Instantiates object, sets cache and session
  *
  * @return [TerminusCommand] $this
  */
 public function __construct()
 {
     //Load commonly used data from cache
     $this->cache = Terminus::getCache();
     $this->logger = Terminus::getLogger();
     $this->outputter = Terminus::getOutputter();
     $this->session = Session::instance();
     if (!Terminus::isTest()) {
         $this->checkForUpdate();
     }
 }
Beispiel #2
0
 public function testSetLogger()
 {
     // This test assumes that the debug output defaults to off.
     $file_name = getLogFileName();
     $message = 'The sky is the daily bread of the eyes.';
     setOutputDestination($file_name);
     Terminus::getLogger()->debug($message);
     $output = retrieveOutput($file_name);
     $this->assertFalse(strpos($output, $message) !== false);
     Terminus::setLogger(['debug' => true, 'format' => 'json']);
     Terminus::getLogger()->debug($message);
     $output = retrieveOutput($file_name);
     $this->assertTrue(strpos($output, $message) !== false);
     resetOutputDestination($file_name);
 }
Beispiel #3
0
 /**
  * Returns invalid positionals, if any. False if not.
  *
  * @param array $args The arguments to evaluate for invalid positionals
  * @return string|bool Returns the first invalid positional or false
  */
 public function invalidPositionals($args)
 {
     $positionals = $this->querySpec(array('type' => 'positional'));
     $args_count = count($args);
     for ($i = 0; $i < $args_count; $i++) {
         if (!isset($positionals[$i]['token'])) {
             continue;
         }
         $token = preg_replace('#\\[?\\<([a-zA-Z].*)\\>\\]?.*#s', '$1', $positionals[$i]['token']);
         if (in_array(trim($token), array('commands', 'email'))) {
             // We exit here because the wp and drush commands need to not have
             // validation running since their commands are dependent on their
             // respective code bases.
             return false;
         }
         $regex = "#^({$token})\$#s";
         \Terminus::getLogger()->debug("Positional match {$regex}");
         if (!preg_match($regex, $args[$i])) {
             return $args[$i];
         }
     }
     return false;
 }
 /**
  * Retrieves and writes Pantheon aliases to a file
  *
  * @param string $location Name of the file to which to write aliases
  * @return bool
  */
 private function writeAliases($location)
 {
     $logger = Terminus::getLogger();
     if (is_dir($location)) {
         $message = 'Please provide a full path with filename,';
         $message .= ' e.g. {location}/pantheon.aliases.drushrc.php';
         $logger->error($message, compact('location'));
     }
     $file_exists = file_exists($location);
     // Create the directory if it doesn't yet exist
     $dirname = dirname($location);
     if (!is_dir($dirname)) {
         mkdir($dirname, 0700, true);
     }
     $content = $this->getAliases();
     $handle = fopen($location, 'w+');
     fwrite($handle, $content);
     fclose($handle);
     chmod($location, 0700);
     $message = 'Pantheon aliases created';
     if ($file_exists) {
         $message = 'Pantheon aliases updated';
     }
     $logger->info($message);
 }
 /**
  * Simplified request method for Pantheon API
  *
  * @param [string] $path    API path (URL)
  * @param [array]  $options Options for the request
  *   [string] method GET is default
  *   [mixed]  data   Native PHP data structure (e.g. int, string array, or
  *     simple object) to be sent along with the request. Will be encoded as
  *     JSON for you.
  * @return [array] $data
  */
 public static function simpleRequest($path, $options = array())
 {
     $method = 'get';
     if (isset($options['method'])) {
         $method = $options['method'];
         unset($options['method']);
     }
     $url = sprintf('%s://%s:%s/api/%s', TERMINUS_PROTOCOL, TERMINUS_HOST, TERMINUS_PORT, $path);
     if (Session::getValue('session')) {
         $options['cookies'] = array('X-Pantheon-Session' => Session::getValue('session'));
     }
     try {
         Terminus::getLogger()->debug('URL: {url}', compact('url'));
         $resp = Request::send($url, $method, $options);
     } catch (Guzzle\Http\Exception\BadResponseException $e) {
         throw new TerminusException('API Request Error: {msg}', array('msg' => $e->getMessage()));
     }
     $json = $resp->getBody(true);
     $data = array('info' => $resp->getInfo(), 'headers' => $resp->getRawHeaders(), 'json' => $json, 'data' => json_decode($json), 'status_code' => $resp->getStatusCode());
     return $data;
 }