1414use yii \base \NotSupportedException ;
1515use yii \web \BadRequestHttpException ;
1616use yii \web \MethodNotAllowedHttpException ;
17+ use yii \web \Response ;
1718use yii \web \ServerErrorHttpException ;
1819
20+ /**
21+ * Class CpController
22+ *
23+ * This controller handles the Control Panel (CP) actions for the plugin.
24+ * It provides methods for managing plugin settings, such as generating or deleting API keys.
25+ *
26+ * @package digitaldiff\diffbase\controllers
27+ */
1928class CpController extends Controller
2029{
21-
2230 /**
23- * @throws NotSupportedException
24- * @throws InvalidConfigException
25- * @throws MissingComponentException
26- * @throws ServerErrorHttpException
27- * @throws StaleResourceException
28- * @throws BusyResourceException
29- * @throws ErrorException
30- * @throws Exception
31+ * Renders the main settings page for the plugin.
32+ *
33+ * - Initializes the plugin and its settings.
34+ * - Automatically generates an API key if none exists.
35+ *
36+ * @throws MissingComponentException If a required component is missing.
37+ * @throws Exception If the plugin is not initialized.
38+ * @return Response The rendered settings page.
3139 */
32- public function actionIndex (): \ yii \ web \ Response
40+ public function actionIndex (): Response
3341 {
3442 $ plugin = Plugin::getInstance ();
3543 if (!$ plugin ) {
@@ -54,6 +62,11 @@ public function actionIndex(): \yii\web\Response
5462 ]);
5563 }
5664
65+ /**
66+ * Retrieves the plugin settings.
67+ *
68+ * @return Settings The plugin settings model.
69+ */
5770 private function getSettings (): Settings
5871 {
5972 /** @var Settings $settings */
@@ -62,18 +75,24 @@ private function getSettings(): Settings
6275 }
6376
6477 /**
65- * @throws NotSupportedException
66- * @throws InvalidConfigException
67- * @throws MissingComponentException
68- * @throws MethodNotAllowedHttpException
69- * @throws ServerErrorHttpException
70- * @throws BadRequestHttpException
71- * @throws StaleResourceException
72- * @throws BusyResourceException
73- * @throws ErrorException
74- * @throws Exception
78+ * Generates a new API key and saves it to the plugin settings.
79+ *
80+ * - Requires a POST request.
81+ * - Displays a success notice upon completion.
82+ *
83+ * @throws NotSupportedException If the operation is not supported.
84+ * @throws InvalidConfigException If the configuration is invalid.
85+ * @throws MissingComponentException If a required component is missing.
86+ * @throws MethodNotAllowedHttpException If the request method is not allowed.
87+ * @throws ServerErrorHttpException If a server error occurs.
88+ * @throws BadRequestHttpException If the request is invalid.
89+ * @throws StaleResourceException If the resource is stale.
90+ * @throws BusyResourceException If the resource is busy.
91+ * @throws ErrorException If an error occurs during execution.
92+ * @throws Exception If an unexpected error occurs.
93+ * @return Response A redirect response to the posted URL.
7594 */
76- public function actionGenerateApiKey (): \ yii \ web \ Response
95+ public function actionGenerateApiKey (): Response
7796 {
7897 $ this ->requirePostRequest ();
7998
@@ -88,25 +107,36 @@ public function actionGenerateApiKey(): \yii\web\Response
88107 }
89108
90109 /**
91- * @throws MissingComponentException
92- * @throws MethodNotAllowedHttpException
93- * @throws BadRequestHttpException
110+ * Deletes the existing API key from the plugin settings.
111+ *
112+ * - Requires a POST request.
113+ * - Displays a success notice upon completion.
114+ *
115+ * @throws MissingComponentException If a required component is missing.
116+ * @throws MethodNotAllowedHttpException If the request method is not allowed.
117+ * @throws BadRequestHttpException If the request is invalid.
118+ * @return Response A redirect response to the posted URL.
94119 */
95- public function actionDeleteApiKey (): \ yii \ web \ Response
120+ public function actionDeleteApiKey (): Response
96121 {
97122 $ this ->requirePostRequest ();
98123
99124 // Settings ber Plugin speichern
100125 Craft::$ app ->plugins ->savePluginSettings (Plugin::getInstance (), ['apiKey ' => null ]);
101- Craft::$ app ->getSession ()->setNotice ('API-Key wurde gelscht . ' );
126+ Craft::$ app ->getSession ()->setNotice ('API-Key wurde gelöscht . ' );
102127
103128 return $ this ->redirectToPostedUrl ();
104129 }
105130
106131 /**
107- * @throws \Exception
132+ * Renders the settings page for the plugin.
133+ *
134+ * - Initializes the plugin and its settings.
135+ *
136+ * @throws \Exception If the plugin is not initialized.
137+ * @return Response The rendered settings page.
108138 */
109- public function actionSettings (): \ yii \ web \ Response
139+ public function actionSettings (): Response
110140 {
111141 $ plugin = Plugin::getInstance ();
112142 if (!$ plugin ) {
0 commit comments