PicoPluginInterface.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * This file is part of Pico. It's copyrighted by the contributors recorded
  4. * in the version control history of the file, available from the following
  5. * original location:
  6. *
  7. * <https://github.com/picocms/Pico/blob/master/lib/PicoPluginInterface.php>
  8. *
  9. * SPDX-License-Identifier: MIT
  10. * License-Filename: LICENSE
  11. */
  12. /**
  13. * Common interface for Pico plugins
  14. *
  15. * For a list of supported events see {@see DummyPlugin}; you can use
  16. * {@see DummyPlugin} as template for new plugins. For a list of deprecated
  17. * events see {@see PicoDeprecated}.
  18. *
  19. * If you're developing a new plugin, you MUST both implement this interface
  20. * and define the class constant `API_VERSION`. You SHOULD always use the
  21. * API version of Pico's latest milestone when releasing a plugin. If you're
  22. * developing a new version of an existing plugin, it is strongly recommended
  23. * to update your plugin to use Pico's latest API version.
  24. *
  25. * @author Daniel Rudolf
  26. * @link http://picocms.org
  27. * @license http://opensource.org/licenses/MIT The MIT License
  28. * @version 3.0
  29. */
  30. interface PicoPluginInterface
  31. {
  32. /**
  33. * Handles a event that was triggered by Pico
  34. *
  35. * @param string $eventName name of the triggered event
  36. * @param array $params passed parameters
  37. */
  38. public function handleEvent(string $eventName, array $params);
  39. /**
  40. * Enables or disables this plugin
  41. *
  42. * @param bool $enabled enable (TRUE) or disable (FALSE) this plugin
  43. * @param bool $recursive when TRUE, enable or disable recursively.
  44. * In other words, if you enable a plugin, all required plugins are
  45. * enabled, too. When disabling a plugin, all depending plugins are
  46. * disabled likewise. Recursive operations are only performed as long
  47. * as a plugin wasn't enabled/disabled manually. This parameter is
  48. * optional and defaults to TRUE.
  49. * @param bool $auto enable or disable to fulfill a dependency. This
  50. * parameter is optional and defaults to FALSE.
  51. *
  52. * @throws RuntimeException thrown when a dependency fails
  53. *@see PicoPluginInterface::isEnabled()
  54. * @see PicoPluginInterface::isStatusChanged()
  55. *
  56. */
  57. public function setEnabled(bool $enabled, bool $recursive = true, bool $auto = false);
  58. /**
  59. * Returns a boolean indicating whether this plugin is enabled or not
  60. *
  61. * You musn't rely on the return value when Pico's `onConfigLoaded` event
  62. * wasn't triggered on all plugins yet. This method might even return NULL
  63. * then. The plugin's status might change later.
  64. *
  65. * @see PicoPluginInterface::setEnabled()
  66. *
  67. * @return bool|null plugin is enabled (TRUE) or disabled (FALSE)
  68. */
  69. public function isEnabled(): ?bool;
  70. /**
  71. * Returns TRUE if the plugin was ever enabled/disabled manually
  72. *
  73. * @see PicoPluginInterface::setEnabled()
  74. *
  75. * @return bool plugin is in its default state (TRUE), FALSE otherwise
  76. */
  77. public function isStatusChanged(): bool;
  78. /**
  79. * Returns a list of names of plugins required by this plugin
  80. *
  81. * @return string[] required plugins
  82. */
  83. public function getDependencies(): array;
  84. /**
  85. * Returns a list of plugins which depend on this plugin
  86. *
  87. * @return object[] dependant plugins
  88. */
  89. public function getDependants(): array;
  90. /**
  91. * Returns the plugin's instance of Pico
  92. *
  93. * @see Pico
  94. *
  95. * @return Pico the plugin's instance of Pico
  96. */
  97. public function getPico(): Pico;
  98. }