237 lines
5.6 KiB
PHP
Raw Normal View History

2023-10-04 20:28:29 +02:00
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Power;
use Joomla\Registry\Registry as JoomlaRegistry;
2024-07-08 23:13:02 +02:00
use Joomla\CMS\Factory as JoomlaFactory;
use Joomla\Input\Input;
use VDM\Joomla\Utilities\GetHelper;
use VDM\Joomla\Utilities\StringHelper;
use VDM\Joomla\Componentbuilder\Utilities\RepoHelper;
2023-10-04 20:28:29 +02:00
use VDM\Joomla\Componentbuilder\Abstraction\BaseConfig;
/**
* Compiler Configurations
*
* All these functions are accessed via the direct name without the get:
* example: $this->component_code_name calls: $this->getComponentcodename()
*
* All values once called are cached, yet can be updated directly:
* example: $this->component_code_name = 'new_code_name'; // be warned!
*
* @since 3.2.0
*/
class Config extends BaseConfig
{
/**
* The Global Joomla Configuration
*
* @var JoomlaRegistry
* @since 3.2.0
*/
protected JoomlaRegistry $config;
/**
* Constructor
*
2024-07-08 23:13:02 +02:00
* @param Input|null $input Input
* @param JoomlaRegistry|null $params The component parameters
* @param JoomlaRegistry|null $config The Joomla configuration
2023-10-04 20:28:29 +02:00
*
* @throws \Exception
* @since 3.2.0
*/
public function __construct(?Input $input = null, ?JoomlaRegistry $params = null, ?JoomlaRegistry $config = null)
{
parent::__construct($input, $params);
$this->config = $config ?: JoomlaFactory::getConfig();
}
/**
2024-07-08 23:13:02 +02:00
* get Gitea Username
2023-10-04 20:28:29 +02:00
*
* @return string the access token
* @since 3.2.0
*/
2024-07-08 23:13:02 +02:00
protected function getGiteausername(): ?string
2023-10-04 20:28:29 +02:00
{
2024-07-08 23:13:02 +02:00
return $this->params->get('gitea_username');
2023-10-04 20:28:29 +02:00
}
/**
2024-07-08 23:13:02 +02:00
* get Gitea Access Token
2023-10-04 20:28:29 +02:00
*
2024-07-08 23:13:02 +02:00
* @return string the access token
2023-10-04 20:28:29 +02:00
* @since 3.2.0
*/
2024-07-08 23:13:02 +02:00
protected function getGiteatoken(): ?string
2023-10-04 20:28:29 +02:00
{
2024-07-08 23:13:02 +02:00
return $this->params->get('gitea_token');
2023-10-04 20:28:29 +02:00
}
2023-10-24 10:36:39 +02:00
/**
* Get super power core organisation
*
* @return string The super power core organisation
* @since 3.2.0
*/
protected function getSuperpowerscoreorganisation(): string
{
// the VDM default organisation is [joomla]
$organisation = 'joomla';
return $organisation;
}
/**
* Get super power init repos
*
* @return array The init repositories on Gitea
* @since 3.2.0
*/
protected function getSuperpowersinitrepos(): array
{
// some defaults repos we need by JCB
$repos = [];
2024-07-08 23:13:02 +02:00
// get the users own power repo (can overwrite all)
if ($this->gitea_username !== null)
2023-10-24 10:36:39 +02:00
{
2024-07-08 23:13:02 +02:00
$repos[$this->gitea_username . '.super-powers'] = (object) [
'organisation' => $this->gitea_username,
'repository' => 'super-powers',
'read_branch' => 'master'
];
2023-10-24 10:36:39 +02:00
}
2024-07-08 23:13:02 +02:00
$repos[$this->super_powers_core_organisation . '.super-powers'] = (object) [
'organisation' => $this->super_powers_core_organisation,
'repository' => 'super-powers',
'read_branch' => 'master'
];
$repos[$this->super_powers_core_organisation . '.gitea'] = (object) [
'organisation' => $this->super_powers_core_organisation,
'repository' => 'gitea',
'read_branch' => 'master'
];
$repos[$this->super_powers_core_organisation . '.openai'] = (object) [
'organisation' => $this->super_powers_core_organisation,
'repository' => 'openai',
'read_branch' => 'master'
];
2023-10-24 10:36:39 +02:00
return $repos;
}
2023-10-04 20:28:29 +02:00
/**
* get temporary path
*
* @return string The temporary path
* @since 3.2.0
*/
protected function getTmppath(): string
{
// get the temporary path
return $this->config->get('tmp_path');
}
2023-10-24 10:36:39 +02:00
/**
* Get switch to add super powers
*
* @return bool Switch to add super powers
* @since 3.2.0
*/
protected function getAddsuperpowers(): bool
{
return (bool) $this->params->get('powers_repository', 0);
}
/**
* Get switch to add own super powers
*
* @return bool Switch to add own super powers
* @since 3.2.0
*/
protected function getAddownpowers(): bool
{
if ($this->add_super_powers)
{
return (bool) $this->params->get('super_powers_repositories', 0);
}
return false;
}
2023-10-04 20:28:29 +02:00
/**
* Get local super powers repository path
*
* @return string The path to the local repository
* @since 3.2.0
*/
protected function getLocalpowersrepositorypath(): string
{
$default = $this->tmp_path . '/super_powers';
if (!$this->add_super_powers)
{
return $default;
}
2023-10-24 10:36:39 +02:00
return $this->params->get('local_powers_repository_path', $default);
2023-10-04 20:28:29 +02:00
}
/**
* Get super power approved paths
*
* @return array The approved paths to the repositories on Gitea
* @since 3.2.0
*/
protected function getApprovedpaths(): array
{
2023-10-24 10:36:39 +02:00
// some defaults repos we need by JCB
$approved = $this->super_powers_init_repos;
2023-10-04 20:28:29 +02:00
2024-07-08 23:13:02 +02:00
$paths = RepoHelper::get(1); // super powers = 1
2023-10-04 20:28:29 +02:00
2024-07-08 23:13:02 +02:00
if ($paths !== null)
2023-10-04 20:28:29 +02:00
{
foreach ($paths as $path)
{
2024-07-08 23:13:02 +02:00
$owner = $path->organisation ?? null;
$repo = $path->repository ?? null;
2023-10-24 10:36:39 +02:00
if ($owner !== null && $repo !== null)
{
// we make sure to get only the objects
$approved = ["{$owner}.{$repo}" => $path] + $approved;
}
2023-10-04 20:28:29 +02:00
}
}
2023-10-24 10:36:39 +02:00
return array_values($approved);
2024-07-08 23:13:02 +02:00
}
/**
* get indentation value
*
* @return string Indentation value
* @since 3.2.2
*/
protected function getIndentationvalue(): string
{
return "\t";
2023-10-04 20:28:29 +02:00
}
}