FEATURE: add registrators for settings form
This commit is contained in:
@@ -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