33
0
mirror of https://github.com/joomla-extensions/patchtester.git synced 2024-11-18 02:55:10 +00:00
patchtester/administrator/components/com_patchtester/PatchTester/Helper.php

63 lines
1.5 KiB
PHP
Raw Normal View History

<?php
/**
* Patch testing component for the Joomla! CMS
*
2017-01-21 19:54:53 +00:00
* @copyright Copyright (C) 2011 - 2012 Ian MacLennan, Copyright (C) 2013 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later
*/
namespace PatchTester;
2014-05-03 02:02:38 +00:00
use Joomla\Registry\Registry;
use PatchTester\GitHub\GitHub;
2014-05-03 02:02:38 +00:00
/**
* Helper class for the patch tester component
*
* @since 2.0
*/
abstract class Helper
{
/**
* Initializes the GitHub object
*
* @return GitHub
*
* @since 2.0
*/
public static function initializeGithub()
{
$params = \JComponentHelper::getParams('com_patchtester');
2014-05-03 02:02:38 +00:00
$options = new Registry;
// Set a user agent for the request
$options->set('userAgent', 'PatchTester/3.0');
// Set the default timeout to 120 seconds
$options->set('timeout', 120);
// Set the API URL
$options->set('api.url', 'https://api.github.com');
// If an API token is set in the params, use it for authentication
if ($params->get('gh_token', ''))
{
$options->set('gh.token', $params->get('gh_token', ''));
}
// Set the username and password if set in the params
elseif ($params->get('gh_user', '') && $params->get('gh_password'))
{
$options->set('api.username', $params->get('gh_user', ''));
$options->set('api.password', $params->get('gh_password', ''));
}
// Display a message about the lowered API limit without credentials
else
{
\JFactory::getApplication()->enqueueMessage(\JText::_('COM_PATCHTESTER_NO_CREDENTIALS'), 'notice');
}
return new GitHub($options);
}
}