Release of v5.0.1-alpha5
Add repositories for better integration with gitea. Refactored the Data classes. Add new Data classes.
This commit is contained in:
@ -189,16 +189,22 @@ abstract class Grep implements GrepInterface
|
||||
{
|
||||
foreach ($this->paths as $n => &$path)
|
||||
{
|
||||
if (isset($path->owner) && strlen($path->owner) > 1 &&
|
||||
isset($path->repo) && strlen($path->repo) > 1)
|
||||
if (isset($path->organisation) && strlen($path->organisation) > 1 &&
|
||||
isset($path->repository) && strlen($path->repository) > 1)
|
||||
{
|
||||
// build the path
|
||||
$path->path = trim($path->owner) . '/' . trim($path->repo);
|
||||
$path->path = trim($path->organisation) . '/' . trim($path->repository);
|
||||
|
||||
// update the branch
|
||||
if ($path->branch === 'default' || empty($path->branch))
|
||||
if ($path->read_branch === 'default' || empty($path->read_branch))
|
||||
{
|
||||
$path->branch = null;
|
||||
$path->read_branch = null;
|
||||
}
|
||||
|
||||
// only update the write branch if set
|
||||
if (isset($path->write_branch) && ($path->write_branch === 'default' || empty($path->write_branch)))
|
||||
{
|
||||
$path->write_branch = null;
|
||||
}
|
||||
|
||||
// set local path
|
||||
|
@ -15,6 +15,7 @@ namespace VDM\Joomla\Abstraction;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Interfaces\Tableinterface as Table;
|
||||
use VDM\Joomla\Interfaces\ModelInterface;
|
||||
|
||||
|
||||
/**
|
||||
@ -22,7 +23,7 @@ use VDM\Joomla\Interfaces\Tableinterface as Table;
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
abstract class Model
|
||||
abstract class Model implements ModelInterface
|
||||
{
|
||||
/**
|
||||
* Last ID
|
||||
@ -40,16 +41,57 @@ abstract class Model
|
||||
*/
|
||||
protected Table $table;
|
||||
|
||||
/**
|
||||
* Table Name
|
||||
*
|
||||
* @var string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected string $tableName;
|
||||
|
||||
/**
|
||||
* The switch to control the behaviour of empty values
|
||||
*
|
||||
* @var bool
|
||||
* @since 3.2.2
|
||||
*/
|
||||
protected bool $allowEmpty = true;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Table $table The search table object.
|
||||
* @param Table $table The search table object.
|
||||
* @param string|null $tableName The table
|
||||
* @param bool|null $allowEmpty The switch to control the behaviour of empty values (default true)
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(Table $table)
|
||||
public function __construct(Table $table, ?string $tableName = null, bool $allowEmpty = null)
|
||||
{
|
||||
$this->table = $table;
|
||||
if ($tableName !== null)
|
||||
{
|
||||
$this->setTable($tableName);
|
||||
}
|
||||
if ($allowEmpty !== null)
|
||||
{
|
||||
$this->setAllowEmpty($allowEmpty);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current active table
|
||||
*
|
||||
* @param string $table The table that should be active
|
||||
*
|
||||
* @return self
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function table(string $table): self
|
||||
{
|
||||
$this->setTable($table);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -309,6 +351,54 @@ abstract class Model
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current active table
|
||||
*
|
||||
* @param string $tableName The table name
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function setTable(string $tableName): void
|
||||
{
|
||||
$this->tableName = $tableName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the switch to control the behaviour of empty values
|
||||
*
|
||||
* @param bool $allowEmpty The switch
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function setAllowEmpty(bool $allowEmpty): void
|
||||
{
|
||||
$this->allowEmpty = $allowEmpty;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current active table
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getTable(): string
|
||||
{
|
||||
return $this->tableName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the switch to control the behaviour of empty values
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.2
|
||||
*/
|
||||
protected function getAllowEmpty(): bool
|
||||
{
|
||||
return $this->allowEmpty;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current active table's fields (including defaults)
|
||||
*
|
||||
@ -345,14 +435,6 @@ abstract class Model
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
abstract protected function validateAfter(&$value, ?string $field = null, ?string $table = null): bool;
|
||||
|
||||
/**
|
||||
* Get the current active table
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
abstract protected function getTable(): string;
|
||||
abstract protected function validateAfter(&$value, ?string $field = null, ?string $table = null): bool;
|
||||
}
|
||||
|
||||
|
@ -13,9 +13,11 @@ namespace VDM\Joomla\Componentbuilder\Compiler;
|
||||
|
||||
|
||||
use Joomla\Registry\Registry as JoomlaRegistry;
|
||||
use Joomla\CMS\Factory as JoomlaFactory;
|
||||
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;
|
||||
use VDM\Joomla\Componentbuilder\Abstraction\BaseConfig;
|
||||
|
||||
|
||||
@ -43,9 +45,9 @@ class Config extends BaseConfig
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Input|null $input Input
|
||||
* @param Registry|null $params The component parameters
|
||||
* @param Registry|null $config The Joomla configuration
|
||||
* @param Input|null $input Input
|
||||
* @param JoomlaRegistry|null $params The component parameters
|
||||
* @param JoomlaRegistry|null $config The Joomla configuration
|
||||
*
|
||||
* @throws \Exception
|
||||
* @since 3.2.0
|
||||
@ -65,7 +67,7 @@ class Config extends BaseConfig
|
||||
*/
|
||||
protected function getGiteausername(): ?string
|
||||
{
|
||||
return $this->custom_gitea_username ?? $this->params->get('gitea_username');
|
||||
return $this->params->get('gitea_username');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -76,66 +78,7 @@ class Config extends BaseConfig
|
||||
*/
|
||||
protected function getGiteatoken(): ?string
|
||||
{
|
||||
return $this->custom_gitea_token ?? $this->params->get('gitea_token');
|
||||
}
|
||||
|
||||
/**
|
||||
* get Add Custom Gitea URL
|
||||
*
|
||||
* @return int the add switch
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getAddcustomgiteaurl(): int
|
||||
{
|
||||
return $this->params->get('add_custom_gitea_url', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* get Custom Gitea URL
|
||||
*
|
||||
* @return string the custom gitea url
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getCustomgiteaurl(): ?string
|
||||
{
|
||||
if ($this->add_custom_gitea_url == 2)
|
||||
{
|
||||
return $this->params->get('custom_gitea_url');
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* get Custom Gitea Username
|
||||
*
|
||||
* @return string the custom access token
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getCustomgiteausername(): ?string
|
||||
{
|
||||
if ($this->add_custom_gitea_url == 2)
|
||||
{
|
||||
return $this->params->get('custom_gitea_username');
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* get Custom Gitea Access Token
|
||||
*
|
||||
* @return string the custom access token
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getCustomgiteatoken(): ?string
|
||||
{
|
||||
if ($this->add_custom_gitea_url == 2)
|
||||
{
|
||||
return $this->params->get('custom_gitea_token');
|
||||
}
|
||||
|
||||
return null;
|
||||
return $this->params->get('gitea_token');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -149,11 +92,6 @@ class Config extends BaseConfig
|
||||
// the VDM default organisation is [joomla]
|
||||
$organisation = 'joomla';
|
||||
|
||||
if ($this->add_custom_gitea_url == 2)
|
||||
{
|
||||
return $this->params->get('super_powers_core_organisation', $organisation);
|
||||
}
|
||||
|
||||
return $organisation;
|
||||
}
|
||||
|
||||
@ -168,45 +106,66 @@ class Config extends BaseConfig
|
||||
// some defaults repos we need by JCB
|
||||
$repos = [];
|
||||
|
||||
// only add custom init with custom gitea
|
||||
$paths = null;
|
||||
if ($this->add_custom_gitea_url == 2)
|
||||
{
|
||||
$paths = $this->params->get('super_powers_core_repos');
|
||||
}
|
||||
|
||||
// get the users own power repo (can overwrite all)
|
||||
if (!empty($this->gitea_username))
|
||||
if ($this->gitea_username !== null)
|
||||
{
|
||||
$repos[$this->gitea_username . '.super-powers'] = (object) ['owner' => $this->gitea_username, 'repo' => 'super-powers', 'branch' => 'master'];
|
||||
$repos[$this->gitea_username . '.super-powers'] = (object) [
|
||||
'organisation' => $this->gitea_username,
|
||||
'repository' => 'super-powers',
|
||||
'read_branch' => 'master'
|
||||
];
|
||||
}
|
||||
|
||||
if (!empty($paths) && is_array($paths))
|
||||
{
|
||||
foreach ($paths as $path)
|
||||
{
|
||||
$owner = $path->owner ?? null;
|
||||
$repo = $path->repo ?? null;
|
||||
if ($owner !== null && $repo !== null)
|
||||
{
|
||||
// we make sure to get only the objects
|
||||
$repos = ["{$owner}.{$repo}" => $path] + $repos;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$repos[$this->super_powers_core_organisation . '.super-powers'] = (object) ['owner' => $this->super_powers_core_organisation, 'repo' => 'super-powers', 'branch' => 'master'];
|
||||
$repos[$this->super_powers_core_organisation . '.jcb-compiler'] = (object) ['owner' => $this->super_powers_core_organisation, 'repo' => 'jcb-compiler', 'branch' => 'master'];
|
||||
$repos[$this->super_powers_core_organisation . '.jcb-packager'] = (object) ['owner' => $this->super_powers_core_organisation, 'repo' => 'jcb-packager', 'branch' => 'master'];
|
||||
$repos[$this->super_powers_core_organisation . '.phpseclib'] = (object) ['owner' => $this->super_powers_core_organisation, 'repo' => 'phpseclib', 'branch' => 'master'];
|
||||
$repos[$this->super_powers_core_organisation . '.search'] = (object) ['owner' => $this->super_powers_core_organisation, 'repo' => 'search', 'branch' => 'master'];
|
||||
$repos[$this->super_powers_core_organisation . '.gitea'] = (object) ['owner' => $this->super_powers_core_organisation, 'repo' => 'gitea', 'branch' => 'master'];
|
||||
$repos[$this->super_powers_core_organisation . '.openai'] = (object) ['owner' => $this->super_powers_core_organisation, 'repo' => 'openai', 'branch' => 'master'];
|
||||
$repos[$this->super_powers_core_organisation . '.minify'] = (object) ['owner' => $this->super_powers_core_organisation, 'repo' => 'minify', 'branch' => 'master'];
|
||||
$repos[$this->super_powers_core_organisation . '.psr'] = (object) ['owner' => $this->super_powers_core_organisation, 'repo' => 'psr', 'branch' => 'master'];
|
||||
$repos[$this->super_powers_core_organisation . '.fof'] = (object) ['owner' => $this->super_powers_core_organisation, 'repo' => 'fof', 'branch' => 'master'];
|
||||
}
|
||||
$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 . '.jcb-compiler'] = (object) [
|
||||
'organisation' => $this->super_powers_core_organisation,
|
||||
'repository' => 'jcb-compiler',
|
||||
'read_branch' => 'master'
|
||||
];
|
||||
$repos[$this->super_powers_core_organisation . '.jcb-packager'] = (object) [
|
||||
'organisation' => $this->super_powers_core_organisation,
|
||||
'repository' => 'jcb-packager',
|
||||
'read_branch' => 'master'
|
||||
];
|
||||
$repos[$this->super_powers_core_organisation . '.phpseclib'] = (object) [
|
||||
'organisation' => $this->super_powers_core_organisation,
|
||||
'repository' => 'phpseclib',
|
||||
'read_branch' => 'master'
|
||||
];
|
||||
$repos[$this->super_powers_core_organisation . '.search'] = (object) [
|
||||
'organisation' => $this->super_powers_core_organisation,
|
||||
'repository' => 'search',
|
||||
'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'
|
||||
];
|
||||
$repos[$this->super_powers_core_organisation . '.minify'] = (object) [
|
||||
'organisation' => $this->super_powers_core_organisation,
|
||||
'repository' => 'minify',
|
||||
'read_branch' => 'master'
|
||||
];
|
||||
$repos[$this->super_powers_core_organisation . '.psr'] = (object) [
|
||||
'organisation' => $this->super_powers_core_organisation,
|
||||
'repository' => 'psr',
|
||||
'read_branch' => 'master'
|
||||
];
|
||||
$repos[$this->super_powers_core_organisation . '.fof'] = (object) [
|
||||
'organisation' => $this->super_powers_core_organisation,
|
||||
'repository' => 'fof',
|
||||
'read_branch' => 'master'
|
||||
];
|
||||
|
||||
return $repos;
|
||||
}
|
||||
@ -830,19 +789,14 @@ class Config extends BaseConfig
|
||||
// some defaults repos we need by JCB
|
||||
$approved = $this->super_powers_core_repos;
|
||||
|
||||
if (!$this->add_own_powers)
|
||||
{
|
||||
return array_values($approved);
|
||||
}
|
||||
$paths = RepoHelper::get(1); // super powers = 1
|
||||
|
||||
$paths = $this->params->get('approved_paths');
|
||||
|
||||
if (!empty($paths))
|
||||
if ($paths !== null)
|
||||
{
|
||||
foreach ($paths as $path)
|
||||
{
|
||||
$owner = $path->owner ?? null;
|
||||
$repo = $path->repo ?? null;
|
||||
$owner = $path->organisation ?? null;
|
||||
$repo = $path->repository ?? null;
|
||||
if ($owner !== null && $repo !== null)
|
||||
{
|
||||
// we make sure to get only the objects
|
||||
@ -879,11 +833,19 @@ class Config extends BaseConfig
|
||||
// some defaults repos we need by JCB
|
||||
$repos = [];
|
||||
// get the users own power repo (can overwrite all)
|
||||
if (!empty($this->gitea_username))
|
||||
if ($this->gitea_username !== null)
|
||||
{
|
||||
$repos[$this->gitea_username . '.joomla-powers'] = (object) ['owner' => $this->gitea_username, 'repo' => 'joomla-powers', 'branch' => 'master'];
|
||||
$repos[$this->gitea_username . '.joomla-powers'] = (object) [
|
||||
'organisation' => $this->gitea_username,
|
||||
'repository' => 'joomla-powers',
|
||||
'read_branch' => 'master'
|
||||
];
|
||||
}
|
||||
$repos[$this->joomla_powers_core_organisation . '.joomla-powers'] = (object) ['owner' => $this->joomla_powers_core_organisation, 'repo' => 'joomla-powers', 'branch' => 'master'];
|
||||
$repos[$this->joomla_powers_core_organisation . '.joomla-powers'] = (object) [
|
||||
'organisation' => $this->joomla_powers_core_organisation,
|
||||
'repository' => 'joomla-powers',
|
||||
'read_branch' => 'master'
|
||||
];
|
||||
|
||||
return $repos;
|
||||
}
|
||||
|
@ -15,7 +15,9 @@ namespace VDM\Joomla\Componentbuilder\Compiler;
|
||||
use Joomla\DI\Container;
|
||||
use VDM\Joomla\Componentbuilder\Service\Crypt;
|
||||
use VDM\Joomla\Componentbuilder\Service\Server;
|
||||
use VDM\Joomla\Componentbuilder\Service\Database;
|
||||
use VDM\Joomla\Service\Database;
|
||||
use VDM\Joomla\Service\Model as BaseModel;
|
||||
use VDM\Joomla\Service\Data;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Service\Model;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Service\Compiler;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Service\Event;
|
||||
@ -149,6 +151,8 @@ abstract class Factory implements FactoryInterface
|
||||
->registerServiceProvider(new Crypt())
|
||||
->registerServiceProvider(new Server())
|
||||
->registerServiceProvider(new Database())
|
||||
->registerServiceProvider(new BaseModel())
|
||||
->registerServiceProvider(new Data())
|
||||
->registerServiceProvider(new Model())
|
||||
->registerServiceProvider(new Compiler())
|
||||
->registerServiceProvider(new Event())
|
||||
|
@ -21,7 +21,6 @@ use VDM\Joomla\Utilities\JsonHelper;
|
||||
use VDM\Joomla\Utilities\GuidHelper;
|
||||
use VDM\Joomla\Utilities\String\ClassfunctionHelper;
|
||||
use VDM\Joomla\Utilities\String\NamespaceHelper;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Factory as Compiler;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Config;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Customcode;
|
||||
@ -102,43 +101,43 @@ class Power implements PowerInterface
|
||||
protected array $retry = [];
|
||||
|
||||
/**
|
||||
* Compiler Config
|
||||
* The Config Class.
|
||||
*
|
||||
* @var Config
|
||||
* @var Config
|
||||
* @since 3.2.0
|
||||
**/
|
||||
*/
|
||||
protected Config $config;
|
||||
|
||||
/**
|
||||
* Compiler Placeholder
|
||||
* The Placeholder Class.
|
||||
*
|
||||
* @var Placeholder
|
||||
* @var Placeholder
|
||||
* @since 3.2.0
|
||||
**/
|
||||
*/
|
||||
protected Placeholder $placeholder;
|
||||
|
||||
/**
|
||||
* Compiler Customcode
|
||||
* The Customcode Class.
|
||||
*
|
||||
* @var Customcode
|
||||
* @var Customcode
|
||||
* @since 3.2.0
|
||||
**/
|
||||
*/
|
||||
protected Customcode $customcode;
|
||||
|
||||
/**
|
||||
* Compiler Customcode in Gui
|
||||
* The Gui Class.
|
||||
*
|
||||
* @var Gui
|
||||
* @var Gui
|
||||
* @since 3.2.0
|
||||
**/
|
||||
*/
|
||||
protected Gui $gui;
|
||||
|
||||
/**
|
||||
* The JCB Superpower class
|
||||
* The Super Class.
|
||||
*
|
||||
* @var Superpower
|
||||
* @var Superpower
|
||||
* @since 3.2.0
|
||||
**/
|
||||
*/
|
||||
protected Superpower $superpower;
|
||||
|
||||
/**
|
||||
@ -158,23 +157,22 @@ class Power implements PowerInterface
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Config|null $config The compiler config object.
|
||||
* @param Placeholder|null $placeholder The compiler placeholder object.
|
||||
* @param Customcode|null $customcode The compiler customcode object.
|
||||
* @param Gui|null $gui The compiler customcode gui object.
|
||||
* @param Superpower|null $superpower The JCB superpower object.
|
||||
* @param Config $config The Config Class.
|
||||
* @param Placeholder $placeholder The Placeholder Class.
|
||||
* @param Customcode $customcode The Customcode Class.
|
||||
* @param Gui $gui The Gui Class.
|
||||
* @param Superpower $superpower The Super Class.
|
||||
*
|
||||
* @throws \Exception
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Config $config = null, ?Placeholder $placeholder = null,
|
||||
?Customcode $customcode = null, ?Gui $gui = null, ?Superpower $superpower = null)
|
||||
public function __construct(Config $config, Placeholder $placeholder,
|
||||
Customcode $customcode, Gui $gui, Superpower $superpower)
|
||||
{
|
||||
$this->config = $config ?: Compiler::_('Config');
|
||||
$this->placeholder = $placeholder ?: Compiler::_('Placeholder');
|
||||
$this->customcode = $customcode ?: Compiler::_('Customcode');
|
||||
$this->gui = $gui ?: Compiler::_('Customcode.Gui');
|
||||
$this->superpower = $superpower ?: Compiler::_('Superpower');
|
||||
$this->config = $config;
|
||||
$this->placeholder = $placeholder;
|
||||
$this->customcode = $customcode;
|
||||
$this->gui = $gui;
|
||||
$this->superpower = $superpower;
|
||||
$this->db = Factory::getDbo();
|
||||
$this->app = Factory::getApplication();
|
||||
}
|
||||
|
@ -19,9 +19,6 @@ use VDM\Joomla\Componentbuilder\JoomlaPower\Grep;
|
||||
use VDM\Joomla\Componentbuilder\JoomlaPower\Super as Superpower;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\JoomlaPower\Extractor;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\JoomlaPower\Injector;
|
||||
use VDM\Joomla\Componentbuilder\JoomlaPower\Model\Upsert;
|
||||
use VDM\Joomla\Componentbuilder\JoomlaPower\Database\Insert;
|
||||
use VDM\Joomla\Componentbuilder\JoomlaPower\Database\Update;
|
||||
|
||||
|
||||
/**
|
||||
@ -55,15 +52,6 @@ class JoomlaPower implements ServiceProviderInterface
|
||||
|
||||
$container->alias(Injector::class, 'Joomla.Power.Injector')
|
||||
->share('Joomla.Power.Injector', [$this, 'getInjector'], true);
|
||||
|
||||
$container->alias(Upsert::class, 'Joomla.Power.Model.Upsert')
|
||||
->share('Joomla.Power.Model.Upsert', [$this, 'getModelUpsert'], true);
|
||||
|
||||
$container->alias(Insert::class, 'Joomla.Power.Insert')
|
||||
->share('Joomla.Power.Insert', [$this, 'getInsert'], true);
|
||||
|
||||
$container->alias(Update::class, 'Joomla.Power.Update')
|
||||
->share('Joomla.Power.Update', [$this, 'getUpdate'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -97,8 +85,7 @@ class JoomlaPower implements ServiceProviderInterface
|
||||
{
|
||||
return new Superpower(
|
||||
$container->get('Joomla.Power.Grep'),
|
||||
$container->get('Joomla.Power.Insert'),
|
||||
$container->get('Joomla.Power.Update')
|
||||
$container->get('Data.Item')
|
||||
);
|
||||
}
|
||||
|
||||
@ -149,53 +136,6 @@ class JoomlaPower implements ServiceProviderInterface
|
||||
$container->get('Power.Parser'),
|
||||
$container->get('Placeholder')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Power Model Upsert
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Upsert
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getModelUpsert(Container $container): Upsert
|
||||
{
|
||||
return new Upsert(
|
||||
$container->get('Table')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Power Insert
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Insert
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getInsert(Container $container): Insert
|
||||
{
|
||||
return new Insert(
|
||||
$container->get('Joomla.Power.Model.Upsert'),
|
||||
$container->get('Insert')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Power Update
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Update
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getUpdate(Container $container): Update
|
||||
{
|
||||
return new Update(
|
||||
$container->get('Joomla.Power.Model.Upsert'),
|
||||
$container->get('Update')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,10 +15,10 @@ namespace VDM\Joomla\Componentbuilder\Compiler\Service;
|
||||
use Joomla\DI\Container;
|
||||
use Joomla\DI\ServiceProviderInterface;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Power as Powers;
|
||||
use VDM\Joomla\Componentbuilder\Power\Grep;
|
||||
use VDM\Joomla\Componentbuilder\Power\Super as Superpower;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Power\Infusion;
|
||||
use VDM\Joomla\Componentbuilder\Power\Grep;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Power\Autoloader;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Power\Infusion;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Power\Structure;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Power\Parser;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Power\Plantuml;
|
||||
@ -26,9 +26,6 @@ use VDM\Joomla\Componentbuilder\Compiler\Power\Repo\Readme as RepoReadme;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Power\Repos\Readme as ReposReadme;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Power\Extractor;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Power\Injector;
|
||||
use VDM\Joomla\Componentbuilder\Power\Model\Upsert;
|
||||
use VDM\Joomla\Componentbuilder\Power\Database\Insert;
|
||||
use VDM\Joomla\Componentbuilder\Power\Database\Update;
|
||||
|
||||
|
||||
/**
|
||||
@ -83,19 +80,10 @@ class Power implements ServiceProviderInterface
|
||||
|
||||
$container->alias(Injector::class, 'Power.Injector')
|
||||
->share('Power.Injector', [$this, 'getInjector'], true);
|
||||
|
||||
$container->alias(Upsert::class, 'Power.Model.Upsert')
|
||||
->share('Power.Model.Upsert', [$this, 'getModelUpsert'], true);
|
||||
|
||||
$container->alias(Insert::class, 'Power.Insert')
|
||||
->share('Power.Insert', [$this, 'getInsert'], true);
|
||||
|
||||
$container->alias(Update::class, 'Power.Update')
|
||||
->share('Power.Update', [$this, 'getUpdate'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Powers
|
||||
* Get The Power Class.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
@ -108,12 +96,13 @@ class Power implements ServiceProviderInterface
|
||||
$container->get('Config'),
|
||||
$container->get('Placeholder'),
|
||||
$container->get('Customcode'),
|
||||
$container->get('Customcode.Gui')
|
||||
$container->get('Customcode.Gui'),
|
||||
$container->get('Superpower')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Superpower
|
||||
* Get The Super Class.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
@ -124,13 +113,12 @@ class Power implements ServiceProviderInterface
|
||||
{
|
||||
return new Superpower(
|
||||
$container->get('Power.Grep'),
|
||||
$container->get('Power.Insert'),
|
||||
$container->get('Power.Update')
|
||||
$container->get('Data.Item')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Grep
|
||||
* Get The Grep Class.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
@ -147,7 +135,7 @@ class Power implements ServiceProviderInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Compiler Autoloader
|
||||
* Get The Autoloader Class.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
@ -164,7 +152,7 @@ class Power implements ServiceProviderInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Compiler Power Infusion
|
||||
* Get The Infusion Class.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
@ -187,7 +175,7 @@ class Power implements ServiceProviderInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Compiler Power Structure Builder
|
||||
* Get The Structure Class.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
@ -210,11 +198,11 @@ class Power implements ServiceProviderInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Compiler Power Parser
|
||||
* Get The Parser Class.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Structure
|
||||
* @return Parser
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getParser(Container $container): Parser
|
||||
@ -223,7 +211,7 @@ class Power implements ServiceProviderInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Compiler Power Plantuml Builder
|
||||
* Get The Plantuml Class.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
@ -236,7 +224,7 @@ class Power implements ServiceProviderInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Compiler Power Repo Readme Builder
|
||||
* Get The Readme Class.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
@ -252,7 +240,7 @@ class Power implements ServiceProviderInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Compiler Power Repos Readme Builder
|
||||
* Get The Readme Class.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
@ -268,7 +256,7 @@ class Power implements ServiceProviderInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Compiler Power Extractor
|
||||
* Get The Extractor Class.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
@ -281,7 +269,7 @@ class Power implements ServiceProviderInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Compiler Power Injector
|
||||
* Get The Injector Class.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
@ -296,53 +284,6 @@ class Power implements ServiceProviderInterface
|
||||
$container->get('Power.Parser'),
|
||||
$container->get('Placeholder')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Power Model Upsert
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Upsert
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getModelUpsert(Container $container): Upsert
|
||||
{
|
||||
return new Upsert(
|
||||
$container->get('Table')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Power Insert
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Insert
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getInsert(Container $container): Insert
|
||||
{
|
||||
return new Insert(
|
||||
$container->get('Power.Model.Upsert'),
|
||||
$container->get('Insert')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Power Update
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Update
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getUpdate(Container $container): Update
|
||||
{
|
||||
return new Update(
|
||||
$container->get('Power.Model.Upsert'),
|
||||
$container->get('Update')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,52 +0,0 @@
|
||||
<?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\Interfaces;
|
||||
|
||||
|
||||
/**
|
||||
* Superpower of JCB
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
interface SuperInterface
|
||||
{
|
||||
/**
|
||||
* Init all power not found in database
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function init(): bool;
|
||||
|
||||
/**
|
||||
* Reset the powers
|
||||
*
|
||||
* @param array $powers The global unique ids of the powers
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function reset(array $powers): bool;
|
||||
|
||||
/**
|
||||
* Load a superpower
|
||||
*
|
||||
* @param string $guid The global unique id of the power
|
||||
* @param array $order The search order
|
||||
* @param string|null $action The action to load power
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function load(string $guid, array $order = ['remote', 'local'], ?string $action = null): bool;
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ class Config extends BaseConfig
|
||||
*/
|
||||
protected function getGiteausername(): ?string
|
||||
{
|
||||
return $this->custom_gitea_username ?? $this->params->get('gitea_username');
|
||||
return $this->params->get('gitea_username');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -76,66 +76,7 @@ class Config extends BaseConfig
|
||||
*/
|
||||
protected function getGiteatoken(): ?string
|
||||
{
|
||||
return $this->custom_gitea_token ?? $this->params->get('gitea_token');
|
||||
}
|
||||
|
||||
/**
|
||||
* get Add Custom Gitea URL
|
||||
*
|
||||
* @return int the add switch
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getAddcustomgiteaurl(): int
|
||||
{
|
||||
return $this->params->get('add_custom_gitea_url', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* get Custom Gitea URL
|
||||
*
|
||||
* @return string the custom gitea url
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getCustomgiteaurl(): ?string
|
||||
{
|
||||
if ($this->add_custom_gitea_url == 2)
|
||||
{
|
||||
return $this->params->get('custom_gitea_url');
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* get Custom Gitea Username
|
||||
*
|
||||
* @return string the custom access token
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getCustomgiteausername(): ?string
|
||||
{
|
||||
if ($this->add_custom_gitea_url == 2)
|
||||
{
|
||||
return $this->params->get('custom_gitea_username');
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* get Custom Gitea Access Token
|
||||
*
|
||||
* @return string the custom access token
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getCustomgiteatoken(): ?string
|
||||
{
|
||||
if ($this->add_custom_gitea_url == 2)
|
||||
{
|
||||
return $this->params->get('custom_gitea_token');
|
||||
}
|
||||
|
||||
return null;
|
||||
return $this->params->get('gitea_token');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -165,9 +106,9 @@ class Config extends BaseConfig
|
||||
// get the users own power repo (can overwrite all)
|
||||
if (!empty($this->gitea_username))
|
||||
{
|
||||
$repos[$this->gitea_username . '.joomla-powers'] = (object) ['owner' => $this->gitea_username, 'repo' => 'joomla-powers', 'branch' => 'master'];
|
||||
$repos[$this->gitea_username . '.joomla-powers'] = (object) ['organisation' => $this->gitea_username, 'repository' => 'joomla-powers', 'read_branch' => 'master'];
|
||||
}
|
||||
$repos[$this->joomla_powers_core_organisation . '.joomla-powers'] = (object) ['owner' => $this->joomla_powers_core_organisation, 'repo' => 'joomla-powers', 'branch' => 'master'];
|
||||
$repos[$this->joomla_powers_core_organisation . '.joomla-powers'] = (object) ['organisation' => $this->joomla_powers_core_organisation, 'repository' => 'joomla-powers', 'read_branch' => 'master'];
|
||||
|
||||
return $repos;
|
||||
}
|
||||
@ -183,7 +124,7 @@ class Config extends BaseConfig
|
||||
// some defaults repos we need by JCB
|
||||
if (!empty($this->gitea_username))
|
||||
{
|
||||
return (object) ['owner' => $this->gitea_username, 'repo' => 'joomla-powers', 'branch' => 'master'];
|
||||
return (object) ['organisation' => $this->gitea_username, 'repository' => 'joomla-powers', 'read_branch' => 'master'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,34 +0,0 @@
|
||||
<?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\JoomlaPower\Database;
|
||||
|
||||
|
||||
use VDM\Joomla\Componentbuilder\Interfaces\Database\InsertInterface;
|
||||
use VDM\Joomla\Componentbuilder\Power\Database\Insert as ExtendingInsert;
|
||||
|
||||
|
||||
/**
|
||||
* Joomla Power Database Insert
|
||||
*
|
||||
* @since 3.2.1
|
||||
*/
|
||||
final class Insert extends ExtendingInsert implements InsertInterface
|
||||
{
|
||||
/**
|
||||
* Table Name
|
||||
*
|
||||
* @var string
|
||||
* @since 3.2.1
|
||||
*/
|
||||
protected string $table = 'power';
|
||||
}
|
||||
|
@ -1,34 +0,0 @@
|
||||
<?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\JoomlaPower\Database;
|
||||
|
||||
|
||||
use VDM\Joomla\Componentbuilder\Power\Database\LoadInterface;
|
||||
use VDM\Joomla\Componentbuilder\Power\Database\Load as ExtendingLoad;
|
||||
|
||||
|
||||
/**
|
||||
* Power Database Load
|
||||
*
|
||||
* @since 2.0.1
|
||||
*/
|
||||
final class Load extends ExtendingLoad implements LoadInterface
|
||||
{
|
||||
/**
|
||||
* Table Name
|
||||
*
|
||||
* @var string
|
||||
* @since 3.2.1
|
||||
*/
|
||||
protected string $table = 'joomla_power';
|
||||
}
|
||||
|
@ -1,34 +0,0 @@
|
||||
<?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\JoomlaPower\Database;
|
||||
|
||||
|
||||
use VDM\Joomla\Componentbuilder\Interfaces\Database\UpdateInterface;
|
||||
use VDM\Joomla\Componentbuilder\Power\Database\Update as ExtendingUpdate;
|
||||
|
||||
|
||||
/**
|
||||
* Joomla Power Database Update
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
final class Update extends ExtendingUpdate implements UpdateInterface
|
||||
{
|
||||
/**
|
||||
* Table Name
|
||||
*
|
||||
* @var string
|
||||
* @since 3.2.1
|
||||
*/
|
||||
protected string $table = 'joomla_power';
|
||||
}
|
||||
|
@ -14,8 +14,9 @@ namespace VDM\Joomla\Componentbuilder\JoomlaPower;
|
||||
|
||||
use Joomla\DI\Container;
|
||||
use VDM\Joomla\Componentbuilder\JoomlaPower\Service\JoomlaPower as Power;
|
||||
use VDM\Joomla\Componentbuilder\Service\Database;
|
||||
use VDM\Joomla\Componentbuilder\JoomlaPower\Service\Database as PowerDatabase;
|
||||
use VDM\Joomla\Service\Database;
|
||||
use VDM\Joomla\Service\Model;
|
||||
use VDM\Joomla\Service\Data;
|
||||
use VDM\Joomla\Componentbuilder\Service\Gitea;
|
||||
use VDM\Joomla\Componentbuilder\Power\Service\Gitea as GiteaPower;
|
||||
use VDM\Joomla\Gitea\Service\Utilities as GiteaUtilities;
|
||||
@ -77,7 +78,8 @@ abstract class Factory implements FactoryInterface
|
||||
return (new Container())
|
||||
->registerServiceProvider(new Power())
|
||||
->registerServiceProvider(new Database())
|
||||
->registerServiceProvider(new PowerDatabase())
|
||||
->registerServiceProvider(new Model())
|
||||
->registerServiceProvider(new Data())
|
||||
->registerServiceProvider(new Gitea())
|
||||
->registerServiceProvider(new GiteaPower())
|
||||
->registerServiceProvider(new GiteaUtilities());
|
||||
|
@ -56,7 +56,9 @@ final class Grep extends ExtendingGrep implements GrepInterface
|
||||
|
||||
try
|
||||
{
|
||||
$path->index = $this->contents->get($path->owner, $path->repo, 'joomla-powers.json', $path->branch);
|
||||
$this->contents->load_($path->base ?? null, $path->token ?? null);
|
||||
$path->index = $this->contents->get($path->organisation, $path->repository, 'joomla-powers.json', $path->read_branch);
|
||||
$this->contents->reset_();
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
@ -108,46 +110,43 @@ final class Grep extends ExtendingGrep implements GrepInterface
|
||||
*/
|
||||
protected function getRemote(object $path, string $guid): ?object
|
||||
{
|
||||
$power = null;
|
||||
if (empty($path->index->{$guid}->settings))
|
||||
{
|
||||
return null;
|
||||
return $power;
|
||||
}
|
||||
|
||||
// get the settings
|
||||
if (($power = $this->loadRemoteFile($path->owner, $path->repo, $path->index->{$guid}->settings, $path->branch)) !== null &&
|
||||
$this->contents->load_($path->base ?? null, $path->token ?? null);
|
||||
if (($power = $this->loadRemoteFile($path->organisation, $path->repository, $path->index->{$guid}->settings, $path->read_branch)) !== null &&
|
||||
isset($power->guid))
|
||||
{
|
||||
// set the git details in params
|
||||
$power->params = (object) [
|
||||
'git' => [
|
||||
'owner' => $path->owner,
|
||||
'repo' => $path->repo,
|
||||
'branch' => $path->branch
|
||||
]
|
||||
'source' => ['guid' => $path->guid ?? null]
|
||||
];
|
||||
|
||||
return $power;
|
||||
}
|
||||
$this->contents->reset_();
|
||||
|
||||
return null;
|
||||
return $power;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the remote file
|
||||
*
|
||||
* @param string $owner The repository owner
|
||||
* @param string $repo The repository name
|
||||
* @param string $path The repository path to file
|
||||
* @param string|null $branch The repository branch name
|
||||
* @param string $organisation The repository organisation
|
||||
* @param string $repository The repository name
|
||||
* @param string $path The repository path to file
|
||||
* @param string|null $branch The repository branch name
|
||||
*
|
||||
* @return mixed
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function loadRemoteFile(string $owner, string $repo, string $path, ?string $branch)
|
||||
protected function loadRemoteFile(string $organisation, string $repository, string $path, ?string $branch)
|
||||
{
|
||||
try
|
||||
{
|
||||
$data = $this->contents->get($owner, $repo, $path, $branch);
|
||||
$data = $this->contents->get($organisation, $repository, $path, $branch);
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
|
@ -1,37 +0,0 @@
|
||||
<?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\JoomlaPower\Model;
|
||||
|
||||
|
||||
use VDM\Joomla\Interfaces\ModelInterface;
|
||||
use VDM\Joomla\Componentbuilder\Power\Model\Load as ExtendingLoad;
|
||||
|
||||
|
||||
/**
|
||||
* Joomla Power Model Load
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
final class Load extends ExtendingLoad implements ModelInterface
|
||||
{
|
||||
/**
|
||||
* Get the current active table
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getTable(): string
|
||||
{
|
||||
return 'joomla_power';
|
||||
}
|
||||
}
|
||||
|
@ -1,38 +0,0 @@
|
||||
<?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\JoomlaPower\Model;
|
||||
|
||||
|
||||
use VDM\Joomla\Interfaces\ModelInterface;
|
||||
use VDM\Joomla\Componentbuilder\Power\Model\Upsert as ExtendingUpsert;
|
||||
|
||||
|
||||
/**
|
||||
* Joomla Power Model Update or Insert
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
final class Upsert extends ExtendingUpsert implements ModelInterface
|
||||
{
|
||||
/**
|
||||
* Get the current active table
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getTable(): string
|
||||
{
|
||||
return 'joomla_power';
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,135 +0,0 @@
|
||||
<?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\JoomlaPower\Service;
|
||||
|
||||
|
||||
use Joomla\DI\Container;
|
||||
use Joomla\DI\ServiceProviderInterface;
|
||||
use VDM\Joomla\Componentbuilder\JoomlaPower\Model\Load as ModelLoad;
|
||||
use VDM\Joomla\Componentbuilder\JoomlaPower\Model\Upsert as ModelUpsert;
|
||||
use VDM\Joomla\Componentbuilder\JoomlaPower\Database\Load as LoadDatabase;
|
||||
use VDM\Joomla\Componentbuilder\JoomlaPower\Database\Insert as InsertDatabase;
|
||||
use VDM\Joomla\Componentbuilder\JoomlaPower\Database\Update as UpdateDatabase;
|
||||
|
||||
|
||||
/**
|
||||
* Database Service Provider
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Database implements ServiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* Registers the service provider with a DI container.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container->alias(ModelLoad::class, 'Joomla.Power.Model.Load')
|
||||
->share('Joomla.Power.Model.Load', [$this, 'getModelLoad'], true);
|
||||
|
||||
$container->alias(ModelUpsert::class, 'Joomla.Power.Model.Upsert')
|
||||
->share('Joomla.Power.Model.Upsert', [$this, 'getModelUpsert'], true);
|
||||
|
||||
$container->alias(LoadDatabase::class, 'Joomla.Power.Database.Load')
|
||||
->share('Joomla.Power.Database.Load', [$this, 'getLoadDatabase'], true);
|
||||
|
||||
$container->alias(InsertDatabase::class, 'Joomla.Power.Database.Insert')
|
||||
->share('Joomla.Power.Database.Insert', [$this, 'getInsertDatabase'], true);
|
||||
|
||||
$container->alias(UpdateDatabase::class, 'Joomla.Power.Database.Update')
|
||||
->share('Joomla.Power.Database.Update', [$this, 'getUpdateDatabase'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Power Model Load
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return ModelLoad
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getModelLoad(Container $container): ModelLoad
|
||||
{
|
||||
return new ModelLoad(
|
||||
$container->get('Table')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Power Model Update or Insert
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return ModelUpsert
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getModelUpsert(Container $container): ModelUpsert
|
||||
{
|
||||
return new ModelUpsert(
|
||||
$container->get('Table')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Load Database
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return LoadDatabase
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getLoadDatabase(Container $container): LoadDatabase
|
||||
{
|
||||
return new LoadDatabase(
|
||||
$container->get('Joomla.Power.Model.Load'),
|
||||
$container->get('Load')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Insert Database
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return InsertDatabase
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getInsertDatabase(Container $container): InsertDatabase
|
||||
{
|
||||
return new InsertDatabase(
|
||||
$container->get('Joomla.Power.Model.Upsert'),
|
||||
$container->get('Insert')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Update Database
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return UpdateDatabase
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getUpdateDatabase(Container $container): UpdateDatabase
|
||||
{
|
||||
return new UpdateDatabase(
|
||||
$container->get('Joomla.Power.Model.Upsert'),
|
||||
$container->get('Update')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -108,8 +108,7 @@ class JoomlaPower implements ServiceProviderInterface
|
||||
{
|
||||
return new Superpower(
|
||||
$container->get('Joomla.Power.Grep'),
|
||||
$container->get('Joomla.Power.Database.Insert'),
|
||||
$container->get('Joomla.Power.Database.Update')
|
||||
$container->get('Data.Item')
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -12,8 +12,8 @@
|
||||
namespace VDM\Joomla\Componentbuilder\JoomlaPower;
|
||||
|
||||
|
||||
use VDM\Joomla\Componentbuilder\Interfaces\SuperInterface;
|
||||
use VDM\Joomla\Componentbuilder\Power\Super as ExtendingSuper;
|
||||
use VDM\Joomla\Interfaces\Data\RemoteInterface;
|
||||
use VDM\Joomla\Data\Remote;
|
||||
|
||||
|
||||
/**
|
||||
@ -21,7 +21,7 @@ use VDM\Joomla\Componentbuilder\Power\Super as ExtendingSuper;
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
final class Super extends ExtendingSuper implements SuperInterface
|
||||
final class Super extends Remote implements RemoteInterface
|
||||
{
|
||||
/**
|
||||
* Table Name
|
||||
|
@ -13,9 +13,11 @@ namespace VDM\Joomla\Componentbuilder\Power;
|
||||
|
||||
|
||||
use Joomla\Registry\Registry as JoomlaRegistry;
|
||||
use Joomla\CMS\Factory as JoomlaFactory;
|
||||
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;
|
||||
use VDM\Joomla\Componentbuilder\Abstraction\BaseConfig;
|
||||
|
||||
|
||||
@ -43,9 +45,9 @@ class Config extends BaseConfig
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Input|null $input Input
|
||||
* @param Registry|null $params The component parameters
|
||||
* @param Registry|null $config The Joomla configuration
|
||||
* @param Input|null $input Input
|
||||
* @param JoomlaRegistry|null $params The component parameters
|
||||
* @param JoomlaRegistry|null $config The Joomla configuration
|
||||
*
|
||||
* @throws \Exception
|
||||
* @since 3.2.0
|
||||
@ -65,7 +67,7 @@ class Config extends BaseConfig
|
||||
*/
|
||||
protected function getGiteausername(): ?string
|
||||
{
|
||||
return $this->custom_gitea_username ?? $this->params->get('gitea_username');
|
||||
return $this->params->get('gitea_username');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -76,66 +78,7 @@ class Config extends BaseConfig
|
||||
*/
|
||||
protected function getGiteatoken(): ?string
|
||||
{
|
||||
return $this->custom_gitea_token ?? $this->params->get('gitea_token');
|
||||
}
|
||||
|
||||
/**
|
||||
* get Add Custom Gitea URL
|
||||
*
|
||||
* @return int the add switch
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getAddcustomgiteaurl(): int
|
||||
{
|
||||
return $this->params->get('add_custom_gitea_url', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* get Custom Gitea URL
|
||||
*
|
||||
* @return string the custom gitea url
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getCustomgiteaurl(): ?string
|
||||
{
|
||||
if ($this->add_custom_gitea_url == 2)
|
||||
{
|
||||
return $this->params->get('custom_gitea_url');
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* get Custom Gitea Username
|
||||
*
|
||||
* @return string the custom access token
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getCustomgiteausername(): ?string
|
||||
{
|
||||
if ($this->add_custom_gitea_url == 2)
|
||||
{
|
||||
return $this->params->get('custom_gitea_username');
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* get Custom Gitea Access Token
|
||||
*
|
||||
* @return string the custom access token
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getCustomgiteatoken(): ?string
|
||||
{
|
||||
if ($this->add_custom_gitea_url == 2)
|
||||
{
|
||||
return $this->params->get('custom_gitea_token');
|
||||
}
|
||||
|
||||
return null;
|
||||
return $this->params->get('gitea_token');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -149,11 +92,6 @@ class Config extends BaseConfig
|
||||
// the VDM default organisation is [joomla]
|
||||
$organisation = 'joomla';
|
||||
|
||||
if ($this->add_custom_gitea_url == 2)
|
||||
{
|
||||
return $this->params->get('super_powers_core_organisation', $organisation);
|
||||
}
|
||||
|
||||
return $organisation;
|
||||
}
|
||||
|
||||
@ -168,38 +106,31 @@ class Config extends BaseConfig
|
||||
// some defaults repos we need by JCB
|
||||
$repos = [];
|
||||
|
||||
// only add custom init with custom gitea
|
||||
$paths = null;
|
||||
if ($this->add_custom_gitea_url == 2)
|
||||
{
|
||||
$paths = $this->params->get('super_powers_init_repos');
|
||||
}
|
||||
|
||||
// get the users own power repo (can overwrite all)
|
||||
if (!empty($this->gitea_username))
|
||||
if ($this->gitea_username !== null)
|
||||
{
|
||||
$repos[$this->gitea_username . '.super-powers'] = (object) ['owner' => $this->gitea_username, 'repo' => 'super-powers', 'branch' => 'master'];
|
||||
$repos[$this->gitea_username . '.super-powers'] = (object) [
|
||||
'organisation' => $this->gitea_username,
|
||||
'repository' => 'super-powers',
|
||||
'read_branch' => 'master'
|
||||
];
|
||||
}
|
||||
|
||||
if (!empty($paths) && is_array($paths))
|
||||
{
|
||||
foreach ($paths as $path)
|
||||
{
|
||||
$owner = $path->owner ?? null;
|
||||
$repo = $path->repo ?? null;
|
||||
if ($owner !== null && $repo !== null)
|
||||
{
|
||||
// we make sure to get only the objects
|
||||
$repos = ["{$owner}.{$repo}" => $path] + $repos;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$repos[$this->super_powers_core_organisation . '.super-powers'] = (object) ['owner' => $this->super_powers_core_organisation, 'repo' => 'super-powers', 'branch' => 'master'];
|
||||
$repos[$this->super_powers_core_organisation . '.gitea'] = (object) ['owner' => $this->super_powers_core_organisation, 'repo' => 'gitea', 'branch' => 'master'];
|
||||
$repos[$this->super_powers_core_organisation . '.openai'] = (object) ['owner' => $this->super_powers_core_organisation, 'repo' => 'openai', 'branch' => 'master'];
|
||||
}
|
||||
$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'
|
||||
];
|
||||
|
||||
return $repos;
|
||||
}
|
||||
@ -212,9 +143,13 @@ class Config extends BaseConfig
|
||||
*/
|
||||
protected function getSuperpowerspushrepo(): ?object
|
||||
{
|
||||
if (!empty($this->gitea_username))
|
||||
if ($this->gitea_username !== null)
|
||||
{
|
||||
return (object) ['owner' => $this->gitea_username, 'repo' => 'super-powers', 'branch' => 'master'];
|
||||
return (object) [
|
||||
'organisation' => $this->gitea_username,
|
||||
'repository' => 'super-powers',
|
||||
'read_branch' => 'master'
|
||||
];
|
||||
}
|
||||
|
||||
return null;
|
||||
@ -288,19 +223,14 @@ class Config extends BaseConfig
|
||||
// some defaults repos we need by JCB
|
||||
$approved = $this->super_powers_init_repos;
|
||||
|
||||
if (!$this->add_own_powers)
|
||||
{
|
||||
return array_values($approved);
|
||||
}
|
||||
$paths = RepoHelper::get(1); // super powers = 1
|
||||
|
||||
$paths = $this->params->get('approved_paths');
|
||||
|
||||
if (!empty($paths))
|
||||
if ($paths !== null)
|
||||
{
|
||||
foreach ($paths as $path)
|
||||
{
|
||||
$owner = $path->owner ?? null;
|
||||
$repo = $path->repo ?? null;
|
||||
$owner = $path->organisation ?? null;
|
||||
$repo = $path->repository ?? null;
|
||||
if ($owner !== null && $repo !== null)
|
||||
{
|
||||
// we make sure to get only the objects
|
||||
|
@ -14,8 +14,9 @@ namespace VDM\Joomla\Componentbuilder\Power;
|
||||
|
||||
use Joomla\DI\Container;
|
||||
use VDM\Joomla\Componentbuilder\Power\Service\Power;
|
||||
use VDM\Joomla\Componentbuilder\Service\Database;
|
||||
use VDM\Joomla\Componentbuilder\Power\Service\Database as PowerDatabase;
|
||||
use VDM\Joomla\Service\Database;
|
||||
use VDM\Joomla\Service\Model;
|
||||
use VDM\Joomla\Service\Data;
|
||||
use VDM\Joomla\Componentbuilder\Power\Service\Generator;
|
||||
use VDM\Joomla\Componentbuilder\Service\Gitea;
|
||||
use VDM\Joomla\Componentbuilder\Power\Service\Gitea as GiteaPower;
|
||||
@ -78,7 +79,8 @@ abstract class Factory implements FactoryInterface
|
||||
return (new Container())
|
||||
->registerServiceProvider(new Power())
|
||||
->registerServiceProvider(new Database())
|
||||
->registerServiceProvider(new PowerDatabase())
|
||||
->registerServiceProvider(new Model())
|
||||
->registerServiceProvider(new Data())
|
||||
->registerServiceProvider(new Generator())
|
||||
->registerServiceProvider(new Gitea())
|
||||
->registerServiceProvider(new GiteaPower())
|
||||
|
@ -12,7 +12,7 @@
|
||||
namespace VDM\Joomla\Componentbuilder\Power\Generator;
|
||||
|
||||
|
||||
use VDM\Joomla\Componentbuilder\Power\Database\Load as Database;
|
||||
use VDM\Joomla\Data\Action\Load as Database;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Power\Parser;
|
||||
use VDM\Joomla\Componentbuilder\Power\Generator\Bucket;
|
||||
use VDM\Joomla\Utilities\String\ClassfunctionHelper;
|
||||
@ -77,7 +77,7 @@ final class Search
|
||||
{
|
||||
if (($power = $this->bucket->get("power.{$guid}")) === null)
|
||||
{
|
||||
if (($power = $this->database->item(['guid' => $guid])) === null)
|
||||
if (($power = $this->database->table('power')->item(['guid' => $guid])) === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@ -255,7 +255,7 @@ final class Search
|
||||
{
|
||||
if (($service_providers = $this->bucket->get("service_providers.{$guid}")) === null)
|
||||
{
|
||||
if (($powers = $this->database->items([
|
||||
if (($powers = $this->database->table('power')->items([
|
||||
'use_selection' => [
|
||||
'operator' => 'LIKE',
|
||||
'value' => "'%{$guid}%'",
|
||||
|
@ -48,14 +48,28 @@ final class Grep extends ExtendingGrep implements GrepInterface
|
||||
|
||||
try
|
||||
{
|
||||
$path->index = $this->contents->get($path->owner, $path->repo, 'super-powers.json', $path->branch);
|
||||
$this->contents->load_($path->base ?? null, $path->token ?? null);
|
||||
$path->index = $this->contents->get($path->organisation, $path->repository, 'super-powers.json', $path->read_branch);
|
||||
$this->contents->reset_();
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$this->app->enqueueMessage(
|
||||
Text::sprintf('COM_COMPONENTBUILDER_PSUPER_POWERB_REPOSITORY_AT_BSSB_GAVE_THE_FOLLOWING_ERRORBR_SP', $this->contents->api(), $path->path, $e->getMessage()),
|
||||
'Error'
|
||||
);
|
||||
if ('super-powers' === $path->repository && 'joomla' !== $path->organisation && (empty($path->base) || $path->base === 'https://git.vdm.dev'))
|
||||
{
|
||||
// give heads-up about the overriding feature
|
||||
$this->app->enqueueMessage(
|
||||
Text::sprintf('COM_COMPONENTBUILDER_PSUPER_POWERB_REPOSITORY_AT_BHTTPSGITVDMDEVSB_CAN_BE_USED_TO_OVERRIDE_ANY_POWERBR_BUT_HAS_NOT_YET_BEEN_SET_IN_YOUR_ACCOUNT_AT_HTTPSGITVDMDEVSBR_SMALLTHIS_IS_AND_OPTIONAL_FEATURESMALL', $path->path, $path->organisation),
|
||||
'Message'
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
// give error
|
||||
$this->app->enqueueMessage(
|
||||
Text::sprintf('COM_COMPONENTBUILDER_PSUPER_POWERB_REPOSITORY_AT_BSSB_GAVE_THE_FOLLOWING_ERRORBR_SP', $this->contents->api(), $path->path, $e->getMessage()),
|
||||
'Error'
|
||||
);
|
||||
}
|
||||
|
||||
$path->index = null;
|
||||
}
|
||||
@ -161,50 +175,48 @@ final class Grep extends ExtendingGrep implements GrepInterface
|
||||
*/
|
||||
protected function getRemote(object $path, string $guid): ?object
|
||||
{
|
||||
$power = null;
|
||||
if (empty($path->index->{$guid}->settings) || empty($path->index->{$guid}->code))
|
||||
{
|
||||
return null;
|
||||
return $power;
|
||||
}
|
||||
|
||||
// get the settings
|
||||
if (($power = $this->loadRemoteFile($path->owner, $path->repo, $path->index->{$guid}->settings, $path->branch)) !== null &&
|
||||
$this->contents->load_($path->base ?? null, $path->token ?? null);
|
||||
if (($power = $this->loadRemoteFile($path->organisation, $path->repository, $path->index->{$guid}->settings, $path->read_branch)) !== null &&
|
||||
isset($power->guid))
|
||||
{
|
||||
// get the code
|
||||
if (($code = $this->loadRemoteFile($path->owner, $path->repo, $path->index->{$guid}->power, $path->branch)) !== null)
|
||||
if (($code = $this->loadRemoteFile($path->organisation, $path->repository, $path->index->{$guid}->power, $path->read_branch)) !== null)
|
||||
{
|
||||
// set the git details in params
|
||||
$power->params = (object) [
|
||||
'git' => [
|
||||
'owner' => $path->owner,
|
||||
'repo' => $path->repo,
|
||||
'branch' => $path->branch
|
||||
]
|
||||
'source' => ['guid' => $path->guid ?? null]
|
||||
];
|
||||
$power->main_class_code = $code;
|
||||
return $power;
|
||||
}
|
||||
}
|
||||
$this->contents->reset_();
|
||||
|
||||
return null;
|
||||
return $power;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the remote file
|
||||
*
|
||||
* @param string $owner The repository owner
|
||||
* @param string $repo The repository name
|
||||
* @param string $path The repository path to file
|
||||
* @param string|null $branch The repository branch name
|
||||
* @param string $organisation The repository organisation
|
||||
* @param string $repository The repository name
|
||||
* @param string $path The repository path to file
|
||||
* @param string|null $branch The repository branch name
|
||||
*
|
||||
* @return mixed
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function loadRemoteFile(string $owner, string $repo, string $path, ?string $branch)
|
||||
protected function loadRemoteFile(string $organisation, string $repository, string $path, ?string $branch)
|
||||
{
|
||||
try
|
||||
{
|
||||
$data = $this->contents->get($owner, $repo, $path, $branch);
|
||||
$data = $this->contents->get($organisation, $repository, $path, $branch);
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
|
@ -1 +0,0 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
@ -1,135 +0,0 @@
|
||||
<?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\Service;
|
||||
|
||||
|
||||
use Joomla\DI\Container;
|
||||
use Joomla\DI\ServiceProviderInterface;
|
||||
use VDM\Joomla\Componentbuilder\Power\Model\Load as ModelLoad;
|
||||
use VDM\Joomla\Componentbuilder\Power\Model\Upsert as ModelUpsert;
|
||||
use VDM\Joomla\Componentbuilder\Power\Database\Load as LoadDatabase;
|
||||
use VDM\Joomla\Componentbuilder\Power\Database\Insert as InsertDatabase;
|
||||
use VDM\Joomla\Componentbuilder\Power\Database\Update as UpdateDatabase;
|
||||
|
||||
|
||||
/**
|
||||
* Database Service Provider
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Database implements ServiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* Registers the service provider with a DI container.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container->alias(ModelLoad::class, 'Power.Model.Load')
|
||||
->share('Power.Model.Load', [$this, 'getModelLoad'], true);
|
||||
|
||||
$container->alias(ModelUpsert::class, 'Power.Model.Upsert')
|
||||
->share('Power.Model.Upsert', [$this, 'getModelUpsert'], true);
|
||||
|
||||
$container->alias(LoadDatabase::class, 'Power.Database.Load')
|
||||
->share('Power.Database.Load', [$this, 'getLoadDatabase'], true);
|
||||
|
||||
$container->alias(InsertDatabase::class, 'Power.Database.Insert')
|
||||
->share('Power.Database.Insert', [$this, 'getInsertDatabase'], true);
|
||||
|
||||
$container->alias(UpdateDatabase::class, 'Power.Database.Update')
|
||||
->share('Power.Database.Update', [$this, 'getUpdateDatabase'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Power Model Load
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return ModelLoad
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getModelLoad(Container $container): ModelLoad
|
||||
{
|
||||
return new ModelLoad(
|
||||
$container->get('Table')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Power Model Update or Insert
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return ModelUpsert
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getModelUpsert(Container $container): ModelUpsert
|
||||
{
|
||||
return new ModelUpsert(
|
||||
$container->get('Table')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Load Database
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return LoadDatabase
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getLoadDatabase(Container $container): LoadDatabase
|
||||
{
|
||||
return new LoadDatabase(
|
||||
$container->get('Power.Model.Load'),
|
||||
$container->get('Load')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Insert Database
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return InsertDatabase
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getInsertDatabase(Container $container): InsertDatabase
|
||||
{
|
||||
return new InsertDatabase(
|
||||
$container->get('Power.Model.Upsert'),
|
||||
$container->get('Insert')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Update Database
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return UpdateDatabase
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getUpdateDatabase(Container $container): UpdateDatabase
|
||||
{
|
||||
return new UpdateDatabase(
|
||||
$container->get('Power.Model.Upsert'),
|
||||
$container->get('Update')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ class Generator implements ServiceProviderInterface
|
||||
public function getSearch(Container $container): Search
|
||||
{
|
||||
return new Search(
|
||||
$container->get('Power.Database.Load'),
|
||||
$container->get('Data.Load'),
|
||||
$container->get('Power.Parser'),
|
||||
$container->get('Power.Generator.Bucket')
|
||||
);
|
||||
|
@ -109,8 +109,7 @@ class Power implements ServiceProviderInterface
|
||||
{
|
||||
return new Superpower(
|
||||
$container->get('Power.Grep'),
|
||||
$container->get('Power.Database.Insert'),
|
||||
$container->get('Power.Database.Update')
|
||||
$container->get('Data.Item')
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -12,11 +12,8 @@
|
||||
namespace VDM\Joomla\Componentbuilder\Power;
|
||||
|
||||
|
||||
use VDM\Joomla\Interfaces\GrepInterface as Grep;
|
||||
use VDM\Joomla\Componentbuilder\Interfaces\Database\InsertInterface as Insert;
|
||||
use VDM\Joomla\Componentbuilder\Interfaces\Database\UpdateInterface as Update;
|
||||
use VDM\Joomla\Utilities\GuidHelper;
|
||||
use VDM\Joomla\Componentbuilder\Interfaces\SuperInterface;
|
||||
use VDM\Joomla\Interfaces\Data\RemoteInterface;
|
||||
use VDM\Joomla\Data\Remote;
|
||||
|
||||
|
||||
/**
|
||||
@ -24,171 +21,14 @@ use VDM\Joomla\Componentbuilder\Interfaces\SuperInterface;
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Super implements SuperInterface
|
||||
final class Super extends Remote implements RemoteInterface
|
||||
{
|
||||
/**
|
||||
* The Power Search Tool
|
||||
*
|
||||
* @var Grep
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected Grep $grep;
|
||||
|
||||
/**
|
||||
* Insert Data Class
|
||||
*
|
||||
* @var Insert
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected Insert $insert;
|
||||
|
||||
/**
|
||||
* Update Data Class
|
||||
*
|
||||
* @var Update
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected Update $update;
|
||||
|
||||
/**
|
||||
* Table Name
|
||||
*
|
||||
* @var string
|
||||
* @since 3.2.1
|
||||
*/
|
||||
protected string $table = 'power';
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Grep $grep The Power Grep object.
|
||||
* @param Insert $insert The Power Database Insert object.
|
||||
* @param Update $update The Power Database Update object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(Grep $grep, Insert $insert, Update $update)
|
||||
{
|
||||
$this->grep = $grep;
|
||||
$this->insert = $insert;
|
||||
$this->update = $update;
|
||||
}
|
||||
|
||||
/**
|
||||
* Init all power not found in database
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function init(): bool
|
||||
{
|
||||
if (($powers = $this->grep->getRemotePowersGuid()) !== null)
|
||||
{
|
||||
foreach($powers as $guid)
|
||||
{
|
||||
if ($this->action($guid) === 'insert' && ($power = $this->grep->get($guid, ['remote'])) !== null)
|
||||
{
|
||||
$this->insert($power);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the powers
|
||||
*
|
||||
* @param array $powers The global unique ids of the powers
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function reset(array $powers): bool
|
||||
{
|
||||
if ($powers === [])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$success = true;
|
||||
|
||||
foreach($powers as $guid)
|
||||
{
|
||||
if (!$this->load($guid, ['remote']))
|
||||
{
|
||||
$success = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a superpower
|
||||
*
|
||||
* @param string $guid The global unique id of the power
|
||||
* @param array $order The search order
|
||||
* @param string|null $action The action to load power
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function load(string $guid, array $order = ['remote', 'local'], ?string $action = null): bool
|
||||
{
|
||||
if (($power = $this->grep->get($guid, $order)) !== null &&
|
||||
($action !== null || ($action = $this->action($power->guid)) !== null))
|
||||
{
|
||||
return method_exists($this, $action) ? $this->{$action}($power) : false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a superpower
|
||||
*
|
||||
* @param object $power The power
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
private function insert(object $power): bool
|
||||
{
|
||||
return $this->insert->item($power);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a superpower
|
||||
*
|
||||
* @param object $power The power
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
private function update(object $power): bool
|
||||
{
|
||||
return $this->update->item($power);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get loading action
|
||||
*
|
||||
* @param string $guid The global unique id of the power
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
private function action(string $guid): string
|
||||
{
|
||||
if (($id = GuidHelper::item($guid, $this->table)) !== null && $id > 0)
|
||||
{
|
||||
return 'update';
|
||||
}
|
||||
|
||||
return 'insert';
|
||||
}
|
||||
protected string $table = 'power';
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -465,6 +465,42 @@ abstract class FilterHelper
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* get available repositories of target area
|
||||
*
|
||||
* @param int $target The target area
|
||||
*
|
||||
* @return array|null The result ids
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public static function repositories(int $target): ?array
|
||||
{
|
||||
$db = Factory::getDbo();
|
||||
$query = $db->getQuery(true);
|
||||
$query
|
||||
->select($db->quoteName(array('repository', 'organisation')))
|
||||
->from($db->quoteName('#__componentbuilder_repository'))
|
||||
->where($db->quoteName('published') . ' >= 1')
|
||||
->where($db->quoteName('target') . ' = ' . $target)
|
||||
->order($db->quoteName('ordering') . ' desc');
|
||||
$db->setQuery($query);
|
||||
$db->execute();
|
||||
|
||||
if ($db->getNumRows())
|
||||
{
|
||||
$items = $db->loadObjectList();
|
||||
$options = [];
|
||||
foreach($items as $item)
|
||||
{
|
||||
$path = $item->organisation . '/' . $item->repository;
|
||||
$options[$path] = $path;
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a component admin views IDs
|
||||
*
|
||||
|
@ -0,0 +1,78 @@
|
||||
<?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\Utilities;
|
||||
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
|
||||
|
||||
/**
|
||||
* Repositories Helper
|
||||
*
|
||||
* @since 3.2.2
|
||||
*/
|
||||
abstract class RepoHelper
|
||||
{
|
||||
/**
|
||||
* get available repositories of target area
|
||||
*
|
||||
* @param int $target The target area
|
||||
*
|
||||
* @return array|null The result set
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public static function get(int $target): ?array
|
||||
{
|
||||
$db = Factory::getDbo();
|
||||
$query = $db->getQuery(true);
|
||||
$query->select($db->quoteName(array(
|
||||
'type',
|
||||
'base',
|
||||
'organisation',
|
||||
'repository',
|
||||
'read_branch',
|
||||
'write_branch',
|
||||
'token',
|
||||
'username',
|
||||
'target',
|
||||
'access_repo',
|
||||
'guid'
|
||||
)))
|
||||
->from($db->quoteName('#__componentbuilder_repository'))
|
||||
->where($db->quoteName('published') . ' >= 1')
|
||||
->where($db->quoteName('target') . ' = ' . $target)
|
||||
->order($db->quoteName('ordering') . ' desc');
|
||||
$db->setQuery($query);
|
||||
$db->execute();
|
||||
|
||||
if ($db->getNumRows())
|
||||
{
|
||||
$items = $db->loadObjectList();
|
||||
$options = [];
|
||||
foreach($items as $item)
|
||||
{
|
||||
if ($item->access_repo != 1)
|
||||
{
|
||||
unset($item->username);
|
||||
unset($item->token);
|
||||
}
|
||||
unset($item->access_repo);
|
||||
$path = $item->organisation . '/' . $item->repository;
|
||||
$options[$path] = $item;
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
112
libraries/vendor_jcb/VDM.Joomla/src/Data/Action/Delete.php
Normal file
112
libraries/vendor_jcb/VDM.Joomla/src/Data/Action/Delete.php
Normal file
@ -0,0 +1,112 @@
|
||||
<?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\Data\Action;
|
||||
|
||||
|
||||
use VDM\Joomla\Interfaces\DeleteInterface as Database;
|
||||
use VDM\Joomla\Interfaces\Data\DeleteInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Data Delete
|
||||
*
|
||||
* @since 3.2.2
|
||||
*/
|
||||
class Delete implements DeleteInterface
|
||||
{
|
||||
/**
|
||||
* The Delete Class.
|
||||
*
|
||||
* @var Database
|
||||
* @since 3.2.2
|
||||
*/
|
||||
protected Database $database;
|
||||
|
||||
/**
|
||||
* Table Name
|
||||
*
|
||||
* @var string
|
||||
* @since 3.2.2
|
||||
*/
|
||||
protected string $table;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Database $database The Delete Class.
|
||||
* @param string|null $table The table name.
|
||||
*
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function __construct(Database $database, ?string $table = null)
|
||||
{
|
||||
$this->database = $database;
|
||||
if ($table !== null)
|
||||
{
|
||||
$this->table = $table;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current active table
|
||||
*
|
||||
* @param string|null $table The table that should be active
|
||||
*
|
||||
* @return self
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function table(?string $table): self
|
||||
{
|
||||
if ($table !== null)
|
||||
{
|
||||
$this->table = $table;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all items in the database that match these conditions
|
||||
*
|
||||
* @param array $conditions Conditions by which to delete the data in database [array of arrays (key => value)]
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.2
|
||||
**/
|
||||
public function items(array $conditions): bool
|
||||
{
|
||||
return $this->database->items($conditions, $this->getTable());
|
||||
}
|
||||
|
||||
/**
|
||||
* Truncate a table
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.2
|
||||
**/
|
||||
public function truncate(): void
|
||||
{
|
||||
$this->database->truncate($this->getTable());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current active table
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function getTable(): string
|
||||
{
|
||||
return $this->table;
|
||||
}
|
||||
}
|
||||
|
@ -9,18 +9,18 @@
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Power\Database;
|
||||
namespace VDM\Joomla\Data\Action;
|
||||
|
||||
|
||||
use VDM\Joomla\Interfaces\ModelInterface as Model;
|
||||
use VDM\Joomla\Database\Insert as Database;
|
||||
use VDM\Joomla\Componentbuilder\Interfaces\Database\InsertInterface;
|
||||
use VDM\Joomla\Interfaces\InsertInterface as Database;
|
||||
use VDM\Joomla\Interfaces\Data\InsertInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Power Database Insert
|
||||
* Data Insert (GUID)
|
||||
*
|
||||
* @since 3.2.0
|
||||
* @since 3.2.2
|
||||
*/
|
||||
class Insert implements InsertInterface
|
||||
{
|
||||
@ -46,20 +46,43 @@ class Insert implements InsertInterface
|
||||
* @var string
|
||||
* @since 3.2.1
|
||||
*/
|
||||
protected string $table = 'power';
|
||||
protected string $table;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Model $model The set model object.
|
||||
* @param Database $database The insert database object.
|
||||
* @param string|null $table The table name.
|
||||
*
|
||||
* @since 3.2.0
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function __construct(Model $model, Database $database)
|
||||
public function __construct(Model $model, Database $database, ?string $table = null)
|
||||
{
|
||||
$this->model = $model;
|
||||
$this->database = $database;
|
||||
if ($table !== null)
|
||||
{
|
||||
$this->table = $table;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current active table
|
||||
*
|
||||
* @param string|null $table The table that should be active
|
||||
*
|
||||
* @return self
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function table(?string $table): self
|
||||
{
|
||||
if ($table !== null)
|
||||
{
|
||||
$this->table = $table;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -97,10 +120,10 @@ class Insert implements InsertInterface
|
||||
public function row(array $item): bool
|
||||
{
|
||||
// check if object could be modelled
|
||||
if (($item = $this->model->row($item, $this->table)) !== null)
|
||||
if (($item = $this->model->row($item, $this->getTable())) !== null)
|
||||
{
|
||||
// Insert the column of this table
|
||||
return $this->database->row($item, $this->table);
|
||||
return $this->database->row($item, $this->getTable());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -117,10 +140,10 @@ class Insert implements InsertInterface
|
||||
public function rows(?array $items): bool
|
||||
{
|
||||
// check if object could be modelled
|
||||
if (($items = $this->model->rows($items, $this->table)) !== null)
|
||||
if (($items = $this->model->rows($items, $this->getTable())) !== null)
|
||||
{
|
||||
// Insert the column of this table
|
||||
return $this->database->rows($items, $this->table);
|
||||
return $this->database->rows($items, $this->getTable());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -137,10 +160,10 @@ class Insert implements InsertInterface
|
||||
public function item(object $item): bool
|
||||
{
|
||||
// check if object could be modelled
|
||||
if (($item = $this->model->item($item, $this->table)) !== null)
|
||||
if (($item = $this->model->item($item, $this->getTable())) !== null)
|
||||
{
|
||||
// Insert the column of this table
|
||||
return $this->database->item($item, $this->table);
|
||||
return $this->database->item($item, $this->getTable());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -157,12 +180,23 @@ class Insert implements InsertInterface
|
||||
public function items(?array $items): bool
|
||||
{
|
||||
// check if object could be modelled
|
||||
if (($items = $this->model->items($items, $this->table)) !== null)
|
||||
if (($items = $this->model->items($items, $this->getTable())) !== null)
|
||||
{
|
||||
// Update the column of this table using guid as the primary key.
|
||||
return $this->database->items($items, $this->table);
|
||||
return $this->database->items($items, $this->getTable());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current active table
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function getTable(): string
|
||||
{
|
||||
return $this->table;
|
||||
}
|
||||
}
|
||||
|
@ -9,18 +9,18 @@
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Power\Database;
|
||||
namespace VDM\Joomla\Data\Action;
|
||||
|
||||
|
||||
use VDM\Joomla\Interfaces\ModelInterface as Model;
|
||||
use VDM\Joomla\Database\Load as Database;
|
||||
use VDM\Joomla\Componentbuilder\Power\Database\LoadInterface;
|
||||
use VDM\Joomla\Interfaces\LoadInterface as Database;
|
||||
use VDM\Joomla\Interfaces\Data\LoadInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Power Database Load
|
||||
* Data Load (GUID)
|
||||
*
|
||||
* @since 2.0.1
|
||||
* @since 3.2.2
|
||||
*/
|
||||
class Load implements LoadInterface
|
||||
{
|
||||
@ -46,21 +46,43 @@ class Load implements LoadInterface
|
||||
* @var string
|
||||
* @since 3.2.1
|
||||
*/
|
||||
protected string $table = 'power';
|
||||
protected string $table;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Table $table The core table object.
|
||||
* @param Model $model The model object.
|
||||
* @param Database $load The database object.
|
||||
* @param string|null $table The table name.
|
||||
*
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function __construct(Model $model, Database $load)
|
||||
public function __construct(Model $model, Database $load, ?string $table = null)
|
||||
{
|
||||
$this->model = $model;
|
||||
$this->load = $load;
|
||||
if ($table !== null)
|
||||
{
|
||||
$this->table = $table;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current active table
|
||||
*
|
||||
* @param string|null $table The table that should be active
|
||||
*
|
||||
* @return self
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function table(?string $table): self
|
||||
{
|
||||
if ($table !== null)
|
||||
{
|
||||
$this->table = $table;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -73,7 +95,6 @@ class Load implements LoadInterface
|
||||
*
|
||||
* @param array $keys The item keys
|
||||
* @param string $field The field key
|
||||
* @param string $table The table
|
||||
*
|
||||
* @return mixed
|
||||
* @since 2.0.1
|
||||
@ -83,11 +104,11 @@ class Load implements LoadInterface
|
||||
return $this->model->value(
|
||||
$this->load->value(
|
||||
["a.{$field}" => $field],
|
||||
['a' => $this->table],
|
||||
['a' => $this->getTable()],
|
||||
$this->prefix($keys)
|
||||
),
|
||||
$field,
|
||||
$this->table
|
||||
$this->getTable()
|
||||
);
|
||||
}
|
||||
|
||||
@ -100,7 +121,6 @@ class Load implements LoadInterface
|
||||
* );
|
||||
*
|
||||
* @param array $keys The item keys
|
||||
* @param string $table The table
|
||||
*
|
||||
* @return object|null
|
||||
* @since 2.0.1
|
||||
@ -110,10 +130,10 @@ class Load implements LoadInterface
|
||||
return $this->model->item(
|
||||
$this->load->item(
|
||||
['all' => 'a.*'],
|
||||
['a' => $this->table],
|
||||
['a' => $this->getTable()],
|
||||
$this->prefix($keys)
|
||||
),
|
||||
$this->table
|
||||
$this->getTable()
|
||||
);
|
||||
}
|
||||
|
||||
@ -127,10 +147,9 @@ class Load implements LoadInterface
|
||||
* ]
|
||||
* ]
|
||||
* );
|
||||
* Example: $this->items($ids, 'table_name');
|
||||
* Example: $this->items($ids);
|
||||
*
|
||||
* @param array $keys The item keys
|
||||
* @param string $table The table
|
||||
*
|
||||
* @return array|null
|
||||
* @since 2.0.1
|
||||
@ -139,12 +158,23 @@ class Load implements LoadInterface
|
||||
{
|
||||
return $this->model->items(
|
||||
$this->load->items(
|
||||
['all' => 'a.*'], ['a' => $this->table], $this->prefix($keys)
|
||||
['all' => 'a.*'], ['a' => $this->getTable()], $this->prefix($keys)
|
||||
),
|
||||
$this->table
|
||||
$this->getTable()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current active table
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function getTable(): string
|
||||
{
|
||||
return $this->table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add prefix to the keys
|
||||
*
|
@ -9,18 +9,18 @@
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Power\Database;
|
||||
namespace VDM\Joomla\Data\Action;
|
||||
|
||||
|
||||
use VDM\Joomla\Interfaces\ModelInterface as Model;
|
||||
use VDM\Joomla\Database\Update as Database;
|
||||
use VDM\Joomla\Componentbuilder\Interfaces\Database\UpdateInterface;
|
||||
use VDM\Joomla\Interfaces\UpdateInterface as Database;
|
||||
use VDM\Joomla\Interfaces\Data\UpdateInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Power Database Update
|
||||
* Data Update
|
||||
*
|
||||
* @since 3.2.0
|
||||
* @since 3.2.2
|
||||
*/
|
||||
class Update implements UpdateInterface
|
||||
{
|
||||
@ -46,20 +46,43 @@ class Update implements UpdateInterface
|
||||
* @var string
|
||||
* @since 3.2.1
|
||||
*/
|
||||
protected string $table = 'power';
|
||||
protected string $table;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Model $model The set model object.
|
||||
* @param Database $database The update database object.
|
||||
* @param string|null $table The table name.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(Model $model, Database $database)
|
||||
public function __construct(Model $model, Database $database, ?string $table = null)
|
||||
{
|
||||
$this->model = $model;
|
||||
$this->database = $database;
|
||||
if ($table !== null)
|
||||
{
|
||||
$this->table = $table;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current active table
|
||||
*
|
||||
* @param string|null $table The table that should be active
|
||||
*
|
||||
* @return self
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function table(?string $table): self
|
||||
{
|
||||
if ($table !== null)
|
||||
{
|
||||
$this->table = $table;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -81,8 +104,8 @@ class Update implements UpdateInterface
|
||||
$item[$key] = $keyValue;
|
||||
$item[$field] = $value;
|
||||
|
||||
// Update the column of this table using guid as the primary key.
|
||||
return $this->row($item);
|
||||
// Update the column of this table using $key as the primary key.
|
||||
return $this->row($item, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -90,17 +113,18 @@ class Update implements UpdateInterface
|
||||
* Example: $this->item(Array);
|
||||
*
|
||||
* @param array $item The item to save
|
||||
* @param string $key The key name
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function row(array $item): bool
|
||||
public function row(array $item, string $key = 'guid'): bool
|
||||
{
|
||||
// check if object could be modelled
|
||||
if (($item = $this->model->row($item, $this->table)) !== null)
|
||||
if (($item = $this->model->row($item, $this->getTable())) !== null)
|
||||
{
|
||||
// Update the column of this table using guid as the primary key.
|
||||
return $this->database->row($item, 'guid', $this->table);
|
||||
// Update the column of this table using $key as the primary key.
|
||||
return $this->database->row($item, $key, $this->getTable());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -110,17 +134,18 @@ class Update implements UpdateInterface
|
||||
* Example: $this->items(Array);
|
||||
*
|
||||
* @param array|null $items The items updated in database (array of arrays)
|
||||
* @param string $key The key name
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function rows(?array $items): bool
|
||||
public function rows(?array $items, string $key = 'guid'): bool
|
||||
{
|
||||
// check if object could be modelled
|
||||
if (($items = $this->model->rows($items, $this->table)) !== null)
|
||||
if (($items = $this->model->rows($items, $this->getTable())) !== null)
|
||||
{
|
||||
// Update the column of this table using guid as the primary key.
|
||||
return $this->database->rows($items, 'guid', $this->table);
|
||||
// Update the column of this table using $key as the primary key.
|
||||
return $this->database->rows($items, $key, $this->getTable());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -130,17 +155,18 @@ class Update implements UpdateInterface
|
||||
* Example: $this->item(Object);
|
||||
*
|
||||
* @param object $item The item to save
|
||||
* @param string $key The key name
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function item(object $item): bool
|
||||
public function item(object $item, string $key = 'guid'): bool
|
||||
{
|
||||
// check if object could be modelled
|
||||
if (($item = $this->model->item($item, $this->table)) !== null)
|
||||
if (($item = $this->model->item($item, $this->getTable())) !== null)
|
||||
{
|
||||
// Update the column of this table using guid as the primary key.
|
||||
return $this->database->item($item, 'guid', $this->table);
|
||||
// Update the column of this table using $key as the primary key.
|
||||
return $this->database->item($item, $key, $this->getTable());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -150,19 +176,31 @@ class Update implements UpdateInterface
|
||||
* Example: $this->items(Array);
|
||||
*
|
||||
* @param array|null $items The items updated in database (array of objects)
|
||||
* @param string $key The key name
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function items(?array $items): bool
|
||||
public function items(?array $items, string $key = 'guid'): bool
|
||||
{
|
||||
// check if object could be modelled
|
||||
if (($items = $this->model->items($items, $this->table)) !== null)
|
||||
if (($items = $this->model->items($items, $this->getTable())) !== null)
|
||||
{
|
||||
// Update the column of this table using guid as the primary key.
|
||||
return $this->database->items($items, 'guid', $this->table);
|
||||
// Update the column of this table using $key as the primary key.
|
||||
return $this->database->items($items, $key, $this->getTable());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current active table
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function getTable(): string
|
||||
{
|
||||
return $this->table;
|
||||
}
|
||||
}
|
||||
|
254
libraries/vendor_jcb/VDM.Joomla/src/Data/Item.php
Normal file
254
libraries/vendor_jcb/VDM.Joomla/src/Data/Item.php
Normal file
@ -0,0 +1,254 @@
|
||||
<?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\Data;
|
||||
|
||||
|
||||
use VDM\Joomla\Interfaces\Data\LoadInterface as Load;
|
||||
use VDM\Joomla\Interfaces\Data\InsertInterface as Insert;
|
||||
use VDM\Joomla\Interfaces\Data\UpdateInterface as Update;
|
||||
use VDM\Joomla\Interfaces\Data\DeleteInterface as Delete;
|
||||
use VDM\Joomla\Interfaces\LoadInterface as Database;
|
||||
use VDM\Joomla\Interfaces\Data\ItemInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Data Item
|
||||
*
|
||||
* @since 3.2.2
|
||||
*/
|
||||
final class Item implements ItemInterface
|
||||
{
|
||||
/**
|
||||
* The Load Class.
|
||||
*
|
||||
* @var Load
|
||||
* @since 3.2.2
|
||||
*/
|
||||
protected Load $load;
|
||||
|
||||
/**
|
||||
* The Insert Class.
|
||||
*
|
||||
* @var Insert
|
||||
* @since 3.2.2
|
||||
*/
|
||||
protected Insert $insert;
|
||||
|
||||
/**
|
||||
* The Update Class.
|
||||
*
|
||||
* @var Update
|
||||
* @since 3.2.2
|
||||
*/
|
||||
protected Update $update;
|
||||
|
||||
/**
|
||||
* The Delete Class.
|
||||
*
|
||||
* @var Delete
|
||||
* @since 3.2.2
|
||||
*/
|
||||
protected Delete $delete;
|
||||
|
||||
/**
|
||||
* The Load Class.
|
||||
*
|
||||
* @var Database
|
||||
* @since 3.2.2
|
||||
*/
|
||||
protected Database $database;
|
||||
|
||||
/**
|
||||
* Table Name
|
||||
*
|
||||
* @var string
|
||||
* @since 3.2.1
|
||||
*/
|
||||
protected string $table;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Load $load The LoadInterface Class.
|
||||
* @param Insert $insert The InsertInterface Class.
|
||||
* @param Update $update The UpdateInterface Class.
|
||||
* @param Delete $delete The UpdateInterface Class.
|
||||
* @param Database $database The Database Load Class.
|
||||
* @param string|null $table The table name.
|
||||
*
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function __construct(Load $load, Insert $insert, Update $update,
|
||||
Delete $delete, Database $database, ?string $table = null)
|
||||
{
|
||||
$this->load = $load;
|
||||
$this->insert = $insert;
|
||||
$this->update = $update;
|
||||
$this->delete = $delete;
|
||||
$this->database = $database;
|
||||
if ($table !== null)
|
||||
{
|
||||
$this->table = $table;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current active table
|
||||
*
|
||||
* @param string $table The table that should be active
|
||||
*
|
||||
* @return self
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function table(string $table): self
|
||||
{
|
||||
$this->table = $table;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an item
|
||||
*
|
||||
* @param string $value The item key value
|
||||
* @param string $key The item key
|
||||
*
|
||||
* @return object|null The item object or null
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function get(string $value, string $key = 'guid'): ?object
|
||||
{
|
||||
return $this->load->table($this->getTable())->item([$key => $value]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value
|
||||
*
|
||||
* @param string $value The item key value
|
||||
* @param string $key The item key
|
||||
* @param string $get The key of the values we want back
|
||||
*
|
||||
* @return mixed
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function value(string $value, string $key = 'guid', string $get = 'id')
|
||||
{
|
||||
// Perform the database query
|
||||
$value = $this->database->value(
|
||||
["a.$get" => $get],
|
||||
["a" => $this->getTable()],
|
||||
["a.$key" => $value]
|
||||
);
|
||||
|
||||
// Check if rows are found
|
||||
if ($value !== null)
|
||||
{
|
||||
// Return the value
|
||||
return $value;
|
||||
}
|
||||
|
||||
// Return null if no rows are found
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an item
|
||||
*
|
||||
* @param object $item The item
|
||||
* @param string $key The item key
|
||||
* @param string|null $action The action to load power
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function set(object $item, string $key = 'guid', ?string $action = null): bool
|
||||
{
|
||||
if ($action !== null || (isset($item->{$key}) && ($action = $this->action($item->{$key}, $key)) !== null))
|
||||
{
|
||||
return method_exists($this, $action) ? $this->{$action}($item, $key) : false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an item
|
||||
*
|
||||
* @param string $value The item key value
|
||||
* @param string $key The item key
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function delete(string $value, string $key = 'guid'): bool
|
||||
{
|
||||
return $this->delete->table($this->getTable())->items([$key => $value]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current active table
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function getTable(): string
|
||||
{
|
||||
return $this->table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a item
|
||||
*
|
||||
* @param object $item The item
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.2
|
||||
*/
|
||||
private function insert(object $item): bool
|
||||
{
|
||||
return $this->insert->table($this->getTable())->item($item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a item
|
||||
*
|
||||
* @param object $item The item
|
||||
* @param string $key The item key
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.2
|
||||
*/
|
||||
private function update(object $item, string $key): bool
|
||||
{
|
||||
return $this->update->table($this->getTable())->item($item, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get loading action
|
||||
*
|
||||
* @param string $value The key value the item
|
||||
* @param string $key The item key
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.2
|
||||
*/
|
||||
private function action(string $value, string $key): string
|
||||
{
|
||||
if (($id = $this->value($value, $key, 'id')) !== null && $id > 0)
|
||||
{
|
||||
return 'update';
|
||||
}
|
||||
|
||||
return 'insert';
|
||||
}
|
||||
}
|
||||
|
351
libraries/vendor_jcb/VDM.Joomla/src/Data/Items.php
Normal file
351
libraries/vendor_jcb/VDM.Joomla/src/Data/Items.php
Normal file
@ -0,0 +1,351 @@
|
||||
<?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\Data;
|
||||
|
||||
|
||||
use VDM\Joomla\Interfaces\Data\LoadInterface as Load;
|
||||
use VDM\Joomla\Interfaces\Data\InsertInterface as Insert;
|
||||
use VDM\Joomla\Interfaces\Data\UpdateInterface as Update;
|
||||
use VDM\Joomla\Interfaces\Data\DeleteInterface as Delete;
|
||||
use VDM\Joomla\Interfaces\LoadInterface as Database;
|
||||
use VDM\Joomla\Interfaces\Data\ItemsInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Data Items
|
||||
*
|
||||
* @since 3.2.2
|
||||
*/
|
||||
final class Items implements ItemsInterface
|
||||
{
|
||||
/**
|
||||
* The LoadInterface Class.
|
||||
*
|
||||
* @var Load
|
||||
* @since 3.2.2
|
||||
*/
|
||||
protected Load $load;
|
||||
|
||||
/**
|
||||
* The InsertInterface Class.
|
||||
*
|
||||
* @var Insert
|
||||
* @since 3.2.2
|
||||
*/
|
||||
protected Insert $insert;
|
||||
|
||||
/**
|
||||
* The UpdateInterface Class.
|
||||
*
|
||||
* @var Update
|
||||
* @since 3.2.2
|
||||
*/
|
||||
protected Update $update;
|
||||
|
||||
/**
|
||||
* The DeleteInterface Class.
|
||||
*
|
||||
* @var Delete
|
||||
* @since 3.2.2
|
||||
*/
|
||||
protected Delete $delete;
|
||||
|
||||
/**
|
||||
* The Load Class.
|
||||
*
|
||||
* @var Database
|
||||
* @since 3.2.2
|
||||
*/
|
||||
protected Database $database;
|
||||
|
||||
/**
|
||||
* Table Name
|
||||
*
|
||||
* @var string
|
||||
* @since 3.2.1
|
||||
*/
|
||||
protected string $table;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Load $load The LoadInterface Class.
|
||||
* @param Insert $insert The InsertInterface Class.
|
||||
* @param Update $update The UpdateInterface Class.
|
||||
* @param Delete $delete The DeleteInterface Class.
|
||||
* @param Database $database The Database Load Class.
|
||||
* @param string|null $table The table name.
|
||||
*
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function __construct(Load $load, Insert $insert, Update $update, Delete $delete,
|
||||
Database $database, ?string $table = null)
|
||||
{
|
||||
$this->load = $load;
|
||||
$this->insert = $insert;
|
||||
$this->update = $update;
|
||||
$this->delete = $delete;
|
||||
$this->database = $database;
|
||||
if ($table !== null)
|
||||
{
|
||||
$this->table = $table;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current active table
|
||||
*
|
||||
* @param string $table The table that should be active
|
||||
*
|
||||
* @return self
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function table(string $table): self
|
||||
{
|
||||
$this->table = $table;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of items
|
||||
*
|
||||
* @param array $values The ids of the items
|
||||
* @param string $key The key of the values
|
||||
*
|
||||
* @return array|null The item object or null
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function get(array $values, string $key = 'guid'): ?array
|
||||
{
|
||||
return $this->load->table($this->getTable())->items([
|
||||
$key => [
|
||||
'operator' => 'IN',
|
||||
'value' => array_values($values)
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the values
|
||||
*
|
||||
* @param array $values The list of values (to search by).
|
||||
* @param string $key The key on which the values being searched.
|
||||
* @param string $get The key of the values we want back
|
||||
*
|
||||
* @return array|null The array of found values.
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function values(array $values, string $key = 'guid', string $get = 'id'): ?array
|
||||
{
|
||||
// Perform the database query
|
||||
$rows = $this->database->rows(
|
||||
["a.$get" => $get],
|
||||
["a" => $this->getTable()],
|
||||
["a.$key" => ['operator' => 'IN', 'value' => $values]]
|
||||
);
|
||||
|
||||
// Check if rows are found
|
||||
if ($rows !== null)
|
||||
{
|
||||
// Return the values from the found rows
|
||||
return array_values(
|
||||
array_map(
|
||||
fn($row) => $row[$get],
|
||||
$rows
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Return null if no rows are found
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set items
|
||||
*
|
||||
* @param array $items The list of items
|
||||
* @param string $key The key on which the items should be set
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function set(array $items, string $key = 'guid'): bool
|
||||
{
|
||||
if (($sets = $this->sort($items, $key)) !== null)
|
||||
{
|
||||
foreach ($sets as $action => $items)
|
||||
{
|
||||
$this->{$action}($items, $key);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete items
|
||||
*
|
||||
* @param array $values The item key value
|
||||
* @param string $key The item key
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function delete(string $values, string $key = 'guid'): bool
|
||||
{
|
||||
return $this->delete->table($this->getTable())->items([$key => ['operator' => 'IN', 'value' => $values]]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current active table
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function getTable(): string
|
||||
{
|
||||
return $this->table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a item
|
||||
*
|
||||
* @param array $items The item
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.2
|
||||
*/
|
||||
private function insert(array $items): bool
|
||||
{
|
||||
return $this->insert->table($this->getTable())->rows($items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a item
|
||||
*
|
||||
* @param object $item The item
|
||||
* @param string $key The item key
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.2
|
||||
*/
|
||||
private function update(array $items, string $key): bool
|
||||
{
|
||||
return $this->update->table($this->getTable())->rows($items, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort items between insert and update.
|
||||
*
|
||||
* @param array $items The list of items.
|
||||
* @param string $key The key on which the items should be sorted.
|
||||
*
|
||||
* @return array|null The sorted sets.
|
||||
* @since 3.2.2
|
||||
*/
|
||||
private function sort(array $items, string $key): ?array
|
||||
{
|
||||
// Extract relevant items based on the key.
|
||||
$values = $this->extractValues($items, $key);
|
||||
if ($values === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$sets = [
|
||||
'insert' => [],
|
||||
'update' => []
|
||||
];
|
||||
|
||||
// Check for existing items.
|
||||
$existingItems = $this->values($values, $key, $key);
|
||||
if ($existingItems !== null)
|
||||
{
|
||||
$sets['update'] = $this->extractSet($items, $existingItems, $key) ?? [];
|
||||
$sets['insert'] = $this->extractSet($items, $existingItems, $key, true) ?? [];
|
||||
}
|
||||
else
|
||||
{
|
||||
$sets['insert'] = $items;
|
||||
}
|
||||
|
||||
// If either set is empty, remove it from the result.
|
||||
$sets = array_filter($sets);
|
||||
|
||||
return !empty($sets) ? $sets : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts values for a given key from an array of items.
|
||||
* Items can be either arrays or objects.
|
||||
*
|
||||
* @param array $items Array of items (arrays or objects)
|
||||
* @param string $key The key to extract values for
|
||||
*
|
||||
* @return array|null Extracted values
|
||||
* @since 3.2.2
|
||||
*/
|
||||
private function extractValues(array $items, string $key): ?array
|
||||
{
|
||||
$result = [];
|
||||
|
||||
foreach ($items as $item)
|
||||
{
|
||||
if (is_array($item) && !empty($item[$key]))
|
||||
{
|
||||
$result[] = $item[$key];
|
||||
}
|
||||
elseif (is_object($item) && !empty($item->{$key}))
|
||||
{
|
||||
$result[] = $item->{$key};
|
||||
}
|
||||
}
|
||||
|
||||
return ($result === []) ? null : $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts items from an array of items based on a set.
|
||||
* Items can be either arrays or objects.
|
||||
*
|
||||
* @param array $items Array of items (arrays or objects)
|
||||
* @param array $set The set to match values against
|
||||
* @param string $key The key of the set values
|
||||
* @param bool $inverse Whether to extract items not in the set
|
||||
*
|
||||
* @return array|null Extracted values
|
||||
* @since 3.2.2
|
||||
*/
|
||||
private function extractSet(array $items, array $set, string $key, bool $inverse = false): ?array
|
||||
{
|
||||
$result = [];
|
||||
|
||||
foreach ($items as $item)
|
||||
{
|
||||
$value = is_array($item) ? ($item[$key] ?? null) : ($item->{$key} ?? null);
|
||||
|
||||
if ($value !== null)
|
||||
{
|
||||
$inSet = in_array($value, $set);
|
||||
if (($inSet && !$inverse) || (!$inSet && $inverse))
|
||||
{
|
||||
$result[] = is_array($item) ? $item : (array) $item; // convert all to arrays
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return empty($result) ? null : $result;
|
||||
}
|
||||
}
|
||||
|
169
libraries/vendor_jcb/VDM.Joomla/src/Data/Remote.php
Normal file
169
libraries/vendor_jcb/VDM.Joomla/src/Data/Remote.php
Normal file
@ -0,0 +1,169 @@
|
||||
<?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\Data;
|
||||
|
||||
|
||||
use VDM\Joomla\Interfaces\GrepInterface as Grep;
|
||||
use VDM\Joomla\Interfaces\Data\ItemInterface as Item;
|
||||
use VDM\Joomla\Interfaces\Data\RemoteInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Load data based on global unique ids from remote system
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Remote implements RemoteInterface
|
||||
{
|
||||
/**
|
||||
* The Grep Class.
|
||||
*
|
||||
* @var Grep
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Grep $grep;
|
||||
|
||||
/**
|
||||
* The Item Class.
|
||||
*
|
||||
* @var Item
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Item $item;
|
||||
|
||||
/**
|
||||
* Table Name
|
||||
*
|
||||
* @var string
|
||||
* @since 3.2.1
|
||||
*/
|
||||
protected string $table;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Grep $grep The GrepInterface Class.
|
||||
* @param Item $item The ItemInterface Class.
|
||||
* @param string|null $table The table name.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(Grep $grep, Item $item, ?string $table = null)
|
||||
{
|
||||
$this->grep = $grep;
|
||||
$this->item = $item;
|
||||
if ($table !== null)
|
||||
{
|
||||
$this->table = $table;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current active table
|
||||
*
|
||||
* @param string $table The table that should be active
|
||||
*
|
||||
* @return self
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function table(string $table): self
|
||||
{
|
||||
$this->table = $table;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Init all items not found in database
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function init(): bool
|
||||
{
|
||||
if (($items = $this->grep->getRemotePowersGuid()) !== null)
|
||||
{
|
||||
foreach($items as $guid)
|
||||
{
|
||||
if ($this->item->table($this->getTable())->value($guid) !== null &&
|
||||
($item = $this->grep->get($guid, ['remote'])) !== null)
|
||||
{
|
||||
$this->item->set($item);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the items
|
||||
*
|
||||
* @param array $items The global unique ids of the items
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function reset(array $items): bool
|
||||
{
|
||||
if ($items === [])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$success = true;
|
||||
|
||||
foreach($items as $guid)
|
||||
{
|
||||
if (!$this->load($guid, ['remote']))
|
||||
{
|
||||
$success = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a item
|
||||
*
|
||||
* @param string $guid The global unique id of the item
|
||||
* @param array $order The search order
|
||||
* @param string|null $action The action to load power
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function load(string $guid, array $order = ['remote', 'local'], ?string $action = null): bool
|
||||
{
|
||||
if (($item = $this->grep->get($guid, $order)) !== null)
|
||||
{
|
||||
return $this->item->table($this->getTable())->set($item);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current active table
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function getTable(): string
|
||||
{
|
||||
return $this->table;
|
||||
}
|
||||
}
|
||||
|
132
libraries/vendor_jcb/VDM.Joomla/src/Database/Delete.php
Normal file
132
libraries/vendor_jcb/VDM.Joomla/src/Database/Delete.php
Normal file
@ -0,0 +1,132 @@
|
||||
<?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\Database;
|
||||
|
||||
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Interfaces\DeleteInterface;
|
||||
use VDM\Joomla\Abstraction\Database;
|
||||
|
||||
|
||||
/**
|
||||
* Database Delete Class
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
final class Delete extends Database implements DeleteInterface
|
||||
{
|
||||
/**
|
||||
* Delete all items in the database that match these conditions
|
||||
*
|
||||
* @param array $conditions Conditions by which to delete the data in database [array of arrays (key => value)]
|
||||
* @param string $table The table where the data is being deleted
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.2
|
||||
**/
|
||||
public function items(array $conditions, string $table): bool
|
||||
{
|
||||
// set the update columns
|
||||
if ($conditions === [])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// get a query object
|
||||
$query = $this->db->getQuery(true);
|
||||
|
||||
// start the conditions bucket
|
||||
$_conditions = [];
|
||||
foreach ($conditions as $key => $value)
|
||||
{
|
||||
if (ArrayHelper::check($value))
|
||||
{
|
||||
if (isset($value['value']) && isset($value['operator']))
|
||||
{
|
||||
// check if value needs to be quoted
|
||||
$quote = $value['quote'] ?? true;
|
||||
if (!$quote)
|
||||
{
|
||||
if (ArrayHelper::check($value['value']))
|
||||
{
|
||||
// add the where by array
|
||||
$_conditions[] = $this->db->quoteName($key)
|
||||
. ' ' . $value['operator']
|
||||
. ' ' . ' (' .
|
||||
implode(',', $value['value'])
|
||||
. ')';
|
||||
}
|
||||
else
|
||||
{
|
||||
// add the conditions
|
||||
$_conditions[] = $this->db->quoteName($key)
|
||||
. ' ' . $value['operator']
|
||||
. ' ' . $value['value'];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ArrayHelper::check($value['value']))
|
||||
{
|
||||
// add the where by array
|
||||
$_conditions[] = $this->db->quoteName($key)
|
||||
. ' ' . $value['operator']
|
||||
. ' ' . ' (' .
|
||||
implode(',', array_map(fn($val) => $this->quote($val), $value['value']))
|
||||
. ')';
|
||||
}
|
||||
else
|
||||
{
|
||||
// add the conditions
|
||||
$_conditions[] = $this->db->quoteName($key)
|
||||
. ' ' . $value['operator']
|
||||
. ' ' . $this->quote($value['value']);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// we should through an exception
|
||||
// for security we just return false for now
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// add default condition
|
||||
$_conditions[] = $this->db->quoteName($key) . ' = ' . $this->quote($value);
|
||||
}
|
||||
}
|
||||
|
||||
// set the query targets
|
||||
$query->delete($this->db->quoteName($this->getTable($table)));
|
||||
$query->where($_conditions);
|
||||
|
||||
$this->db->setQuery($query);
|
||||
|
||||
return $this->db->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Truncate a table
|
||||
*
|
||||
* @param string $table The table that should be truncated
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.2
|
||||
**/
|
||||
public function truncate(string $table): void
|
||||
{
|
||||
$this->db->truncateTable($this->getTable($table));
|
||||
}
|
||||
}
|
||||
|
@ -40,15 +40,7 @@ final class Load extends Database implements LoadInterface
|
||||
?array $order = null, ?int $limit = null): ?array
|
||||
{
|
||||
// set key if found
|
||||
$key = '';
|
||||
if (isset($select['key']))
|
||||
{
|
||||
if (is_string($select['key']))
|
||||
{
|
||||
$key = $select['key'];
|
||||
}
|
||||
unset($select['key']);
|
||||
}
|
||||
$key = $this->getKey($select);
|
||||
|
||||
// check if we can get many rows
|
||||
if ($this->many($select, $tables, $where, $order, $limit))
|
||||
@ -77,15 +69,7 @@ final class Load extends Database implements LoadInterface
|
||||
?array $order = null, ?int $limit = null): ?array
|
||||
{
|
||||
// set key if found
|
||||
$key = '';
|
||||
if (isset($select['key']))
|
||||
{
|
||||
if (is_string($select['key']))
|
||||
{
|
||||
$key = $select['key'];
|
||||
}
|
||||
unset($select['key']);
|
||||
}
|
||||
$key = $this->getKey($select);
|
||||
|
||||
// check if we can get many rows
|
||||
if ($this->many($select, $tables, $where, $order, $limit))
|
||||
@ -464,6 +448,30 @@ final class Load extends Database implements LoadInterface
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the key from the selection array.
|
||||
*
|
||||
* This function retrieves a key from the provided selection array.
|
||||
* The key is removed from the array after being retrieved.
|
||||
*
|
||||
* @param array $select Array of selection keys.
|
||||
*
|
||||
* @return string|null The key, or null if no key is found.
|
||||
* @since 3.2.2
|
||||
**/
|
||||
protected function getKey(array &$select): ?string
|
||||
{
|
||||
$key = null;
|
||||
|
||||
// Check for 'key' first and ensure it's a string.
|
||||
if (isset($select['key']) && is_string($select['key']))
|
||||
{
|
||||
$key = $select['key'];
|
||||
unset($select['key']); // Remove 'key' from the array.
|
||||
}
|
||||
|
||||
return $key;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,60 @@
|
||||
<?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\Interfaces\Data;
|
||||
|
||||
|
||||
/**
|
||||
* Data Delete
|
||||
*
|
||||
* @since 3.2.2
|
||||
*/
|
||||
interface DeleteInterface
|
||||
{
|
||||
/**
|
||||
* Set the current active table
|
||||
*
|
||||
* @param string|null $table The table that should be active
|
||||
*
|
||||
* @return self
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function table(?string $table): self;
|
||||
|
||||
/**
|
||||
* Delete all items in the database that match these conditions
|
||||
*
|
||||
* @param array $conditions Conditions by which to delete the data in database [array of arrays (key => value)]
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.2
|
||||
**/
|
||||
public function items(array $conditions): bool;
|
||||
|
||||
/**
|
||||
* Truncate a table
|
||||
*
|
||||
* @param string|null $table The table that should be truncated
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.2
|
||||
**/
|
||||
public function truncate(): void;
|
||||
|
||||
/**
|
||||
* Get the current active table
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function getTable(): string;
|
||||
}
|
||||
|
@ -9,16 +9,26 @@
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Interfaces\Database;
|
||||
namespace VDM\Joomla\Interfaces\Data;
|
||||
|
||||
|
||||
/**
|
||||
* Database Insert
|
||||
* Data Insert
|
||||
*
|
||||
* @since 3.2.1
|
||||
* @since 3.2.2
|
||||
*/
|
||||
interface InsertInterface
|
||||
{
|
||||
/**
|
||||
* Set the current active table
|
||||
*
|
||||
* @param string|null $table The table that should be active
|
||||
*
|
||||
* @return self
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function table(?string $table): self;
|
||||
|
||||
/**
|
||||
* Insert a value to a given table
|
||||
* Example: $this->value(Value, 'value_key', 'GUID');
|
||||
@ -76,6 +86,13 @@ interface InsertInterface
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function items(?array $items): bool;
|
||||
|
||||
|
||||
/**
|
||||
* Get the current active table
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function getTable(): string;
|
||||
}
|
||||
|
@ -0,0 +1,86 @@
|
||||
<?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\Interfaces\Data;
|
||||
|
||||
|
||||
/**
|
||||
* Data Item Interface
|
||||
*
|
||||
* @since 3.2.2
|
||||
*/
|
||||
interface ItemInterface
|
||||
{
|
||||
/**
|
||||
* Set the current active table
|
||||
*
|
||||
* @param string $table The table that should be active
|
||||
*
|
||||
* @return self
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function table(string $table): self;
|
||||
|
||||
/**
|
||||
* Get an item
|
||||
*
|
||||
* @param string $value The item key value
|
||||
* @param string $key The item key
|
||||
*
|
||||
* @return object|null The item object or null
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function get(string $value, string $key = 'guid'): ?object;
|
||||
|
||||
/**
|
||||
* Get the value
|
||||
*
|
||||
* @param string $value The item key value
|
||||
* @param string $key The item key
|
||||
* @param string $get The key of the values we want back
|
||||
*
|
||||
* @return mixed
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function value(string $value, string $key = 'guid', string $get = 'id');
|
||||
|
||||
/**
|
||||
* Set an item
|
||||
*
|
||||
* @param object $item The item
|
||||
* @param string $key The item key
|
||||
* @param string|null $action The action to load power
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function set(object $item, string $key = 'guid', ?string $action = null): bool;
|
||||
|
||||
/**
|
||||
* Delete an item
|
||||
*
|
||||
* @param string $value The item key value
|
||||
* @param string $key The item key
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function delete(string $value, string $key = 'guid'): bool;
|
||||
|
||||
/**
|
||||
* Get the current active table
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function getTable(): string;
|
||||
}
|
||||
|
@ -0,0 +1,85 @@
|
||||
<?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\Interfaces\Data;
|
||||
|
||||
|
||||
/**
|
||||
* Data Items Interface
|
||||
*
|
||||
* @since 3.2.2
|
||||
*/
|
||||
interface ItemsInterface
|
||||
{
|
||||
/**
|
||||
* Set the current active table
|
||||
*
|
||||
* @param string $table The table that should be active
|
||||
*
|
||||
* @return self
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function table(string $table): self;
|
||||
|
||||
/**
|
||||
* Get list of items
|
||||
*
|
||||
* @param array $values The ids of the items
|
||||
* @param string $key The key of the values
|
||||
*
|
||||
* @return array|null The item object or null
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function get(array $values, string $key = 'guid'): ?array;
|
||||
|
||||
/**
|
||||
* Get the values
|
||||
*
|
||||
* @param array $values The list of values (to search by).
|
||||
* @param string $key The key on which the values being searched.
|
||||
* @param string $get The key of the values we want back
|
||||
*
|
||||
* @return array|null The array of found values.
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function values(array $values, string $key = 'guid', string $get = 'id'): ?array;
|
||||
|
||||
/**
|
||||
* Set items
|
||||
*
|
||||
* @param array $items The list of items
|
||||
* @param string $key The key on which the items should be set
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function set(array $items, string $key = 'guid'): bool;
|
||||
|
||||
/**
|
||||
* Delete items
|
||||
*
|
||||
* @param array $values The item key value
|
||||
* @param string $key The item key
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function delete(string $values, string $key = 'guid'): bool;
|
||||
|
||||
/**
|
||||
* Get the current active table
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function getTable(): string;
|
||||
}
|
||||
|
@ -9,16 +9,26 @@
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Power\Database;
|
||||
namespace VDM\Joomla\Interfaces\Data;
|
||||
|
||||
|
||||
/**
|
||||
* Power Database Load
|
||||
* Data Load Interface
|
||||
*
|
||||
* @since 2.0.1
|
||||
* @since 3.2.2
|
||||
*/
|
||||
interface LoadInterface
|
||||
{
|
||||
/**
|
||||
* Set the current active table
|
||||
*
|
||||
* @param string|null $table The table that should be active
|
||||
*
|
||||
* @return self
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function table(?string $table): self;
|
||||
|
||||
/**
|
||||
* Get a value from a given table
|
||||
* Example: $this->value(
|
||||
@ -29,7 +39,6 @@ interface LoadInterface
|
||||
*
|
||||
* @param array $keys The item keys
|
||||
* @param string $field The field key
|
||||
* @param string $table The table
|
||||
*
|
||||
* @return mixed
|
||||
* @since 2.0.1
|
||||
@ -45,7 +54,6 @@ interface LoadInterface
|
||||
* );
|
||||
*
|
||||
* @param array $keys The item keys
|
||||
* @param string $table The table
|
||||
*
|
||||
* @return object|null
|
||||
* @since 2.0.1
|
||||
@ -62,14 +70,21 @@ interface LoadInterface
|
||||
* ]
|
||||
* ]
|
||||
* );
|
||||
* Example: $this->items($ids, 'table_name');
|
||||
* Example: $this->items($keys);
|
||||
*
|
||||
* @param array $keys The item keys
|
||||
* @param string $table The table
|
||||
*
|
||||
* @return array|null
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function items(array $keys): ?array;
|
||||
public function items(array $keys): ?array;
|
||||
|
||||
/**
|
||||
* Get the current active table
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function getTable(): string;
|
||||
}
|
||||
|
@ -0,0 +1,69 @@
|
||||
<?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\Interfaces\Data;
|
||||
|
||||
|
||||
/**
|
||||
* Load data based on global unique ids from remote system
|
||||
*
|
||||
* @since 3.2.2
|
||||
*/
|
||||
interface RemoteInterface
|
||||
{
|
||||
/**
|
||||
* Set the current active table
|
||||
*
|
||||
* @param string $table The table that should be active
|
||||
*
|
||||
* @return self
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function table(string $table): self;
|
||||
|
||||
/**
|
||||
* Init all items not found in database
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function init(): bool;
|
||||
|
||||
/**
|
||||
* Reset the items
|
||||
*
|
||||
* @param array $items The global unique ids of the items
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function reset(array $items): bool;
|
||||
|
||||
/**
|
||||
* Load a item
|
||||
*
|
||||
* @param string $guid The global unique id of the item
|
||||
* @param array $order The search order
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function load(string $guid, array $order = ['remote', 'local']): bool;
|
||||
|
||||
/**
|
||||
* Get the current active table
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function getTable(): string;
|
||||
}
|
||||
|
@ -9,16 +9,26 @@
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Interfaces\Database;
|
||||
namespace VDM\Joomla\Interfaces\Data;
|
||||
|
||||
|
||||
/**
|
||||
* Database Update
|
||||
* Data Update
|
||||
*
|
||||
* @since 3.2.1
|
||||
* @since 3.2.2
|
||||
*/
|
||||
interface UpdateInterface
|
||||
{
|
||||
/**
|
||||
* Set the current active table
|
||||
*
|
||||
* @param string|null $table The table that should be active
|
||||
*
|
||||
* @return self
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function table(?string $table): self;
|
||||
|
||||
/**
|
||||
* Update a value to a given table
|
||||
* Example: $this->value(Value, 'value_key', 'GUID');
|
||||
@ -38,43 +48,55 @@ interface UpdateInterface
|
||||
* Example: $this->item(Array);
|
||||
*
|
||||
* @param array $item The item to save
|
||||
* @param string $key The key name
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function row(array $item): bool;
|
||||
public function row(array $item, string $key = 'guid'): bool;
|
||||
|
||||
/**
|
||||
* Update multiple rows to a given table
|
||||
* Example: $this->items(Array);
|
||||
*
|
||||
* @param array|null $items The items updated in database (array of arrays)
|
||||
* @param string $key The key name
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function rows(?array $items): bool;
|
||||
public function rows(?array $items, string $key = 'guid'): bool;
|
||||
|
||||
/**
|
||||
* Update single item with multiple values to a given table
|
||||
* Example: $this->item(Object);
|
||||
*
|
||||
* @param object $item The item to save
|
||||
* @param string $key The key name
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function item(object $item): bool;
|
||||
public function item(object $item, string $key = 'guid'): bool;
|
||||
|
||||
/**
|
||||
* Update multiple items to a given table
|
||||
* Example: $this->items(Array);
|
||||
*
|
||||
* @param array|null $items The items updated in database (array of objects)
|
||||
* @param string $key The key name
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function items(?array $items): bool;
|
||||
public function items(?array $items, string $key = 'guid'): bool;
|
||||
|
||||
/**
|
||||
* Get the current active table
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function getTable(): string;
|
||||
}
|
||||
|
@ -0,0 +1,43 @@
|
||||
<?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\Interfaces;
|
||||
|
||||
|
||||
/**
|
||||
* Database Delete Interface
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
interface DeleteInterface
|
||||
{
|
||||
/**
|
||||
* Delete all rows in the database that match these conditions
|
||||
*
|
||||
* @param array $conditions Conditions by which to delete the data in database [array of arrays (key => value)]
|
||||
* @param string $table The table where the data is being deleted
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function items(array $conditions, string $table): bool;
|
||||
|
||||
/**
|
||||
* Truncate a table
|
||||
*
|
||||
* @param string $table The table that should be truncated
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.2
|
||||
**/
|
||||
public function truncate(string $table): void;
|
||||
}
|
||||
|
@ -19,6 +19,16 @@ namespace VDM\Joomla\Interfaces;
|
||||
*/
|
||||
interface ModelInterface
|
||||
{
|
||||
/**
|
||||
* Set the current active table
|
||||
*
|
||||
* @param string $table The table that should be active
|
||||
*
|
||||
* @return self
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function table(string $table): self;
|
||||
|
||||
/**
|
||||
* Model the value
|
||||
* Example: $this->value(value, 'value_key', 'table_name');
|
||||
@ -36,13 +46,13 @@ interface ModelInterface
|
||||
* Model the values of an item
|
||||
* Example: $this->item(Object, 'table_name');
|
||||
*
|
||||
* @param object $item The item object
|
||||
* @param object|null $item The item object
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return object|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function item(object $item, ?string $table = null): ?object;
|
||||
public function item(?object $item, ?string $table = null): ?object;
|
||||
|
||||
/**
|
||||
* Model the values of multiple items
|
||||
@ -60,13 +70,13 @@ interface ModelInterface
|
||||
* Model the values of an row
|
||||
* Example: $this->item(Array, 'table_name');
|
||||
*
|
||||
* @param array $item The item array
|
||||
* @param array|null $item The item array
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function row(array $item, ?string $table = null): ?array;
|
||||
public function row(?array $item, ?string $table = null): ?array;
|
||||
|
||||
/**
|
||||
* Model the values of multiple rows
|
||||
@ -89,6 +99,26 @@ interface ModelInterface
|
||||
* @return int|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function last(?string $table = null): ?int;
|
||||
public function last(?string $table = null): ?int;
|
||||
|
||||
/**
|
||||
* Set the current active table
|
||||
*
|
||||
* @param string $tableName The table name
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function setTable(string $tableName): void;
|
||||
|
||||
/**
|
||||
* Set the switch to control the behaviour of empty values
|
||||
*
|
||||
* @param bool $allowEmpty The switch
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function setAllowEmpty(bool $allowEmpty): void;
|
||||
}
|
||||
|
||||
|
@ -9,22 +9,22 @@
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Power\Model;
|
||||
namespace VDM\Joomla\Model;
|
||||
|
||||
|
||||
use VDM\Joomla\Abstraction\Model as AbstractionModel;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Utilities\ObjectHelper;
|
||||
use VDM\Joomla\Interfaces\ModelInterface;
|
||||
use VDM\Joomla\Abstraction\Model;
|
||||
|
||||
|
||||
/**
|
||||
* Power Model Load
|
||||
*
|
||||
* @since 3.2.0
|
||||
* @since 3.2.2
|
||||
*/
|
||||
class Load extends AbstractionModel implements ModelInterface
|
||||
final class Load extends Model implements ModelInterface
|
||||
{
|
||||
/**
|
||||
* Model the value
|
||||
@ -80,6 +80,11 @@ class Load extends AbstractionModel implements ModelInterface
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// check if we allow empty
|
||||
elseif ($this->getAllowEmpty() && empty($value))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// remove empty values
|
||||
return false;
|
||||
}
|
||||
@ -101,19 +106,13 @@ class Load extends AbstractionModel implements ModelInterface
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// check if we allow empty
|
||||
elseif ($this->getAllowEmpty() && empty($value))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// remove empty values
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current active table
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getTable(): string
|
||||
{
|
||||
return 'power';
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Power\Model;
|
||||
namespace VDM\Joomla\Model;
|
||||
|
||||
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
@ -24,7 +24,7 @@ use VDM\Joomla\Abstraction\Model;
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Upsert extends Model implements ModelInterface
|
||||
final class Upsert extends Model implements ModelInterface
|
||||
{
|
||||
/**
|
||||
* Model the value
|
||||
@ -80,6 +80,11 @@ class Upsert extends Model implements ModelInterface
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// check if we allow empty
|
||||
elseif ($this->getAllowEmpty() && empty($value))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// remove empty values
|
||||
return false;
|
||||
}
|
||||
@ -101,20 +106,13 @@ class Upsert extends Model implements ModelInterface
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// check if we allow empty
|
||||
elseif ($this->getAllowEmpty() && empty($value))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// remove empty values
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current active table
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getTable(): string
|
||||
{
|
||||
return 'power';
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
162
libraries/vendor_jcb/VDM.Joomla/src/Service/Data.php
Normal file
162
libraries/vendor_jcb/VDM.Joomla/src/Service/Data.php
Normal file
@ -0,0 +1,162 @@
|
||||
<?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\Service;
|
||||
|
||||
|
||||
use Joomla\DI\Container;
|
||||
use Joomla\DI\ServiceProviderInterface;
|
||||
use VDM\Joomla\Data\Action\Load;
|
||||
use VDM\Joomla\Data\Action\Insert;
|
||||
use VDM\Joomla\Data\Action\Update;
|
||||
use VDM\Joomla\Data\Action\Delete;
|
||||
use VDM\Joomla\Data\Item;
|
||||
use VDM\Joomla\Data\Items;
|
||||
|
||||
|
||||
/**
|
||||
* Data Service Provider
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Data implements ServiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* Registers the service provider with a DI container.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container->alias(Load::class, 'Data.Load')
|
||||
->share('Data.Load', [$this, 'getLoad'], true);
|
||||
|
||||
$container->alias(Insert::class, 'Data.Insert')
|
||||
->share('Data.Insert', [$this, 'getInsert'], true);
|
||||
|
||||
$container->alias(Update::class, 'Data.Update')
|
||||
->share('Data.Update', [$this, 'getUpdate'], true);
|
||||
|
||||
$container->alias(Delete::class, 'Data.Delete')
|
||||
->share('Data.Delete', [$this, 'getDelete'], true);
|
||||
|
||||
$container->alias(Item::class, 'Data.Item')
|
||||
->share('Data.Item', [$this, 'getItem'], true);
|
||||
|
||||
$container->alias(Items::class, 'Data.Items')
|
||||
->share('Data.Items', [$this, 'getItems'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get The Load Class.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Load
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getLoad(Container $container): Load
|
||||
{
|
||||
return new Load(
|
||||
$container->get('Model.Load'),
|
||||
$container->get('Load')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get The Insert Class.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Insert
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getInsert(Container $container): Insert
|
||||
{
|
||||
return new Insert(
|
||||
$container->get('Model.Upsert'),
|
||||
$container->get('Insert')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get The Update Class.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Update
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getUpdate(Container $container): Update
|
||||
{
|
||||
return new Update(
|
||||
$container->get('Model.Upsert'),
|
||||
$container->get('Update')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get The Delete Class.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Delete
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getDelete(Container $container): Delete
|
||||
{
|
||||
return new Delete(
|
||||
$container->get('Delete')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get The Item Class.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Item
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getItem(Container $container): Item
|
||||
{
|
||||
return new Item(
|
||||
$container->get('Data.Load'),
|
||||
$container->get('Data.Insert'),
|
||||
$container->get('Data.Update'),
|
||||
$container->get('Data.Delete'),
|
||||
$container->get('Load')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get The Items Class.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Items
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getItems(Container $container): Items
|
||||
{
|
||||
return new Items(
|
||||
$container->get('Data.Load'),
|
||||
$container->get('Data.Insert'),
|
||||
$container->get('Data.Update'),
|
||||
$container->get('Data.Delete'),
|
||||
$container->get('Load')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Componentbuilder\Service;
|
||||
namespace VDM\Joomla\Service;
|
||||
|
||||
|
||||
use Joomla\DI\Container;
|
||||
@ -17,6 +17,7 @@ use Joomla\DI\ServiceProviderInterface;
|
||||
use VDM\Joomla\Database\Load;
|
||||
use VDM\Joomla\Database\Insert;
|
||||
use VDM\Joomla\Database\Update;
|
||||
use VDM\Joomla\Database\Delete;
|
||||
|
||||
|
||||
/**
|
||||
@ -44,6 +45,9 @@ class Database implements ServiceProviderInterface
|
||||
|
||||
$container->alias(Update::class, 'Update')
|
||||
->share('Update', [$this, 'getUpdate'], true);
|
||||
|
||||
$container->alias(Delete::class, 'Delete')
|
||||
->share('Delete', [$this, 'getDelete'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -83,6 +87,19 @@ class Database implements ServiceProviderInterface
|
||||
public function getUpdate(Container $container): Update
|
||||
{
|
||||
return new Update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Core Delete Database
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Delete
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public function getDelete(Container $container): Delete
|
||||
{
|
||||
return new Delete();
|
||||
}
|
||||
}
|
||||
|
75
libraries/vendor_jcb/VDM.Joomla/src/Service/Model.php
Normal file
75
libraries/vendor_jcb/VDM.Joomla/src/Service/Model.php
Normal file
@ -0,0 +1,75 @@
|
||||
<?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\Service;
|
||||
|
||||
|
||||
use Joomla\DI\Container;
|
||||
use Joomla\DI\ServiceProviderInterface;
|
||||
use VDM\Joomla\Model\Load;
|
||||
use VDM\Joomla\Model\Upsert;
|
||||
|
||||
|
||||
/**
|
||||
* Model Service Provider
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Model implements ServiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* Registers the service provider with a DI container.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container->alias(Load::class, 'Model.Load')
|
||||
->share('Model.Load', [$this, 'getLoad'], true);
|
||||
|
||||
$container->alias(Upsert::class, 'Model.Upsert')
|
||||
->share('Model.Upsert', [$this, 'getUpsert'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get The Load Class.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Load
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getLoad(Container $container): Load
|
||||
{
|
||||
return new Load(
|
||||
$container->get('Table')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get The Upsert Class.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Upsert
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getUpsert(Container $container): Upsert
|
||||
{
|
||||
return new Upsert(
|
||||
$container->get('Table')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user