Moved many field related get methods to its own classes

This commit is contained in:
2022-09-10 10:12:13 +02:00
parent 4a32d3d50e
commit c5a85f167e
34 changed files with 2406 additions and 32 deletions

View File

@@ -14,15 +14,16 @@ namespace VDM\Joomla\Componentbuilder\Compiler\Service;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use VDM\Joomla\Componentbuilder\Compiler\Config as CompilerConfig;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Registry;
/**
* Compiler Config Service Provider
* Compiler Service Provider
*
* @since 3.2.0
*/
class Config implements ServiceProviderInterface
class Compiler implements ServiceProviderInterface
{
/**
* Registers the service provider with a DI container.
@@ -34,8 +35,11 @@ class Config implements ServiceProviderInterface
*/
public function register(Container $container)
{
$container->alias(CompilerConfig::class, 'Config')
$container->alias(Config::class, 'Config')
->share('Config', [$this, 'getConfig'], true);
$container->alias(Registry::class, 'Registry')
->share('Registry', [$this, 'getRegistry'], true);
}
/**
@@ -43,12 +47,26 @@ class Config implements ServiceProviderInterface
*
* @param Container $container The DI container.
*
* @return CompilerConfig
* @return Config
* @since 3.2.0
*/
public function getConfig(Container $container): CompilerConfig
public function getConfig(Container $container): Config
{
return new CompilerConfig();
}
return new Config();
}
/**
* Get the Compiler Registry
*
* @param Container $container The DI container.
*
* @return Registry
* @since 3.2.0
*/
public function getRegistry(Container $container): Registry
{
return new Registry();
}
}

View File

@@ -13,7 +13,8 @@ namespace VDM\Joomla\Componentbuilder\Compiler\Service;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\DI\ServiceProviderInterface;
use Joomla\CMS\Version;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\EventInterface;
use VDM\Joomla\Componentbuilder\Compiler\JoomlaThree\Event as J3Event;
@@ -25,6 +26,14 @@ use VDM\Joomla\Componentbuilder\Compiler\JoomlaThree\Event as J3Event;
*/
class Event implements ServiceProviderInterface
{
/**
* Current Joomla Version We are IN
*
* @var int
* @since 3.2.0
**/
protected $currentVersion;
/**
* Registers the service provider with a DI container.
*
@@ -37,6 +46,27 @@ class Event implements ServiceProviderInterface
{
$container->alias(J3Event::class, 'J3.Event')
->share('J3.Event', [$this, 'getJ3Event'], true);
$container->alias(EventInterface::class, 'Event')
->share('Event', [$this, 'getEvent'], true);
}
/**
* Get the Event
*
* @param Container $container The DI container.
*
* @return EventInterface
* @since 3.2.0
*/
public function getEvent(Container $container): EventInterface
{
if (empty($this->currentVersion))
{
$this->currentVersion = Version::MAJOR_VERSION;
}
return $container->get('J' . $this->currentVersion . '.Event');
}
/**
@@ -44,12 +74,13 @@ class Event implements ServiceProviderInterface
*
* @param Container $container The DI container.
*
* @return EventInterface
* @return J3Event
* @since 3.2.0
*/
public function getJ3Event(Container $container): EventInterface
public function getJ3Event(Container $container): J3Event
{
return new J3Event();
}
}
}

View File

