From 62855c5029a4e4a9341f662137946aa8b14ceb87 Mon Sep 17 00:00:00 2001 From: Ibrahim BinAlshikh Date: Tue, 19 Mar 2024 07:58:16 +0300 Subject: [PATCH 1/4] refactor: Removal of Two Deprecated Classes --- webfiori/framework/EAbstractWebService.php | 44 -- .../framework/ExtendedWebServicesManager.php | 437 ------------------ 2 files changed, 481 deletions(-) delete mode 100644 webfiori/framework/EAbstractWebService.php delete mode 100644 webfiori/framework/ExtendedWebServicesManager.php diff --git a/webfiori/framework/EAbstractWebService.php b/webfiori/framework/EAbstractWebService.php deleted file mode 100644 index 93766386..00000000 --- a/webfiori/framework/EAbstractWebService.php +++ /dev/null @@ -1,44 +0,0 @@ -setTranslationHelper(); - $langCode = $this->getTranslation()->getCode(); - $generalDir = 'general'; - $this->createLangDir($generalDir); - - if ($langCode == 'AR') { - $this->setLangVars($generalDir, [ - 'action-not-supported' => 'العملية غير مدعومة.', - 'content-not-supported' => 'نوع المحتوى غير مدعوم.', - 'action-not-impl' => 'لم يتم تنفيذ العملية.', - 'missing-params' => 'المعاملات التالية مفقودة من جسم الطلب: ', - 'inv-params' => 'المُعاملات التالية لديها قيم غير صالحة: ', - 'db-error' => 'خطأ في قاعدة البيانات.' - ]); - } else { - $this->setLangVars($generalDir, [ - 'action-not-supported' => 'Action is not supported by the API.', - 'content-not-supported' => 'Content type not supported.', - 'action-not-impl' => 'API action is not implemented yet.', - 'missing-params' => 'The following required parameter(s) where missing from the request body: ', - 'inv-params' => 'The following parameter(s) has invalid values: ', - 'db-error' => 'Database Error.' - ]); - } - } - /** - * Sends a response message to indicate that an action is not implemented. - * - * This method will send back a JSON string in the following format: - *

- * {
- *   "message":"Action not implemented.",
- *   "type":"error",
- * } - *

- * In addition to the message, The response will sent HTTP code 404 - Not Found. - * Note that the content of the field "message" might differ. It depends on - * the language. If no language is selected or language is not supported, - * The language that will be used is the language that was set as default - * language in the class 'SiteConfig'. - * - * @since 1.0 - */ - public function actionNotImpl() { - $message = $this->get('general/action-not-impl'); - $this->sendResponse($message, self::$E, 404); - } - /** - * Sends a response message to indicate that an action is not supported by the API. - * - * This method will send back a JSON string in the following format: - *

- * {
- *   "message":"Action not supported",
- *   "type":"error"
- * } - *

- * In addition to the message, The response will sent HTTP code 404 - Not Found. - * Note that the content of the field "message" might differ. It depends on - * the language. If no language is selected or language is not supported, - * The language that will be used is the language that was set as default - * language in the class 'SiteConfig'. - * - * @since 1.0 - */ - public function actionNotSupported() { - $message = $this->get('general/action-not-supported'); - $this->sendResponse($message, self::$E, 404); - } - /** - * Sends a response message to indicate that request content type is - * not supported by the API. - * - * This method will send back a JSON string in the following format: - *

- * {
- *   "message":"Content type not supported.",
- *   "type":"error",
- *   "request-content-type":"content_type"
- * } - *

- * In addition to the message, The response will sent HTTP code 404 - Not Found. - * Note that the content of the field "message" might differ. It depends on - * the language. If no language is selected or language is not supported, - * The language that will be used is the language that was set as default - * language in the class 'SiteConfig'. - * - * @since 1.1 - */ - public function contentTypeNotSupported(string $cType = '') { - $message = $this->get('general/content-not-supported'); - $this->sendResponse($message, self::$E, 404,'"request-content-type":"'.$cType.'"'); - } - /** - * Creates a sub array to define language variables. - * - * An example: if the given string is 'general', - * an array with key name 'general' will be created. Another example is - * if the given string is 'pages/login', two arrays will be created. The - * top one will have the key value 'pages' and another one inside - * the pages array with key value 'login'. - * - * @param string $dir A string that looks like a directory. - * - * @since 1.0 - */ - public function createLangDir(string $dir) { - $this->getTranslation()->createDirectory($dir); - } - /** - * Sends a response message to indicate that a database error has occur. - * - * This method will send back a JSON string in the following format: - *

- * {
- *   "message":"a_message",
- *   "type":"error",
- *   "err-info":OTHER_DATA
- * } - *

- * In here, 'OTHER_DATA' can be a basic string. - * Also, The response will sent HTTP code 404 - Not Found. - * - * @param JsonI|Json|DB|string $info An object of type JsonI or - * Json that describe the error in more details. Also it can be a simple string. - * Also, this parameter can be a database instance that contains database error - * information. - * Note that the content of the field "message" might differ. It depends on - * the language. If no language is selected or language is not supported, - * The language that will be used is the language that was set as default - * language in the class 'SiteConfig'. - * - * @since 1.0 - */ - public function databaseErr($info = '') { - $message = $this->get('general/db-error'); - - if ($info instanceof DB) { - $dbErr = $info->getLastError(); - $json = new Json([ - 'error-message' => $dbErr['message'], - 'error-code' => $dbErr['code'] - ]); - - if (defined('WF_VERBOSE') && WF_VERBOSE === true) { - $json->add('query', $info->getLastQuery()); - } - $this->sendResponse($message, self::$E, 404, $json); - } else { - $this->sendResponse($message, self::$E, 404, $info); - } - } - /** - * Returns the value of a language variable. - * - * @param string $dir A directory to the language variable (such as 'pages/login/login-label'). - * - * @return string|array If the given directory represents a label, the - * method will return its value. If it represents an array, the array will - * be returned. If nothing was found, the returned value will be the passed - * value to the method. - * - * @since 1.0 - */ - public function get(string $dir) { - return Lang::getLabel($dir); - } - /** - * Returns an associative array that contains HTTP authorization header - * content. - * - * The generated associative array will have two indices: - * - * Note that if no authorization header is sent, The two indices will be empty. - * - * @return array An associative array. - * - * @since 1.0.1 - */ - public function getAuthorizationHeader() { - $retVal = [ - 'type' => '', - 'credentials' => '' - ]; - $headers = Util::getRequestHeaders(); - - if (isset($headers['authorization'])) { - $split = explode(' ', $headers['authorization']); - - if (count($split) == 2) { - $retVal['type'] = strtolower($split[0]); - $retVal['credentials'] = $split[1]; - } - } - - return $retVal; - } - /** - * Returns the language instance which is linked with the API instance. - * - * @return Lang an instance of the class 'Lang'. - * - * @since 1.0 - */ - public function getTranslation() { - return $this->translation; - } - /** - * Sends a response message to indicate that a request parameter(s) have invalid values. - * - * This method will send back a JSON string in the following format: - *

- * {
- *   "message":"The following parameter(s) has invalid values: 'param_1', 'param_2', 'param_n'",
- *   "type":"error"
- * } - *

- * In addition to the message, The response will sent HTTP code 404 - Not Found. - * Note that the content of the field "message" might differ. It depends on - * the language. If no language is selected or language is not supported, - * The language that will be used is the language that was set as default - * language in the class 'SiteConfig'. - * - * @since 1.3 - */ - public function invParams() { - $val = ''; - $paramsNamesArr = $this->getInvalidParameters(); - - if (gettype($paramsNamesArr) == 'array') { - $i = 0; - $count = count($paramsNamesArr); - - foreach ($paramsNamesArr as $paramName) { - if ($i + 1 == $count) { - $val .= '\''.$paramName.'\''; - } else { - $val .= '\''.$paramName.'\', '; - } - $i++; - } - } - $message = $this->get('general/inv-params'); - $this->sendResponse($message.$val.'.', self::$E, 404); - } - /** - * Sends a response message to indicate that a request parameter or parameters are missing. - * - * This method will send back a JSON string in the following format: - *

- * {
- *   "message":"The following required parameter(s) where missing from the request body: 'param_1', 'param_2', 'param_n'",
- *   "type":"error",
- * } - *

- * In addition to the message, The response will sent HTTP code 404 - Not Found. - * Note that the content of the field "message" might differ. It depends on - * the language. If no language is selected or language is not supported, - * The language that will be used is the language that was set as default - * language in the class 'SiteConfig'. - * - * @since 1.3 - */ - public function missingParams() { - $val = ''; - $paramsNamesArr = $this->getMissingParameters(); - - if (gettype($paramsNamesArr) == 'array') { - $i = 0; - $count = count($paramsNamesArr); - - foreach ($paramsNamesArr as $paramName) { - if ($i + 1 == $count) { - $val .= '\''.$paramName.'\''; - } else { - $val .= '\''.$paramName.'\', '; - } - $i++; - } - } - $message = $this->get('general/missing-params'); - $this->sendResponse($message.$val.'.', self::$E, 404); - } - /** - * Sends a response message to indicate that a user is not authorized to - * do an API call. - * - * This method will send back a JSON string in the following format: - *

- * {
- *   "message":"Not authorized",
- *   "type":"error"
- * } - *

- * In addition to the message, The response will sent HTTP code 401 - Not Authorized. - * Note that the content of the field "message" might differ. It depends on - * the language. If no language is selected or language is not supported, - * The language that will be used is the language that was set as default - * language in the class 'SiteConfig'. - * - * @since 1.0 - */ - public function notAuth() { - $message = $this->get('general/http-codes/401/message'); - $this->sendResponse($message, self::$E, 401); - } - /** - * Auto-register services tables which exist on a specific directory. - * - * Note that the statement 'return __NAMESPACE__' should be included at the - * end of service class for auto-register to work. If the statement - * does not exist, the method will assume that the path is the namespace of - * each class. Also, the classes which represents web services must be suffixed - * with the word 'Service' in order to register them (e.g. RegisterUserService). - * - * @param string $pathToScan A path which is relative to application source - * code folder. For example, if application folder name is 'my-app' and - * the web services are in the folder 'my-app/apis/user, - * then the value of the argument must be 'apis/user'. - * - * @since 1.0.1 - */ - public function registerServices($pathToScan) { - App::autoRegister($pathToScan, function (AbstractWebService $ws, ExtendedWebServicesManager $m) - { - $m->addService($ws); - }, 'Service', [$this], [$this]); - } - /** - * Sends a response message to indicate that request method is not supported. - * - * This method will send back a JSON string in the following format: - *

- * {
- *   "message":"Method Not Allowed.",
- *   "type":"error",
- * } - *

- * In addition to the message, The response will sent HTTP code 405 - Method Not Allowed. - * Note that the content of the field "message" might differ. It depends on - * the language. If no language is selected or language is not supported, - * The language that will be used is the language that was set as default - * language in the class 'SiteConfig'. - * - * @since 1.0 - */ - public function requestMethodNotAllowed() { - $message = $this->get('general/http-codes/405/message'); - $this->sendResponse($message, self::$E, 405); - } - /** - * Sets multiple language variables. - * - * @param string $dir A string that looks like a - * directory. - * - * @param array $arr An associative array. The key will act as the variable - * and the value of the key will act as the variable value. - * - * @since 1.0 - */ - public function setLangVars($dir,$arr = []) { - $this->getTranslation()->setMultiple($dir, $arr); - } - /** - * Set the language at which the API is going to use for the response. - */ - private function setTranslationHelper() { - $reqMeth = Request::getMethod(); - $activeSession = SessionsManager::getActiveSession(); - - if ($activeSession !== null) { - $tempCode = $activeSession->getLangCode(true); - } else { - $tempCode = App::getConfig()->getPrimaryLanguage(); - } - - if ($reqMeth == 'GET' || $reqMeth == 'DELETE') { - $langCode = isset($_GET['lang']) ? filter_var($_GET['lang']) : $tempCode; - } else if ($reqMeth == 'POST' || $reqMeth == 'PUT') { - $langCode = isset($_POST['lang']) ? filter_var($_POST['lang']) : $tempCode; - } else { - $langCode = $tempCode; - } - $this->translation = Lang::loadTranslation($langCode); - } -} From b8ac09554b6369d9da1914497b017c9157eda332 Mon Sep 17 00:00:00 2001 From: Ibrahim BinAlshikh Date: Tue, 19 Mar 2024 08:02:41 +0300 Subject: [PATCH 2/4] Revert "refactor: Removal of Two Deprecated Classes" This reverts commit 62855c5029a4e4a9341f662137946aa8b14ceb87. --- webfiori/framework/EAbstractWebService.php | 44 ++ .../framework/ExtendedWebServicesManager.php | 437 ++++++++++++++++++ 2 files changed, 481 insertions(+) create mode 100644 webfiori/framework/EAbstractWebService.php create mode 100644 webfiori/framework/ExtendedWebServicesManager.php diff --git a/webfiori/framework/EAbstractWebService.php b/webfiori/framework/EAbstractWebService.php new file mode 100644 index 00000000..93766386 --- /dev/null +++ b/webfiori/framework/EAbstractWebService.php @@ -0,0 +1,44 @@ +setTranslationHelper(); + $langCode = $this->getTranslation()->getCode(); + $generalDir = 'general'; + $this->createLangDir($generalDir); + + if ($langCode == 'AR') { + $this->setLangVars($generalDir, [ + 'action-not-supported' => 'العملية غير مدعومة.', + 'content-not-supported' => 'نوع المحتوى غير مدعوم.', + 'action-not-impl' => 'لم يتم تنفيذ العملية.', + 'missing-params' => 'المعاملات التالية مفقودة من جسم الطلب: ', + 'inv-params' => 'المُعاملات التالية لديها قيم غير صالحة: ', + 'db-error' => 'خطأ في قاعدة البيانات.' + ]); + } else { + $this->setLangVars($generalDir, [ + 'action-not-supported' => 'Action is not supported by the API.', + 'content-not-supported' => 'Content type not supported.', + 'action-not-impl' => 'API action is not implemented yet.', + 'missing-params' => 'The following required parameter(s) where missing from the request body: ', + 'inv-params' => 'The following parameter(s) has invalid values: ', + 'db-error' => 'Database Error.' + ]); + } + } + /** + * Sends a response message to indicate that an action is not implemented. + * + * This method will send back a JSON string in the following format: + *

+ * {
+ *   "message":"Action not implemented.",
+ *   "type":"error",
+ * } + *

+ * In addition to the message, The response will sent HTTP code 404 - Not Found. + * Note that the content of the field "message" might differ. It depends on + * the language. If no language is selected or language is not supported, + * The language that will be used is the language that was set as default + * language in the class 'SiteConfig'. + * + * @since 1.0 + */ + public function actionNotImpl() { + $message = $this->get('general/action-not-impl'); + $this->sendResponse($message, self::$E, 404); + } + /** + * Sends a response message to indicate that an action is not supported by the API. + * + * This method will send back a JSON string in the following format: + *

+ * {
+ *   "message":"Action not supported",
+ *   "type":"error"
+ * } + *

+ * In addition to the message, The response will sent HTTP code 404 - Not Found. + * Note that the content of the field "message" might differ. It depends on + * the language. If no language is selected or language is not supported, + * The language that will be used is the language that was set as default + * language in the class 'SiteConfig'. + * + * @since 1.0 + */ + public function actionNotSupported() { + $message = $this->get('general/action-not-supported'); + $this->sendResponse($message, self::$E, 404); + } + /** + * Sends a response message to indicate that request content type is + * not supported by the API. + * + * This method will send back a JSON string in the following format: + *

+ * {
+ *   "message":"Content type not supported.",
+ *   "type":"error",
+ *   "request-content-type":"content_type"
+ * } + *

+ * In addition to the message, The response will sent HTTP code 404 - Not Found. + * Note that the content of the field "message" might differ. It depends on + * the language. If no language is selected or language is not supported, + * The language that will be used is the language that was set as default + * language in the class 'SiteConfig'. + * + * @since 1.1 + */ + public function contentTypeNotSupported(string $cType = '') { + $message = $this->get('general/content-not-supported'); + $this->sendResponse($message, self::$E, 404,'"request-content-type":"'.$cType.'"'); + } + /** + * Creates a sub array to define language variables. + * + * An example: if the given string is 'general', + * an array with key name 'general' will be created. Another example is + * if the given string is 'pages/login', two arrays will be created. The + * top one will have the key value 'pages' and another one inside + * the pages array with key value 'login'. + * + * @param string $dir A string that looks like a directory. + * + * @since 1.0 + */ + public function createLangDir(string $dir) { + $this->getTranslation()->createDirectory($dir); + } + /** + * Sends a response message to indicate that a database error has occur. + * + * This method will send back a JSON string in the following format: + *

+ * {
+ *   "message":"a_message",
+ *   "type":"error",
+ *   "err-info":OTHER_DATA
+ * } + *

+ * In here, 'OTHER_DATA' can be a basic string. + * Also, The response will sent HTTP code 404 - Not Found. + * + * @param JsonI|Json|DB|string $info An object of type JsonI or + * Json that describe the error in more details. Also it can be a simple string. + * Also, this parameter can be a database instance that contains database error + * information. + * Note that the content of the field "message" might differ. It depends on + * the language. If no language is selected or language is not supported, + * The language that will be used is the language that was set as default + * language in the class 'SiteConfig'. + * + * @since 1.0 + */ + public function databaseErr($info = '') { + $message = $this->get('general/db-error'); + + if ($info instanceof DB) { + $dbErr = $info->getLastError(); + $json = new Json([ + 'error-message' => $dbErr['message'], + 'error-code' => $dbErr['code'] + ]); + + if (defined('WF_VERBOSE') && WF_VERBOSE === true) { + $json->add('query', $info->getLastQuery()); + } + $this->sendResponse($message, self::$E, 404, $json); + } else { + $this->sendResponse($message, self::$E, 404, $info); + } + } + /** + * Returns the value of a language variable. + * + * @param string $dir A directory to the language variable (such as 'pages/login/login-label'). + * + * @return string|array If the given directory represents a label, the + * method will return its value. If it represents an array, the array will + * be returned. If nothing was found, the returned value will be the passed + * value to the method. + * + * @since 1.0 + */ + public function get(string $dir) { + return Lang::getLabel($dir); + } + /** + * Returns an associative array that contains HTTP authorization header + * content. + * + * The generated associative array will have two indices: + * + * Note that if no authorization header is sent, The two indices will be empty. + * + * @return array An associative array. + * + * @since 1.0.1 + */ + public function getAuthorizationHeader() { + $retVal = [ + 'type' => '', + 'credentials' => '' + ]; + $headers = Util::getRequestHeaders(); + + if (isset($headers['authorization'])) { + $split = explode(' ', $headers['authorization']); + + if (count($split) == 2) { + $retVal['type'] = strtolower($split[0]); + $retVal['credentials'] = $split[1]; + } + } + + return $retVal; + } + /** + * Returns the language instance which is linked with the API instance. + * + * @return Lang an instance of the class 'Lang'. + * + * @since 1.0 + */ + public function getTranslation() { + return $this->translation; + } + /** + * Sends a response message to indicate that a request parameter(s) have invalid values. + * + * This method will send back a JSON string in the following format: + *

+ * {
+ *   "message":"The following parameter(s) has invalid values: 'param_1', 'param_2', 'param_n'",
+ *   "type":"error"
+ * } + *

+ * In addition to the message, The response will sent HTTP code 404 - Not Found. + * Note that the content of the field "message" might differ. It depends on + * the language. If no language is selected or language is not supported, + * The language that will be used is the language that was set as default + * language in the class 'SiteConfig'. + * + * @since 1.3 + */ + public function invParams() { + $val = ''; + $paramsNamesArr = $this->getInvalidParameters(); + + if (gettype($paramsNamesArr) == 'array') { + $i = 0; + $count = count($paramsNamesArr); + + foreach ($paramsNamesArr as $paramName) { + if ($i + 1 == $count) { + $val .= '\''.$paramName.'\''; + } else { + $val .= '\''.$paramName.'\', '; + } + $i++; + } + } + $message = $this->get('general/inv-params'); + $this->sendResponse($message.$val.'.', self::$E, 404); + } + /** + * Sends a response message to indicate that a request parameter or parameters are missing. + * + * This method will send back a JSON string in the following format: + *

+ * {
+ *   "message":"The following required parameter(s) where missing from the request body: 'param_1', 'param_2', 'param_n'",
+ *   "type":"error",
+ * } + *

+ * In addition to the message, The response will sent HTTP code 404 - Not Found. + * Note that the content of the field "message" might differ. It depends on + * the language. If no language is selected or language is not supported, + * The language that will be used is the language that was set as default + * language in the class 'SiteConfig'. + * + * @since 1.3 + */ + public function missingParams() { + $val = ''; + $paramsNamesArr = $this->getMissingParameters(); + + if (gettype($paramsNamesArr) == 'array') { + $i = 0; + $count = count($paramsNamesArr); + + foreach ($paramsNamesArr as $paramName) { + if ($i + 1 == $count) { + $val .= '\''.$paramName.'\''; + } else { + $val .= '\''.$paramName.'\', '; + } + $i++; + } + } + $message = $this->get('general/missing-params'); + $this->sendResponse($message.$val.'.', self::$E, 404); + } + /** + * Sends a response message to indicate that a user is not authorized to + * do an API call. + * + * This method will send back a JSON string in the following format: + *

+ * {
+ *   "message":"Not authorized",
+ *   "type":"error"
+ * } + *

+ * In addition to the message, The response will sent HTTP code 401 - Not Authorized. + * Note that the content of the field "message" might differ. It depends on + * the language. If no language is selected or language is not supported, + * The language that will be used is the language that was set as default + * language in the class 'SiteConfig'. + * + * @since 1.0 + */ + public function notAuth() { + $message = $this->get('general/http-codes/401/message'); + $this->sendResponse($message, self::$E, 401); + } + /** + * Auto-register services tables which exist on a specific directory. + * + * Note that the statement 'return __NAMESPACE__' should be included at the + * end of service class for auto-register to work. If the statement + * does not exist, the method will assume that the path is the namespace of + * each class. Also, the classes which represents web services must be suffixed + * with the word 'Service' in order to register them (e.g. RegisterUserService). + * + * @param string $pathToScan A path which is relative to application source + * code folder. For example, if application folder name is 'my-app' and + * the web services are in the folder 'my-app/apis/user, + * then the value of the argument must be 'apis/user'. + * + * @since 1.0.1 + */ + public function registerServices($pathToScan) { + App::autoRegister($pathToScan, function (AbstractWebService $ws, ExtendedWebServicesManager $m) + { + $m->addService($ws); + }, 'Service', [$this], [$this]); + } + /** + * Sends a response message to indicate that request method is not supported. + * + * This method will send back a JSON string in the following format: + *

+ * {
+ *   "message":"Method Not Allowed.",
+ *   "type":"error",
+ * } + *

+ * In addition to the message, The response will sent HTTP code 405 - Method Not Allowed. + * Note that the content of the field "message" might differ. It depends on + * the language. If no language is selected or language is not supported, + * The language that will be used is the language that was set as default + * language in the class 'SiteConfig'. + * + * @since 1.0 + */ + public function requestMethodNotAllowed() { + $message = $this->get('general/http-codes/405/message'); + $this->sendResponse($message, self::$E, 405); + } + /** + * Sets multiple language variables. + * + * @param string $dir A string that looks like a + * directory. + * + * @param array $arr An associative array. The key will act as the variable + * and the value of the key will act as the variable value. + * + * @since 1.0 + */ + public function setLangVars($dir,$arr = []) { + $this->getTranslation()->setMultiple($dir, $arr); + } + /** + * Set the language at which the API is going to use for the response. + */ + private function setTranslationHelper() { + $reqMeth = Request::getMethod(); + $activeSession = SessionsManager::getActiveSession(); + + if ($activeSession !== null) { + $tempCode = $activeSession->getLangCode(true); + } else { + $tempCode = App::getConfig()->getPrimaryLanguage(); + } + + if ($reqMeth == 'GET' || $reqMeth == 'DELETE') { + $langCode = isset($_GET['lang']) ? filter_var($_GET['lang']) : $tempCode; + } else if ($reqMeth == 'POST' || $reqMeth == 'PUT') { + $langCode = isset($_POST['lang']) ? filter_var($_POST['lang']) : $tempCode; + } else { + $langCode = $tempCode; + } + $this->translation = Lang::loadTranslation($langCode); + } +} From 0d5f7983426f7d766e79e6932ec47cf9ac7853dd Mon Sep 17 00:00:00 2001 From: Ibrahim BinAlshikh Date: Tue, 19 Mar 2024 08:09:57 +0300 Subject: [PATCH 3/4] chore: Cleanup --- webfiori/framework/EAbstractWebService.php | 44 ---- .../framework/ExtendedWebServicesManager.php | 206 +----------------- .../framework/writers/WebServiceWriter.php | 3 +- 3 files changed, 4 insertions(+), 249 deletions(-) delete mode 100644 webfiori/framework/EAbstractWebService.php diff --git a/webfiori/framework/EAbstractWebService.php b/webfiori/framework/EAbstractWebService.php deleted file mode 100644 index 93766386..00000000 --- a/webfiori/framework/EAbstractWebService.php +++ /dev/null @@ -1,44 +0,0 @@ - - * {
- *   "message":"Action not implemented.",
- *   "type":"error",
- * } - *

