| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279 |
- <?php
- namespace ModulesGarden\Servers\ProxmoxCloudVps\Core\Hook;
- /**
- * a base class for every hook integration controller
- */
- abstract class AbstractHookIntegrationController
- {
- /** @var string
- * allowed integration type
- */
- const TYPE_APPEND = 'append';
- /** @var string
- * allowed integration type
- */
- const TYPE_PREPEND = 'prepend';
- /** @var string
- * allowed integration type
- */
- const TYPE_REPLACE = 'replace';
- /** @var string
- * allowed integration type
- */
- const TYPE_CUSTOM = 'custom';
- /** @var string
- * allowed integration type
- */
- const TYPE_AFTER = 'after';
- /** @var string
- * allowed integration type
- */
- const TYPE_BEFORE = 'before';
- /** @var string
- * allowed insert integration type
- */
- const INSERT_TYPE_FULL = 'full';
- /** @var string
- * allowed insert integration type
- */
- const INSERT_TYPE_CONTENT = 'content';
- /** @var string
- * allowed insert integration type, this type includes only the main container conetnt
- */
- const INSERT_TYPE_MC_CONTENT = 'mc_content';
- /** @var null|string
- * determines the file name to be integrated which
- * if null, will not integrate
- */
- protected $fileName = null;
- /** @var null|array
- * determines the $_REQUEST params for which the integration should be done
- * if null, this condition will be skipped
- */
- protected $requestParams = null;
- /** @var null|callable
- * a callback for the admin area controller
- */
- protected $controllerCallback = null;
- /** @var null|string
- * a jQuery selector determines a DOM object to which the Vue App should be added
- * e.g '#exampleDiv', '.btn-container:first'
- */
- protected $jqSelector = null;
- /** @var string
- * states what type of integration should be used
- */
- protected $integrationType = self::TYPE_APPEND;
- /** @var null|string
- * a js function name, just for custom integration type
- */
- protected $jsFunctionName = null;
- /** @var string
- * states what type of insert integration should be used
- */
- protected $insertIntegrationType = self::INSERT_TYPE_CONTENT;
- /**
- * @param null|string $fileName
- */
- public function setFileName($fileName)
- {
- if ((is_string($fileName) && $fileName !== '') || $fileName === null)
- {
- $this->fileName = $fileName;
- }
- return $this;
- }
- /**
- * @param null|array $requestParams
- */
- public function setRequestParams($requestParams = null)
- {
- if (is_array($requestParams) || $requestParams === null)
- {
- $this->requestParams = $requestParams;
- }
- return $this;
- }
- /**
- * @param callable|null $controllerCallback
- */
- public function setControllerCallback($controllerCallback)
- {
- $this->controllerCallback = $controllerCallback;
- }
- /**
- * @param null|string $jqSelector
- */
- public function setJqSelector($jqSelector)
- {
- if ((is_string($jqSelector) && $jqSelector !== '') || $jqSelector === null)
- {
- $this->jqSelector = $jqSelector;
- }
- }
- /**
- * @param string $type
- * @return self::class
- */
- public function setIntegrationType($type = null)
- {
- if (in_array($type, $this->getAvailableIntegrationTypes()))
- {
- $this->integrationType = $type;
- }
- return $this;
- }
- /**
- * @param null|string $jsFunctionName
- */
- public function setJsFunctionName ($jsFunctionName)
- {
- if ($jsFunctionName !== '' && is_string($jsFunctionName))
- {
- $this->jsFunctionName = $jsFunctionName;
- }
- return $this;
- }
- /**
- * @return null|string
- */
- public function getJsFunctionName ()
- {
- return $this->jsFunctionName;
- }
- /**
- * @return null|string
- */
- public function getFileName()
- {
- return $this->fileName;
- }
- /**
- * @return null|array
- */
- public function getRequestParams()
- {
- return $this->requestParams;
- }
- /**
- * @return callable|null
- */
- public function getControllerCallback()
- {
- return $this->controllerCallback;
- }
- /**
- * @return null|string
- */
- public function getJqSelector()
- {
- return $this->jqSelector;
- }
- /**
- * @return string
- */
- public function getIntegrationType()
- {
- return $this->integrationType;
- }
- /**
- * @return array
- * returns a list of integration types possible to use
- */
- public function getAvailableIntegrationTypes()
- {
- return [
- self::TYPE_APPEND,
- self::TYPE_PREPEND,
- self::TYPE_REPLACE,
- self::TYPE_CUSTOM,
- self::TYPE_AFTER,
- self::TYPE_BEFORE
- ];
- }
- /**
- * @param string $type
- * @return self::class
- */
- public function setIntegrationInsertType($type = null)
- {
- if (in_array($type, $this->getAvailableInsertIntegrationTypes()))
- {
- $this->insertIntegrationType = $type;
- }
- return $this;
- }
- /**
- *
- * @return type string
- */
- public function getIntegrationInsertType()
- {
- return $this->insertIntegrationType;
- }
- /**
- *
- * @return type array
- */
- public function getAvailableInsertIntegrationTypes()
- {
- return [
- self::INSERT_TYPE_CONTENT,
- self::INSERT_TYPE_FULL,
- self::INSERT_TYPE_MC_CONTENT
- ];
- }
- /**
- * a wrapper to set up integration process quickly
- */
- public function addIntegration($fileName = null, $requestParams = null, $controllerCallback = null, $jqSelector = null,
- $integrationType = null, $jsFunctionName = null, $insertIntegrationType = null)
- {
- $this->setFileName($fileName);
- $this->setRequestParams($requestParams);
- $this->setControllerCallback($controllerCallback);
- $this->setJqSelector($jqSelector);
- $this->setIntegrationType($integrationType);
- $this->setJsFunctionName($jsFunctionName);
- $this->setIntegrationInsertType($insertIntegrationType);
- }
- }
|