@@ -25,6 +25,14 @@ use VDM\Joomla\Componentbuilder\Compiler\Extension\JoomlaThree\InstallScript as
*/
class Extension implements ServiceProviderInterface
{
/**
* Current Joomla Version Being Build
*
* @var int
* @since 3.2.0
**/
protected $targetVersion;
/**
* Registers the service provider with a DI container.
*
@@ -35,6 +43,9 @@ class Extension implements ServiceProviderInterface
*/
public function register(Container $container)
{
$container->alias(GetScriptInterface::class, 'Extension.InstallScript')
->share('Extension.InstallScript', [$this, 'getExtensionInstallScript'], true);
$container->alias(J3InstallScript::class, 'J3.Extension.InstallScript')
->share('J3.Extension.InstallScript', [$this, 'getJ3ExtensionInstallScript'], true);
}
@@ -44,12 +55,31 @@ class Extension implements ServiceProviderInterface
*
* @param Container $container The DI container.
*
* @return J3InstallScript
* @since 3.2.0
*/
public function getJ3ExtensionInstallScript(Container $container): J3InstallScript
{
return new J3InstallScript();
}
/**
* Get the Joomla Extension Install Script
*
* @param Container $container The DI container.
*
* @return GetScriptInterface
* @since 3.2.0
*/
public function getJ3ExtensionInstallScript(Container $container): GetScriptInterface
public function getExtensionInstallScript(Container $container): GetScriptInterface
{
return new J3InstallScript();
}
if (empty($this->targetVersion))
{
$this->targetVersion = $container->get('Config')->joomla_version;
}
return $container->get('J' . $this->targetVersion . '.Extension.InstallScript');
}
}

View File

