/** * Retrieves an instance of the GitHub object * * @param \Joomla\Application\AbstractApplication $app Application object * @param boolean $useBot Flag to use a bot account. * @param string $botUser The bot account user name. * @param string $botPassword The bot account password. * * @return GitHub * * @since 1.0 * @throws \RuntimeException */ public static function getInstance($app, $useBot = false, $botUser = '', $botPassword = '') { $options = new Registry(); // Check if we're in the web application and a token exists if ($app instanceof \JTracker\Application) { $session = $app->getSession(); $token = $session->get('gh_oauth_access_token'); } else { $token = false; } // If a token is active in the session (web app), and we haven't been instructed to use a bot account, use that for authentication if ($token && !$useBot) { $options->set('gh.token', $token); } else { // Check if credentials are supplied if ($botUser && $botPassword) { $user = $botUser; $password = $botPassword; } else { // Check for support for multiple accounts $accounts = $app->get('github.accounts'); if ($accounts) { $user = isset($accounts[0]->username) ? $accounts[0]->username : null; $password = isset($accounts[0]->password) ? $accounts[0]->password : null; // Store the other accounts $options->set('api.accounts', $accounts); } else { // Support for a single account $user = $app->get('github.username'); $password = $app->get('github.password'); } } // Add the username and password to the options object if both are set if ($user && $password) { // Set the options from the first account $options->set('api.username', $user); $options->set('api.password', $password); } } // The cURL extension is required to properly work. $transport = HttpFactory::getAvailableDriver($options, array('curl')); // Check if we *really* got a cURL transport... if (!$transport instanceof Curl) { throw new \RuntimeException('Please enable cURL.'); } $http = new Http($options, $transport); // Instantiate the object return new Github($options, $http); }
/** * Get a ControllerInterface object for a given name. * * @param string $name The controller name (excluding prefix) for which to fetch and instance. * * @return ControllerInterface * * @since 1.0 * @throws \RuntimeException */ protected function fetchController($name) { // Derive the controller class name. $class = $this->controllerPrefix . ucfirst($name); // If the controller class does not exist panic. if (!class_exists($class) || !is_subclass_of($class, 'Joomla\\Controller\\ControllerInterface')) { throw new \RuntimeException(sprintf('Unable to locate controller `%s`.', $class), 404); } // Instantiate the controller. $controller = new $class($this->input, $this->app); if ($controller instanceof ContainerAwareInterface) { $controller->setContainer($this->app->getContainer()); } return $controller; }
/** * Class constructor. * * @param Input $input An optional argument to provide dependency injection for the application's * input object. If the argument is a Input object that object will become * the application's input object, otherwise a default input object is created. * @param Registry $config An optional argument to provide dependency injection for the application's * config object. If the argument is a Registry object that object will become * the application's config object, otherwise a default config object is created. * @param Web\WebClient $client An optional argument to provide dependency injection for the application's * client object. If the argument is a Web\WebClient object that object will become * the application's client object, otherwise a default client object is created. * * @since 1.0 */ public function __construct(Input $input = null, Registry $config = null, Web\WebClient $client = null) { parent::__construct($input, $config); $this->client = $client instanceof Web\WebClient ? $client : new Web\WebClient(); // Set the execution datetime and timestamp; $this->set('execution.datetime', gmdate('Y-m-d H:i:s')); $this->set('execution.timestamp', time()); // Setup the response object. $this->response = new \stdClass(); $this->response->cachable = false; $this->response->headers = array(); $this->response->body = array(); // Set the system URIs. $this->loadSystemUris(); }
/** * Class constructor. * * @param Input\Cli $input An optional argument to provide dependency injection for the application's * input object. If the argument is a InputCli object that object will become * the application's input object, otherwise a default input object is created. * @param Registry $config An optional argument to provide dependency injection for the application's * config object. If the argument is a Registry object that object will become * the application's config object, otherwise a default config object is created. * * @param CliOutput $output The output handler. * * @since 1.0 */ public function __construct(Input\Cli $input = null, Registry $config = null, CliOutput $output = null) { // Close the application if we are not executed from the command line. // @codeCoverageIgnoreStart if (!defined('STDOUT') || !defined('STDIN') || !isset($_SERVER['argv'])) { $this->close(); } // @codeCoverageIgnoreEnd parent::__construct($input instanceof Input\Input ? $input : new Input\Cli(), $config); // Set the execution datetime and timestamp; $this->set('execution.datetime', gmdate('Y-m-d H:i:s')); $this->set('execution.timestamp', time()); // Set the current directory. $this->set('cwd', getcwd()); $this->output = $output instanceof CliOutput ? $output : new Cli\Output\Stdout(); }
/** * Class constructor. * * @param Input\Cli $input An optional argument to provide dependency injection for the application's * input object. If the argument is an InputCli object that object will become * the application's input object, otherwise a default input object is created. * @param Registry $config An optional argument to provide dependency injection for the application's * config object. If the argument is a Registry object that object will become * the application's config object, otherwise a default config object is created. * @param Cli\CliOutput $output The output handler. * @param Cli\CliInput $cliInput The CLI input handler. * * @since 1.0 */ public function __construct(Input\Cli $input = null, Registry $config = null, Cli\CliOutput $output = null, Cli\CliInput $cliInput = null) { // Close the application if we are not executed from the command line. // @codeCoverageIgnoreStart if (!defined('STDOUT') || !defined('STDIN') || !isset($_SERVER['argv'])) { $this->close(); } // @codeCoverageIgnoreEnd $this->output = $output instanceof Cli\CliOutput ? $output : new Cli\Output\Stdout(); // Set the CLI input object. $this->cliInput = $cliInput instanceof Cli\CliInput ? $cliInput : new Cli\CliInput(); // Call the constructor as late as possible (it runs `initialise`). parent::__construct($input instanceof Input\Input ? $input : new Input\Cli(), $config); // Set the current directory. $this->set('cwd', getcwd()); }
/** * Tests the Joomla\Application\AbstractApplication::setLogger and getLogger methods. * * @return void * * @covers Joomla\Application\AbstractApplication::setLogger * @covers Joomla\Application\AbstractApplication::getLogger * @since 1.0 */ public function testSetLogger() { $mockLogger = $this->getMock('Psr\\Log\\AbstractLogger', array('log'), array(), '', false); $this->assertSame($this->instance, $this->instance->setLogger($mockLogger), 'Checks chainging.'); $this->assertSame($mockLogger, $this->instance->getLogger(), 'Checks the get method.'); }
/** * Returns a list of global variables to add to the existing list * * @return array An array of global variables * * @since 1.0 */ public function getGlobals() { return ['uri' => $this->app->get('uri')]; }
/** * Class constructor. * * @param Input $input An optional argument to provide dependency injection for the application's * input object. If the argument is an Input object that object will become * the application's input object, otherwise a default input object is created. * @param Registry $config An optional argument to provide dependency injection for the application's * config object. If the argument is a Registry object that object will become * the application's config object, otherwise a default config object is created. * @param Web\WebClient $client An optional argument to provide dependency injection for the application's * client object. If the argument is a Web\WebClient object that object will become * the application's client object, otherwise a default client object is created. * * @since 1.0 */ public function __construct(Input $input = null, Registry $config = null, Web\WebClient $client = null) { $this->client = $client instanceof Web\WebClient ? $client : new Web\WebClient(); // Setup the response object. $this->response = new \stdClass(); $this->response->cachable = false; $this->response->headers = array(); $this->response->body = array(); // Call the constructor as late as possible (it runs `initialise`). parent::__construct($input, $config); // Set the system URIs. $this->loadSystemUris(); }