AbstractHookIntegrationController.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. <?php
  2. namespace ModulesGarden\Servers\ProxmoxVps\Core\Hook;
  3. /**
  4. * a base class for every hook integration controller
  5. */
  6. abstract class AbstractHookIntegrationController
  7. {
  8. /** @var string
  9. * allowed integration type
  10. */
  11. const TYPE_APPEND = 'append';
  12. /** @var string
  13. * allowed integration type
  14. */
  15. const TYPE_PREPEND = 'prepend';
  16. /** @var string
  17. * allowed integration type
  18. */
  19. const TYPE_REPLACE = 'replace';
  20. /** @var string
  21. * allowed integration type
  22. */
  23. const TYPE_CUSTOM = 'custom';
  24. /** @var string
  25. * allowed integration type
  26. */
  27. const TYPE_AFTER = 'after';
  28. /** @var string
  29. * allowed integration type
  30. */
  31. const TYPE_BEFORE = 'before';
  32. /** @var string
  33. * allowed insert integration type
  34. */
  35. const INSERT_TYPE_FULL = 'full';
  36. /** @var string
  37. * allowed insert integration type
  38. */
  39. const INSERT_TYPE_CONTENT = 'content';
  40. /** @var string
  41. * allowed insert integration type, this type includes only the main container conetnt
  42. */
  43. const INSERT_TYPE_MC_CONTENT = 'mc_content';
  44. /** @var null|string
  45. * determines the file name to be integrated which
  46. * if null, will not integrate
  47. */
  48. protected $fileName = null;
  49. /** @var null|array
  50. * determines the $_REQUEST params for which the integration should be done
  51. * if null, this condition will be skipped
  52. */
  53. protected $requestParams = null;
  54. /** @var null|callable
  55. * a callback for the admin area controller
  56. */
  57. protected $controllerCallback = null;
  58. /** @var null|string
  59. * a jQuery selector determines a DOM object to which the Vue App should be added
  60. * e.g '#exampleDiv', '.btn-container:first'
  61. */
  62. protected $jqSelector = null;
  63. /** @var string
  64. * states what type of integration should be used
  65. */
  66. protected $integrationType = self::TYPE_APPEND;
  67. /** @var null|string
  68. * a js function name, just for custom integration type
  69. */
  70. protected $jsFunctionName = null;
  71. /** @var string
  72. * states what type of insert integration should be used
  73. */
  74. protected $insertIntegrationType = self::INSERT_TYPE_CONTENT;
  75. /**
  76. * @param null|string $fileName
  77. */
  78. public function setFileName($fileName)
  79. {
  80. if ((is_string($fileName) && $fileName !== '') || $fileName === null)
  81. {
  82. $this->fileName = $fileName;
  83. }
  84. return $this;
  85. }
  86. /**
  87. * @param null|array $requestParams
  88. */
  89. public function setRequestParams($requestParams = null)
  90. {
  91. if (is_array($requestParams) || $requestParams === null)
  92. {
  93. $this->requestParams = $requestParams;
  94. }
  95. return $this;
  96. }
  97. /**
  98. * @param callable|null $controllerCallback
  99. */
  100. public function setControllerCallback($controllerCallback)
  101. {
  102. $this->controllerCallback = $controllerCallback;
  103. }
  104. /**
  105. * @param null|string $jqSelector
  106. */
  107. public function setJqSelector($jqSelector)
  108. {
  109. if ((is_string($jqSelector) && $jqSelector !== '') || $jqSelector === null)
  110. {
  111. $this->jqSelector = $jqSelector;
  112. }
  113. }
  114. /**
  115. * @param string $type
  116. * @return self::class
  117. */
  118. public function setIntegrationType($type = null)
  119. {
  120. if (in_array($type, $this->getAvailableIntegrationTypes()))
  121. {
  122. $this->integrationType = $type;
  123. }
  124. return $this;
  125. }
  126. /**
  127. * @param null|string $jsFunctionName
  128. */
  129. public function setJsFunctionName ($jsFunctionName)
  130. {
  131. if ($jsFunctionName !== '' && is_string($jsFunctionName))
  132. {
  133. $this->jsFunctionName = $jsFunctionName;
  134. }
  135. return $this;
  136. }
  137. /**
  138. * @return null|string
  139. */
  140. public function getJsFunctionName ()
  141. {
  142. return $this->jsFunctionName;
  143. }
  144. /**
  145. * @return null|string
  146. */
  147. public function getFileName()
  148. {
  149. return $this->fileName;
  150. }
  151. /**
  152. * @return null|array
  153. */
  154. public function getRequestParams()
  155. {
  156. return $this->requestParams;
  157. }
  158. /**
  159. * @return callable|null
  160. */
  161. public function getControllerCallback()
  162. {
  163. return $this->controllerCallback;
  164. }
  165. /**
  166. * @return null|string
  167. */
  168. public function getJqSelector()
  169. {
  170. return $this->jqSelector;
  171. }
  172. /**
  173. * @return string
  174. */
  175. public function getIntegrationType()
  176. {
  177. return $this->integrationType;
  178. }
  179. /**
  180. * @return array
  181. * returns a list of integration types possible to use
  182. */
  183. public function getAvailableIntegrationTypes()
  184. {
  185. return [
  186. self::TYPE_APPEND,
  187. self::TYPE_PREPEND,
  188. self::TYPE_REPLACE,
  189. self::TYPE_CUSTOM,
  190. self::TYPE_AFTER,
  191. self::TYPE_BEFORE
  192. ];
  193. }
  194. /**
  195. * @param string $type
  196. * @return self::class
  197. */
  198. public function setIntegrationInsertType($type = null)
  199. {
  200. if (in_array($type, $this->getAvailableInsertIntegrationTypes()))
  201. {
  202. $this->insertIntegrationType = $type;
  203. }
  204. return $this;
  205. }
  206. /**
  207. *
  208. * @return type string
  209. */
  210. public function getIntegrationInsertType()
  211. {
  212. return $this->insertIntegrationType;
  213. }
  214. /**
  215. *
  216. * @return type array
  217. */
  218. public function getAvailableInsertIntegrationTypes()
  219. {
  220. return [
  221. self::INSERT_TYPE_CONTENT,
  222. self::INSERT_TYPE_FULL,
  223. self::INSERT_TYPE_MC_CONTENT
  224. ];
  225. }
  226. /**
  227. * a wrapper to set up integration process quickly
  228. */
  229. public function addIntegration($fileName = null, $requestParams = null, $controllerCallback = null, $jqSelector = null,
  230. $integrationType = null, $jsFunctionName = null, $insertIntegrationType = null)
  231. {
  232. $this->setFileName($fileName);
  233. $this->setRequestParams($requestParams);
  234. $this->setControllerCallback($controllerCallback);
  235. $this->setJqSelector($jqSelector);
  236. $this->setIntegrationType($integrationType);
  237. $this->setJsFunctionName($jsFunctionName);
  238. $this->setIntegrationInsertType($insertIntegrationType);
  239. }
  240. }