FEATURE: add registrators for settings form
This commit is contained in:
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Handlers\Registrators\Items;
|
||||||
|
|
||||||
|
class SettingExtension
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var string human readable ID of settings section (used e.g. as ID parameter in html)
|
||||||
|
*/
|
||||||
|
protected $id;
|
||||||
|
/**
|
||||||
|
* @var string translations string used for describing briefly settings section
|
||||||
|
*/
|
||||||
|
protected $name;
|
||||||
|
/**
|
||||||
|
* @var string view used for rendering given settings part
|
||||||
|
*/
|
||||||
|
protected $view;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SettingExtension constructor.
|
||||||
|
*
|
||||||
|
* @param string $id
|
||||||
|
* @param string $name
|
||||||
|
* @param string $view
|
||||||
|
*/
|
||||||
|
public function __construct($id, $name, $view)
|
||||||
|
{
|
||||||
|
$this->id = $id;
|
||||||
|
$this->name = $name;
|
||||||
|
$this->view = $view;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getId()
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getView()
|
||||||
|
{
|
||||||
|
return $this->view;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Handlers\Registrators;
|
||||||
|
|
||||||
|
use App\Enumerations\Exceptions\EnumerationExistsException;
|
||||||
|
use App\Handlers\Registrators\Items\SettingExtension;
|
||||||
|
|
||||||
|
class SettingsExtensionRegistrator
|
||||||
|
{
|
||||||
|
protected $settingsExtensions;
|
||||||
|
|
||||||
|
function __construct($app)
|
||||||
|
{
|
||||||
|
$this->settingsExtensions = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method for registering new settings extensions/parts
|
||||||
|
*
|
||||||
|
* @param $sectionId
|
||||||
|
* @param $sectionName
|
||||||
|
* @param $sectionView
|
||||||
|
*
|
||||||
|
* @throws EnumerationExistsException
|
||||||
|
*/
|
||||||
|
public function register($sectionId, $sectionName, $sectionView)
|
||||||
|
{
|
||||||
|
$this->checkIfRegistered($sectionId);
|
||||||
|
|
||||||
|
// register new extension
|
||||||
|
$this->settingsExtensions[$sectionId] = new SettingExtension($sectionId, $sectionName, $sectionView);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers new setting part - only as SettingExtension directly
|
||||||
|
*
|
||||||
|
* @param SettingExtension $extension
|
||||||
|
*/
|
||||||
|
public function registerObject(SettingExtension $extension)
|
||||||
|
{
|
||||||
|
$this->checkIfRegistered($extension->getId());
|
||||||
|
|
||||||
|
$this->settingsExtensions[$extension->getId()] = $extension;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for all registered extensions
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get()
|
||||||
|
{
|
||||||
|
return $this->settingsExtensions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if this section is not already defined
|
||||||
|
*
|
||||||
|
* @param $sectionId
|
||||||
|
*
|
||||||
|
* @throws EnumerationExistsException
|
||||||
|
*/
|
||||||
|
private function checkIfRegistered($sectionId)
|
||||||
|
{
|
||||||
|
if (isset($this->settingsExtensions[$sectionId])) {
|
||||||
|
throw new EnumerationExistsException('Already existing key ' . $sectionId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user