33
0
mirror of https://github.com/joomla-extensions/patchtester.git synced 2024-12-22 02:49:01 +00:00

Refactor to use Joomla 4 structure step 1 WIP

Signed-off-by: Roland Dalmulder <contact@rolandd.com>
This commit is contained in:
Roland Dalmulder 2023-08-17 22:01:47 +02:00
parent cfcfdf440d
commit 63510fe4f9
No known key found for this signature in database
GPG Key ID: 6D30CD38749A5B9E
31 changed files with 181 additions and 106 deletions

View File

@ -1,36 +0,0 @@
<?php
/**
* Patch testing component for the Joomla! CMS
*
* @copyright Copyright (C) 2011 - 2012 Ian MacLennan, Copyright (C) 2013 - 2018 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later
*/
\defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
if (!Factory::getUser()->authorise('core.manage', 'com_patchtester')) {
throw new RuntimeException(Text::_('JERROR_ALERTNOAUTHOR'), 403);
}
// Application reference
$app = Factory::getApplication();
// Import our Composer autoloader to load the component classes
require_once __DIR__ . '/vendor/autoload.php';
// Build the controller class name based on task
$task = $app->input->getCmd('task', 'display');
// If $task is an empty string, apply our default since JInput might not
if ($task === '') {
$task = 'display';
}
$class = '\\PatchTester\\Controller\\' . ucfirst(strtolower($task)) . 'Controller';
if (!class_exists($class)) {
throw new InvalidArgumentException(Text::sprintf('JLIB_APPLICATION_ERROR_INVALID_CONTROLLER_CLASS', $class), 404);
}
// Instantiate and execute the controller
/** @var \PatchTester\Controller\AbstractController $controller */
$controller = new $class($app);
$controller->execute();

View File

@ -9,6 +9,7 @@
<authorUrl>https://www.joomla.org</authorUrl>
<version>4.2.2</version>
<description>COM_PATCHTESTER_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Component\Patchtester</namespace>
<scriptfile>script.php</scriptfile>
<install>
<sql>
@ -38,7 +39,7 @@
<folder>js</folder>
</media>
<administration>
<menu img="../media/com_patchtester/images/icon-16-patchtester.png">com_patchtester</menu>
<menu img="../media/com_patchtester/images/icon-16-patchtester.png" view="pulls">com_patchtester</menu>
<files folder="admin">
<folder>backups</folder>
<folder>forms</folder>
@ -48,7 +49,6 @@
<folder>vendor</folder>
<filename>access.xml</filename>
<filename>config.xml</filename>
<filename>patchtester.php</filename>
</files>
</administration>
<updateservers>

View File

@ -0,0 +1,54 @@
<?php
/**
* Patch testing component for the Joomla! CMS
*
* @copyright Copyright (C) 2011 - 2012 Ian MacLennan, Copyright (C) 2013 - 2018 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later
*/
defined('_JEXEC') or die;
use Joomla\CMS\Dispatcher\ComponentDispatcherFactoryInterface;
use Joomla\CMS\Extension\ComponentInterface;
use Joomla\CMS\Extension\Service\Provider\ComponentDispatcherFactory;
use Joomla\CMS\Extension\Service\Provider\MVCFactory;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\Component\Patchtester\Administrator\Extension\PatchtesterComponent;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
/**
* The patch tester service provider.
*
* @since 4.0.0
*/
return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since 4.0.0
*/
public function register(Container $container)
{
$container->registerServiceProvider(new MVCFactory('\\Joomla\\Component\\Patchtester'));
$container->registerServiceProvider(new ComponentDispatcherFactory('\\Joomla\\Component\\Patchtester'));
$container->set(
ComponentInterface::class,
function (Container $container) {
require_once dirname(__DIR__) . '/vendor/autoload.php';
$component = new PatchtesterComponent($container->get(ComponentDispatcherFactoryInterface::class));
$component->setMVCFactory($container->get(MVCFactoryInterface::class));
return $component;
}
);
}
};

View File