- * In addition to the message, The response will sent HTTP code 404 - Not Found. - * Note that the content of the field "message" might differ. It depends on - * the language. If no language is selected or language is not supported, - * The language that will be used is the language that was set as default - * language in the class 'SiteConfig'. - * - * @since 1.0 - */ - public function actionNotImpl() { - $message = $this->get('general/action-not-impl'); - $this->sendResponse($message, self::$E, 404); - } - /** - * Sends a response message to indicate that an action is not supported by the API. - * - * This method will send back a JSON string in the following format: - *

- * {
- *   "message":"Action not supported",
- *   "type":"error"
- * } - *

- * In addition to the message, The response will sent HTTP code 404 - Not Found. - * Note that the content of the field "message" might differ. It depends on - * the language. If no language is selected or language is not supported, - * The language that will be used is the language that was set as default - * language in the class 'SiteConfig'. - * - * @since 1.0 - */ - public function actionNotSupported() { - $message = $this->get('general/action-not-supported'); - $this->sendResponse($message, self::$E, 404); - } - /** - * Sends a response message to indicate that request content type is - * not supported by the API. - * - * This method will send back a JSON string in the following format: - *

- * {
- *   "message":"Content type not supported.",
- *   "type":"error",
- *   "request-content-type":"content_type"
- * } - *

- * In addition to the message, The response will sent HTTP code 404 - Not Found. - * Note that the content of the field "message" might differ. It depends on - * the language. If no language is selected or language is not supported, - * The language that will be used is the language that was set as default - * language in the class 'SiteConfig'. - * - * @since 1.1 - */ - public function contentTypeNotSupported(string $cType = '') { - $message = $this->get('general/content-not-supported'); - $this->sendResponse($message, self::$E, 404,'"request-content-type":"'.$cType.'"'); - } /** * Creates a sub array to define language variables. * @@ -191,9 +115,9 @@ public function databaseErr($info = '') { if (defined('WF_VERBOSE') && WF_VERBOSE === true) { $json->add('query', $info->getLastQuery()); } - $this->sendResponse($message, self::$E, 404, $json); + $this->sendResponse($message, self::E, 404, $json); } else { - $this->sendResponse($message, self::$E, 404, $info); + $this->sendResponse($message, self::E, 404, $info); } } /** @@ -255,112 +179,10 @@ public function getAuthorizationHeader() { public function getTranslation() { return $this->translation; } - /** - * Sends a response message to indicate that a request parameter(s) have invalid values. - * - * This method will send back a JSON string in the following format: - *

- * {
- *   "message":"The following parameter(s) has invalid values: 'param_1', 'param_2', 'param_n'",
- *   "type":"error"
- * } - *

- * In addition to the message, The response will sent HTTP code 404 - Not Found. - * Note that the content of the field "message" might differ. It depends on - * the language. If no language is selected or language is not supported, - * The language that will be used is the language that was set as default - * language in the class 'SiteConfig'. - * - * @since 1.3 - */ - public function invParams() { - $val = ''; - $paramsNamesArr = $this->getInvalidParameters(); - - if (gettype($paramsNamesArr) == 'array') { - $i = 0; - $count = count($paramsNamesArr); - - foreach ($paramsNamesArr as $paramName) { - if ($i + 1 == $count) { - $val .= '\''.$paramName.'\''; - } else { - $val .= '\''.$paramName.'\', '; - } - $i++; - } - } - $message = $this->get('general/inv-params'); - $this->sendResponse($message.$val.'.', self::$E, 404); - } - /** - * Sends a response message to indicate that a request parameter or parameters are missing. - * - * This method will send back a JSON string in the following format: - *

- * {
- *   "message":"The following required parameter(s) where missing from the request body: 'param_1', 'param_2', 'param_n'",
- *   "type":"error",
- * } - *

- * In addition to the message, The response will sent HTTP code 404 - Not Found. - * Note that the content of the field "message" might differ. It depends on - * the language. If no language is selected or language is not supported, - * The language that will be used is the language that was set as default - * language in the class 'SiteConfig'. - * - * @since 1.3 - */ - public function missingParams() { - $val = ''; - $paramsNamesArr = $this->getMissingParameters(); - - if (gettype($paramsNamesArr) == 'array') { - $i = 0; - $count = count($paramsNamesArr); - - foreach ($paramsNamesArr as $paramName) { - if ($i + 1 == $count) { - $val .= '\''.$paramName.'\''; - } else { - $val .= '\''.$paramName.'\', '; - } - $i++; - } - } - $message = $this->get('general/missing-params'); - $this->sendResponse($message.$val.'.', self::$E, 404); - } - /** - * Sends a response message to indicate that a user is not authorized to - * do an API call. - * - * This method will send back a JSON string in the following format: - *

- * {
- *   "message":"Not authorized",
- *   "type":"error"
- * } - *

- * In addition to the message, The response will sent HTTP code 401 - Not Authorized. - * Note that the content of the field "message" might differ. It depends on - * the language. If no language is selected or language is not supported, - * The language that will be used is the language that was set as default - * language in the class 'SiteConfig'. - * - * @since 1.0 - */ - public function notAuth() { - $message = $this->get('general/http-codes/401/message'); - $this->sendResponse($message, self::$E, 401); - } /** * Auto-register services tables which exist on a specific directory. * - * Note that the statement 'return __NAMESPACE__' should be included at the - * end of service class for auto-register to work. If the statement - * does not exist, the method will assume that the path is the namespace of - * each class. Also, the classes which represents web services must be suffixed + * The classes which represents web services must be suffixed * with the word 'Service' in order to register them (e.g. RegisterUserService). * * @param string $pathToScan A path which is relative to application source @@ -376,28 +198,6 @@ public function registerServices($pathToScan) { $m->addService($ws); }, 'Service', [$this], [$this]); } - /** - * Sends a response message to indicate that request method is not supported. - * - * This method will send back a JSON string in the following format: - *

- * {
- *   "message":"Method Not Allowed.",
- *   "type":"error",
- * } - *

- * In addition to the message, The response will sent HTTP code 405 - Method Not Allowed. - * Note that the content of the field "message" might differ. It depends on - * the language. If no language is selected or language is not supported, - * The language that will be used is the language that was set as default - * language in the class 'SiteConfig'. - * - * @since 1.0 - */ - public function requestMethodNotAllowed() { - $message = $this->get('general/http-codes/405/message'); - $this->sendResponse($message, self::$E, 405); - } /** * Sets multiple language variables. * diff --git a/webfiori/framework/writers/WebServiceWriter.php b/webfiori/framework/writers/WebServiceWriter.php index d322499c..568884b8 100644 --- a/webfiori/framework/writers/WebServiceWriter.php +++ b/webfiori/framework/writers/WebServiceWriter.php @@ -10,7 +10,6 @@ */ namespace webfiori\framework\writers; -use webfiori\framework\EAbstractWebService; use webfiori\http\AbstractWebService; use webfiori\http\ParamOption; use webfiori\http\ParamType; @@ -51,7 +50,7 @@ public function __construct($webServicesObj = null) { parent::__construct('NewWebService', APP_PATH.'apis', APP_DIR.'\\apis'); $this->setSuffix('Service'); - $this->addUseStatement(EAbstractWebService::class); + $this->addUseStatement(AbstractWebService::class); $this->addUseStatement(ParamType::class); $this->addUseStatement(ParamOption::class); $this->addUseStatement(RequestMethod::class); From 3e33eb8ee9009437fddbaac7a7e3a1c140755302 Mon Sep 17 00:00:00 2001 From: Ibrahim BinAlshikh Date: Tue, 19 Mar 2024 08:18:12 +0300 Subject: [PATCH 4/4] fix(cli) Fix Create Service Command --- .../framework/test/writers/WebServiceWritterTest.php | 6 +++--- webfiori/framework/writers/WebServiceWriter.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/webfiori/framework/test/writers/WebServiceWritterTest.php b/tests/webfiori/framework/test/writers/WebServiceWritterTest.php index a2f0d18f..9128fe80 100644 --- a/tests/webfiori/framework/test/writers/WebServiceWritterTest.php +++ b/tests/webfiori/framework/test/writers/WebServiceWritterTest.php @@ -17,7 +17,7 @@ public function test00() { $this->assertEquals('app\\apis', $writter->getNamespace()); $this->assertEquals('Service', $writter->getSuffix()); $this->assertEquals([ - "webfiori\\framework\\EAbstractWebService", + "webfiori\http\AbstractWebService", "webfiori\http\ParamType", "webfiori\http\ParamOption", "webfiori\\http\\RequestMethod" @@ -33,7 +33,7 @@ public function test01() { $this->assertEquals('app\\apis', $writter->getNamespace()); $this->assertEquals('Service', $writter->getSuffix()); $this->assertEquals([ - "webfiori\\framework\\EAbstractWebService", + "webfiori\http\AbstractWebService", "webfiori\http\ParamType", "webfiori\http\ParamOption", "webfiori\\http\\RequestMethod" @@ -61,7 +61,7 @@ public function test02() { $this->assertEquals('app\\apis', $writter->getNamespace()); $this->assertEquals('Service', $writter->getSuffix()); $this->assertEquals([ - "webfiori\\framework\\EAbstractWebService", + "webfiori\http\AbstractWebService", "webfiori\http\ParamType", "webfiori\http\ParamOption", "webfiori\\http\\RequestMethod" diff --git a/webfiori/framework/writers/WebServiceWriter.php b/webfiori/framework/writers/WebServiceWriter.php index 568884b8..5537d217 100644 --- a/webfiori/framework/writers/WebServiceWriter.php +++ b/webfiori/framework/writers/WebServiceWriter.php @@ -145,7 +145,7 @@ public function writeClassComment() { } public function writeClassDeclaration() { - $this->append('class '.$this->getName().' extends EAbstractWebService {'); + $this->append('class '.$this->getName().' extends AbstractWebService {'); } /** *