@@ -0,0 +1,250 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 30th April, 2015
* @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\Compiler\Service;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use VDM\Joomla\Componentbuilder\Compiler\Field as CompilerField;
use VDM\Joomla\Componentbuilder\Compiler\Field\Data;
use VDM\Joomla\Componentbuilder\Compiler\Field\Name;
use VDM\Joomla\Componentbuilder\Compiler\Field\TypeName;
use VDM\Joomla\Componentbuilder\Compiler\Field\UniqueName;
use VDM\Joomla\Componentbuilder\Compiler\Field\Validation;
use VDM\Joomla\Componentbuilder\Compiler\Field\Customcode;
use VDM\Joomla\Componentbuilder\Compiler\Field\DatabaseName;
use VDM\Joomla\Componentbuilder\Compiler\Field\JoomlaThree\CoreValidation as J3CoreValidation;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Field\CoreValidationInterface;
/**
* Compiler Field
*
* @since 3.2.0
*/
class Field implements ServiceProviderInterface
{
/**
* Current Joomla Version Being Build
*
* @var int
* @since 3.2.0
**/
protected $targetVersion;
/**
* 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(CompilerField::class, 'Field')
->share('Field', [$this, 'getField'], true);
$container->alias(Data::class, 'Field.Data')
->share('Field.Data', [$this, 'getData'], true);
$container->alias(Validation::class, 'Field.Validation')
->share('Field.Validation', [$this, 'getValidation'], true);
$container->alias(J3CoreValidation::class, 'J3.Field.Core.Validation')
->share('J3.Field.Core.Validation', [$this, 'getJ3CoreValidation'], true);
$container->alias(CoreValidationInterface::class, 'Field.Core.Validation')
->share('Field.Core.Validation', [$this, 'getCoreValidation'], true);
$container->alias(Customcode::class, 'Field.Customcode')
->share('Field.Customcode', [$this, 'getCustomcode'], true);
$container->alias(Name::class, 'Field.Name')
->share('Field.Name', [$this, 'getFieldName'], true);
$container->alias(TypeName::class, 'Field.Type.Name')
->share('Field.Type.Name', [$this, 'getFieldTypeName'], true);
$container->alias(UniqueName::class, 'Field.Unique.Name')
->share('Field.Unique.Name', [$this, 'getFieldUniqueName'], true);
$container->alias(DatabaseName::class, 'Field.Database.Name')
->share('Field.Database.Name', [$this, 'getFieldDatabaseName'], true);
}
/**
* Get the Compiler Field
*
* @param Container $container The DI container.
*
* @return CompilerField
* @since 3.2.0
*/
public function getField(Container $container): CompilerField
{
return new CompilerField(
$container->get('Field.Data'),
$container->get('Field.Name'),
$container->get('Field.Type.Name'),
$container->get('Field.Unique.Name')
);
}
/**
* Get the Compiler Field Data
*
* @param Container $container The DI container.
*
* @return Data
* @since 3.2.0
*/
public function getData(Container $container): Data
{
return new Data(
$container->get('Config'),
$container->get('Event'),
$container->get('History'),
$container->get('Placeholder'),
$container->get('Customcode'),
$container->get('Field.Customcode'),
$container->get('Field.Validation')
);
}
/**
* Get the Compiler Field Validation
*
* @param Container $container The DI container.
*
* @return Validation
* @since 3.2.0
*/
public function getValidation(Container $container): Validation
{
return new Validation(
$container->get('Registry'),
$container->get('Customcode.Gui'),
$container->get('Placeholder'),
$container->get('Customcode'),
$container->get('Field.Core.Validation')
);
}
/**
* Get the Compiler Field Joomla 3 Validation
*
* @param Container $container The DI container.
*
* @return J3CoreValidation
* @since 3.2.0
*/
public function getJ3CoreValidation(Container $container): J3CoreValidation
{
return new J3CoreValidation();
}
/**
* Get the Compiler Field Core Validation
*
* @param Container $container The DI container.
*
* @return CoreValidationInterface
* @since 3.2.0
*/
public function getCoreValidation(Container $container): CoreValidationInterface
{
if (empty($this->targetVersion))
{
$this->targetVersion = $container->get('Config')->joomla_version;
}
return $container->get('J' . $this->targetVersion . '.Field.Core.Validation');
}
/**
* Get the Compiler Field Customcode
*
* @param Container $container The DI container.
*
* @return Customcode
* @since 3.2.0
*/
public function getCustomcode(Container $container): Customcode
{
return new Customcode(
$container->get('Customcode.Dispenser')
);
}
/**
* Get the Compiler Field Name
*
* @param Container $container The DI container.
*
* @return Name
* @since 3.2.0
*/
public function getFieldName(Container $container): Name
{
return new Name(
$container->get('Placeholder'),
$container->get('Field.Unique.Name'),
$container->get('Registry')
);
}
/**
* Get the Compiler Field Type Name
*
* @param Container $container The DI container.
*
* @return TypeName
* @since 3.2.0
*/
public function getFieldTypeName(Container $container): TypeName
{
return new TypeName();
}
/**
* Get the Compiler Field Unique Name
*
* @param Container $container The DI container.
*
* @return UniqueName
* @since 3.2.0
*/
public function getFieldUniqueName(Container $container): UniqueName
{
return new UniqueName(
$container->get('Registry')
);
}
/**
* Get the Compiler Field Database Name
*
* @param Container $container The DI container.
*
* @return DatabaseName
* @since 3.2.0
*/
public function getFieldDatabaseName(Container $container): DatabaseName
{
return new DatabaseName(
$container->get('Registry')
);
}
}

View File

@@ -0,0 +1,88 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 30th April, 2015
* @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\Compiler\Service;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\CMS\Version;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\HistoryInterface;
use VDM\Joomla\Componentbuilder\Compiler\JoomlaThree\History as J3History;
/**
* History Service Provider
*
* @since 3.2.0
*/
class History implements ServiceProviderInterface
{
/**
* Current Joomla Version We are IN
*
* @var int
* @since 3.2.0
**/
protected $currentVersion;
/**
* 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(J3History::class, 'J3.History')
->share('J3.History', [$this, 'getJ3History'], true);
$container->alias(HistoryInterface::class, 'History')
->share('History', [$this, 'getHistory'], true);
}
/**
* Get the History
*
* @param Container $container The DI container.
*
* @return HistoryInterface
* @since 3.2.0
*/
public function getHistory(Container $container): HistoryInterface
{
if (empty($this->currentVersion))
{
$this->currentVersion = Version::MAJOR_VERSION;
}
return $container->get('J' . $this->currentVersion . '.History');
}
/**
* Get the Joomla 3 History
*
* @param Container $container The DI container.
*
* @return J3History
* @since 3.2.0
*/
public function getJ3History(Container $container): J3History
{
return new J3History(
$container->get('Config')
);
}
}