Example #1
0
 /**
  * Runs the Terminus command
  *
  * @return [void]
  */
 public function run()
 {
     if (!Terminus::isTest() && empty($this->arguments)) {
         $this->arguments[] = 'help';
     }
     // Load bundled commands early, so that they're forced to use the same
     // APIs as non-bundled commands.
     Utils\loadCommand($this->arguments[0]);
     if (isset($this->config['require'])) {
         foreach ($this->config['require'] as $path) {
             Utils\loadFile($path);
         }
     }
     try {
         // Show synopsis if it's a composite command.
         $r = $this->findCommandToRun($this->arguments);
         if (is_array($r)) {
             list($command) = $r;
             if ($command->canHaveSubcommands()) {
                 $command->showUsage();
                 exit;
             }
         }
     } catch (TerminusException $e) {
         // Do nothing. Actual error-handling will be done by _runCommand
         $this->logger->debug($e->getMessage());
     }
     // First try at showing man page
     if ($this->arguments[0] == 'help' && isset($this->arguments[1])) {
         $this->_runCommand();
     }
     $this->_runCommand();
 }
Example #2
0
File: API.php Project: m6w6/seekat
 /**
  * Queue the actual HTTP transfer through \seekat\API\Deferred and return the promise
  *
  * @param string $method The HTTP request method
  * @param mixed $args The HTTP query string parameters
  * @param mixed $body Thee HTTP message's body
  * @param array $headers The request's additional HTTP headers
  * @return ExtendedPromiseInterface
  */
 private function __xfer(string $method, $args = null, $body = null, array $headers = null) : ExtendedPromiseInterface
 {
     if (isset($this->__data)) {
         $this->__log->debug(__FUNCTION__ . "({$method}) -> resolve", ["url" => (string) $this->__url, "args" => $args, "body" => $body, "headers" => $headers]);
         return resolve($this);
     }
     $url = $this->__url->mod(["query" => new QueryString($args)]);
     $request = new Request($method, $url, (array) $headers + $this->__headers, $body = is_array($body) ? json_encode($body) : (is_resource($body) ? new Body($body) : (is_scalar($body) ? (new Body())->append($body) : $body)));
     $this->__log->info(__FUNCTION__ . "({$method}) -> request", ["url" => (string) $this->__url, "args" => $this->__url->query, "body" => $body, "headers" => $headers]);
     return (new Call($this, $this->__client, $request))->promise();
 }
 /**
  * {@inheritdoc}
  */
 public function add($key, $data, $ttl)
 {
     if (!$this->enabled) {
         return true;
     }
     try {
         $data = $this->storageFormat($key, $data, $ttl);
         $nKey = $this->key($key);
         $ret = @$this->getConnection()->add($nKey, $data, $ttl);
         $this->Logger->debug("[{$this->persistentId}] " . ($ret ? "Successful" : "Failed to") . " add: '{$key}', Hash: '{$nKey}'");
         return $ret;
     } catch (Exception $e) {
         throw new CacheException($e->getMessage(), $e->getCode());
     }
 }
Example #4
0
 /**
  * @return array [pid => returnCode, ...]
  */
 public function processChildExited()
 {
     $childrenExited = [];
     while (($pid = pcntl_waitpid(0, $status, WNOHANG)) > 0) {
         if (($returnCode = pcntl_wexitstatus($status)) !== 0) {
             $this->logger->debug(sprintf('Child[%d] exited with an error, return code %d', $pid, $returnCode));
         } else {
             $this->logger->debug(sprintf('Child[%d] exited', $pid));
         }
         unset($this->children[$pid]);
         $this->childrenCount--;
         $childrenExited[$pid] = $returnCode;
     }
     return $childrenExited;
 }
 /**
  * gets svn info on the provided path from the remote repo
  * returns the info in a SimpleXMLExtended object, with the hierarchy:
  *
  * entry /
  *  (attributes: kind, path, revision)
  *  url
  *  repository /
  *   root
  *   uuid
  *  commit /
  *   (attributes: revision)
  *   author
  *   date
  *
  * @param string $svnPath SVN path to retrieve (i.e. "tags/2011-03-30_00-00-00")
  * @throws SubversionToolsException
  * @return SimpleXMLExtended commit metadata
  */
 public function getPathInfo($svnPath)
 {
     $this->_validateSvnConfig();
     $user = escapeshellarg($this->svnUsername);
     $pw = escapeshellarg($this->svnPassword);
     $svnPath = trim($svnPath, '/');
     $svn = "svn info --xml --username {$user} --password {$pw} {$this->svnRepository}/{$svnPath}";
     $this->Logger->debug($svn);
     $rawPathInfo = trim(shell_exec($svn));
     $this->Logger->debug($rawPathInfo);
     try {
         $parsedPathInfo = $this->SimpleXMLParser->parseXMLString($rawPathInfo);
         if (!isset($parsedPathInfo->entry)) {
             throw new Exception();
         }
     } catch (Exception $e) {
         throw new SubversionToolsException('Path not found in repository!');
     }
     return $parsedPathInfo;
 }
Example #6
0
 protected function restart()
 {
     if (!$this->processManager->isParent()) {
         return;
     }
     $this->logger->debug('Going to restart the daemon ...');
     $this->isRunning = false;
     $this->__destruct();
     //        // Close the resource handles to prevent this process from hanging on the exec() output.
     //        if (is_resource(STDOUT)) {
     //            fclose(STDOUT);
     //        }
     //        if (is_resource(STDERR)) {
     //            fclose(STDERR);
     //        }
     //        if (is_resource(STDIN)) {
     //            fclose(STDIN);
     //        }
     // exec($this->command()); // run php command as did the user
     exit;
 }