@ -7,20 +7,22 @@
* @license GNU General Public License version 2 or later
*/
namespace PatchTester\Controller;
namespace Joomla\Component\Patchtester\Administrator\Controller;
use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\Component\Patchtester\Administrator\Model\AbstractModel;
use Joomla\Input\Input;
use Joomla\Registry\Registry;
use PatchTester\Model\AbstractModel;
/**
* Base controller for the patch testing component
*
* @since 2.0
*/
abstract class AbstractController
abstract class AbstractController extends BaseController
{
/**
* The active application
@ -50,7 +52,7 @@ abstract class AbstractController
*
* @since 2.0
*/
public function __construct(CMSApplication $app)
public function __construct($config = array(), MVCFactoryInterface $factory = null, ?CMSApplication $app = null, ?Input $input = null)
{
$this->app = $app;
// Set the context for the controller

View File

@ -7,12 +7,12 @@
* @license GNU General Public License version 2 or later
*/
namespace PatchTester\Controller;
namespace Joomla\Component\Patchtester\Administrator\Controller;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;
use PatchTester\Model\PullModel;
use Joomla\Component\Patchtester\Administrator\Model\PullModel;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;

View File

@ -7,12 +7,12 @@
* @license GNU General Public License version 2 or later
*/
namespace PatchTester\Controller;
namespace Joomla\Component\Patchtester\Administrator\Controller;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\Registry\Registry;
use PatchTester\Model\AbstractModel;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
@ -24,8 +24,16 @@ use PatchTester\Model\AbstractModel;
*
* @since 2.0
*/
class DisplayController extends AbstractController
class DisplayController extends BaseController
{
/**
* The default view.
*
* @var string
* @since 1.6
*/
protected $default_view = 'pulls';
/**
* Default ordering value
*
@ -41,7 +49,7 @@ class DisplayController extends AbstractController
* @since 2.0
* @throws \RuntimeException
*/
public function execute()
public function executeOld()
{
// Set up variables to build our classes
$view = $this->getInput()->getCmd('view', $this->defaultView);

View File

@ -7,12 +7,12 @@
* @license GNU General Public License version 2 or later
*/
namespace PatchTester\Controller;
namespace Joomla\Component\Patchtester\Administrator\Controller;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Response\JsonResponse;
use PatchTester\Model\PullsModel;
use Joomla\Component\Patchtester\Administrator\Model\PullsModel;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;

View File

@ -7,17 +7,17 @@
* @license GNU General Public License version 2 or later
*/
namespace PatchTester\Controller;
namespace Joomla\Component\Patchtester\Administrator\Controller;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Filesystem\Folder;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;
use Joomla\Component\Patchtester\Administrator\Model\PullModel;
use Joomla\Component\Patchtester\Administrator\Model\PullsModel;
use Joomla\Component\Patchtester\Administrator\Model\TestsModel;
use Joomla\Filesystem\File;
use PatchTester\Model\PullModel;
use PatchTester\Model\PullsModel;
use PatchTester\Model\TestsModel;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;

View File

@ -7,12 +7,12 @@
* @license GNU General Public License version 2 or later
*/
namespace PatchTester\Controller;
namespace Joomla\Component\Patchtester\Administrator\Controller;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;
use PatchTester\Model\PullModel;
use Joomla\Component\Patchtester\Administrator\Model\PullModel;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;

View File

@ -7,14 +7,14 @@
* @license GNU General Public License version 2 or later
*/
namespace PatchTester\Controller;
namespace Joomla\Component\Patchtester\Administrator\Controller;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Response\JsonResponse;
use Joomla\CMS\Session\Session;
use PatchTester\Helper;
use PatchTester\Model\TestsModel;
use Joomla\Component\Patchtester\Administrator\Helper\Helper;
use Joomla\Component\Patchtester\Administrator\Model\TestsModel;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;

View File

@ -0,0 +1,44 @@
<?php
/**
* Patch testing component for the Joomla! CMS
*
* @copyright Copyright (C) 2011 - 2012 Ian MacLennan, Copyright (C) 2013 - 2018 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later
*/
namespace Joomla\Component\Patchtester\Administrator\Extension;
use Joomla\CMS\Extension\BootableExtensionInterface;
use Joomla\CMS\Extension\MVCComponent;
use Psr\Container\ContainerInterface;
// phpcs:disable PSR1.Files.SideEffects
\defined('JPATH_PLATFORM') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Component class for com_contact
*
* @since 4.0.0
*/
class PatchtesterComponent extends MVCComponent
implements BootableExtensionInterface
{
/**
* Booting the extension. This is the function to set up the environment of the extension like
* registering new class loaders, etc.
*
* If required, some initial set up can be done from services of the container, eg.
* registering HTML services.
*
* @param ContainerInterface $container The container
*
* @return void
*
* @since 4.0.0
*/
public function boot(ContainerInterface $container)
{
}
}

View File

@ -7,7 +7,7 @@
* @license GNU General Public License version 2 or later
*/
namespace PatchTester\Field;
namespace Joomla\Component\Patchtester\Administrator\Field;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\Field\ListField;

View File

@ -7,7 +7,7 @@
* @license GNU General Public License version 2 or later
*/
namespace PatchTester\Field;
namespace Joomla\Component\Patchtester\Administrator\Field;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\Field\ListField;

View File

@ -7,7 +7,7 @@
* @license GNU General Public License version 2 or later
*/
namespace PatchTester\GitHub\Exception;
namespace Joomla\Component\Patchtester\Administrator\Github\Exception;
use Joomla\CMS\Http\Response;

View File

@ -7,12 +7,13 @@
* @license GNU General Public License version 2 or later
*/
namespace PatchTester\GitHub;
namespace Joomla\Component\Patchtester\Administrator\GitHub;
use Joomla\CMS\Http\Http;
use Joomla\CMS\Http\HttpFactory;
use Joomla\CMS\Http\Response;
use Joomla\CMS\Uri\Uri;
use Joomla\Component\Patchtester\Administrator\Github\Exception\UnexpectedResponse;
use Joomla\Registry\Registry;
/**
@ -150,8 +151,8 @@ class GitHub
*
* @return Response
*
* @since 3.0.0
* @throws Exception\UnexpectedResponse
* @throws UnexpectedResponse
*@since 3.0.0
*/
protected function processResponse(Response $response, $expectedCode = 200)
{
@ -162,7 +163,7 @@ class GitHub
$error = isset($body->error) ? $body->error
: (isset($body->message) ? $body->message : 'Unknown Error');
throw new Exception\UnexpectedResponse(
throw new UnexpectedResponse(
$response,
$error,
$response->code

View File

@ -7,13 +7,13 @@
* @license GNU General Public License version 2 or later
*/
namespace PatchTester;
namespace Joomla\Component\Patchtester\Administrator\Helper;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\Registry\Registry;
use PatchTester\GitHub\GitHub;
use src\GitHub\GitHub;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;

View File

@ -7,7 +7,7 @@
* @license GNU General Public License version 2 or later
*/
namespace PatchTester;
namespace Joomla\Component\Patchtester\Administrator\Helper;
/**
* Helper class for Joomla's issue tracker integrations

View File

@ -7,7 +7,7 @@
* @license GNU General Public License version 2 or later
*/
namespace PatchTester\Model;
namespace Joomla\Component\Patchtester\Administrator\Model;
use Joomla\CMS\Factory;
use Joomla\Database\DatabaseDriver;

View File

@ -7,9 +7,10 @@
* @license GNU General Public License version 2 or later
*/
namespace PatchTester\Model;
namespace Joomla\Component\Patchtester\Administrator\Model;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

View File

@ -7,7 +7,7 @@
* @license GNU General Public License version 2 or later
*/
namespace PatchTester\Model;
namespace Joomla\Component\Patchtester\Administrator\Model;
use Joomla\Archive\Zip;
use Joomla\CMS\Component\ComponentHelper;
@ -16,14 +16,14 @@ use Joomla\CMS\Filesystem\Path;
use Joomla\CMS\Http\HttpFactory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Version;
use Joomla\Component\Patchtester\Administrator\Helper\Helper;
use Joomla\Database\DatabaseDriver;
use Joomla\Filesystem\File;
use Joomla\Filesystem\Folder;
use Joomla\Registry\Registry;
use PatchTester\GitHub\Exception\UnexpectedResponse;
use PatchTester\GitHub\GitHub;
use PatchTester\Helper;
use RuntimeException;
use src\GitHub\Exception\UnexpectedResponse;
use src\GitHub\GitHub;
use stdClass;
// phpcs:disable PSR1.Files.SideEffects

View File

@ -7,15 +7,15 @@
* @license GNU General Public License version 2 or later
*/
namespace PatchTester\Model;
namespace Joomla\Component\Patchtester\Administrator\Model;
use Exception;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Model\ListModel;
use Joomla\Component\Patchtester\Administrator\Github\Exception\UnexpectedResponse;
use Joomla\Component\Patchtester\Administrator\Helper\Helper;
use Joomla\Database\DatabaseQuery;
use PatchTester\GitHub\Exception\UnexpectedResponse;
use PatchTester\Helper;
use RuntimeException;
// phpcs:disable PSR1.Files.SideEffects

View File

@ -7,9 +7,10 @@
* @license GNU General Public License version 2 or later
*/
namespace PatchTester\Model;
namespace Joomla\Component\Patchtester\Administrator\Model;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

View File

@ -7,11 +7,13 @@
* @license GNU General Public License version 2 or later
*/
namespace PatchTester\View;
namespace Joomla\Component\Patchtester\Administrator\View;
use Joomla\CMS\Filesystem\Path;
use Joomla\CMS\Language\Text;
use PatchTester\Model\AbstractModel;
use Joomla\Component\Patchtester\Administrator\Model\AbstractModel;
use PatchTester\View\RuntimeException;
use PatchTester\View\SplPriorityQueue;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;

View File

@ -7,9 +7,9 @@
* @license GNU General Public License version 2 or later
*/
namespace PatchTester\View;
namespace Joomla\Component\Patchtester\Administrator\View;
use PatchTester\Model\AbstractModel;
use Joomla\Component\Patchtester\Administrator\Model\AbstractModel;
/**
* Base view for the patch testing component

View File

@ -7,9 +7,10 @@
* @license GNU General Public License version 2 or later
*/
namespace PatchTester\View;
namespace Joomla\Component\Patchtester\Administrator\View;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

View File

@ -15,7 +15,7 @@ use Joomla\CMS\Language\Text;
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/** @var \PatchTester\View\DefaultHtmlView $this */
/** @var \Joomla\Component\Patchtester\Administrator\View\DefaultHtmlView $this */
HTMLHelper::_('jquery.framework');
HTMLHelper::_('behavior.core');

View File

@ -7,17 +7,17 @@
* @license GNU General Public License version 2 or later
*/
namespace PatchTester\View\Pulls;
namespace Joomla\Component\Patchtester\Administrator\View\Pulls;
use Exception;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\Pagination\Pagination;
use Joomla\CMS\Toolbar\Toolbar;
use Joomla\CMS\Toolbar\ToolbarHelper;
use Joomla\Component\Patchtester\Administrator\Helper\TrackerHelper;
use Joomla\Registry\Registry;
use PatchTester\TrackerHelper;
use PatchTester\View\DefaultHtmlView;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
@ -28,9 +28,9 @@ use PatchTester\View\DefaultHtmlView;
*
* @since 2.0
*
* @property-read \PatchTester\Model\PullsModel $model The model object.
* @property-read \Joomla\Component\Patchtester\Administrator\Model\PullsModel $model The model object.
*/
class PullsHtmlView extends DefaultHtmlView
class HtmlView extends BaseHtmlView
{
/**
* Array containing environment errors
@ -84,12 +84,12 @@ class PullsHtmlView extends DefaultHtmlView
/**
* Method to render the view.
*
* @return string The rendered view.
* @return void
*
* @since 2.0.0
* @throws Exception
*/
public function render(): string
public function display($tpl = null): void
{
if (!extension_loaded('openssl')) {
$this->envErrors[] = Text::_('COM_PATCHTESTER_REQUIREMENT_OPENSSL');
@ -100,11 +100,12 @@ class PullsHtmlView extends DefaultHtmlView
}
if (!count($this->envErrors)) {
$this->state = $this->model->getState();
$this->items = $this->model->getItems();
$this->pagination = $this->model->getPagination();
$this->filterForm = $this->model->getFilterForm();
$this->activeFilters = $this->model->getActiveFilters();
$model = $this->getModel();
$this->state = $model->getState();
$this->items = $model->getItems();
$this->pagination = $model->getPagination();
$this->filterForm = $model->getFilterForm();
$this->activeFilters = $model->getActiveFilters();
$this->trackerAlias = TrackerHelper::getTrackerAlias($this->state->get('github_user'), $this->state->get('github_repo'));
}
@ -115,7 +116,8 @@ class PullsHtmlView extends DefaultHtmlView
$this->addToolbar();
Text::script('COM_PATCHTESTER_CONFIRM_RESET');
return parent::render();
parent::display($tpl);
}
/**

View File

@ -16,7 +16,7 @@ use Joomla\CMS\Router\Route;
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/** @var \PatchTester\View\Pulls\PullsHtmlView $this */
/** @var \Joomla\Component\Patchtester\Administrator\View\Pulls\PullsHtmlView $this */
HTMLHelper::_('stylesheet', 'com_patchtester/octicons.css', ['version' => '3.5.0', 'relative' => true]);
HTMLHelper::_('script', 'com_patchtester/patchtester.js', ['version' => 'auto', 'relative' => true]);

View File

@ -8,7 +8,7 @@
*/
use Joomla\CMS\Language\Text;
use PatchTester\View\Pulls\PullsHtmlView;
use Joomla\Component\Patchtester\Administrator\View\Pulls\PullsHtmlView;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;

View File

@ -13,7 +13,7 @@ use Joomla\CMS\Language\Text;
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/** @var \PatchTester\View\Pulls\PullsHtmlView $this */
/** @var \Joomla\Component\Patchtester\Administrator\View\Pulls\PullsHtmlView $this */
?>
<h3><?php echo Text::_('COM_PATCHTESTER_REQUIREMENTS_HEADING'); ?></h3>
<p><?php echo Text::_('COM_PATCHTESTER_REQUIREMENTS_NOT_MET'); ?></p>

View File

@ -18,10 +18,5 @@
"require-dev": {
"joomla/crowdin-sync": "dev-master",
"squizlabs/php_codesniffer": "~3.0"
},
"autoload": {
"psr-4": {
"PatchTester\\": "administrator/components/com_patchtester/PatchTester/"
}
}
}