EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
Ref
Yurii4552f1e44abf
diff --git a/application/Espo/Controllers/Formula.php b/application/Espo/Controllers/Formula.phpindex 9b7006f226..0c17a40b18 100644--- a/application/Espo/Controllers/Formula.php+++ b/application/Espo/Controllers/Formula.php@@ -31,6 +31,7 @@ namespace Espo\Controllers;use Espo\Core\Api\Request;use Espo\Core\Api\RequestWrapper;+use Espo\Core\Api\Route\ContentType;use Espo\Core\Exceptions\NotFoundSilent;use Espo\Tools\Formula\Service;use Espo\Core\Exceptions\BadRequest;@@ -75,7 +76,7 @@ class Formula*/public function postActionRun(Request $request): stdClass{- if ($request instanceof RequestWrapper && $request->getContentType() !== 'application/json') {+ if ($request->getContentType() !== ContentType::APPLICATION_JSON) {throw new BadRequest();}diff --git a/application/Espo/Controllers/User.php b/application/Espo/Controllers/User.phpindex 273195f118..4cd9f04cca 100644--- a/application/Espo/Controllers/User.php+++ b/application/Espo/Controllers/User.php@@ -30,6 +30,7 @@namespace Espo\Controllers;use Espo\Core\Api\Response;+use Espo\Core\Api\Route\ContentType;use Espo\Core\Exceptions\BadRequest;use Espo\Core\Exceptions\Forbidden;use Espo\Core\Api\Request;@@ -42,7 +43,7 @@ class User extends Record{public function postActionCreate(Request $request, Response $response): stdClass{- if ($request->getHeader('Content-Type') !== 'application/json') {+ if ($request->getContentType() !== ContentType::APPLICATION_JSON) {throw new BadRequest("Not supported content type.");}diff --git a/application/Espo/Core/Api/ActionHandler.php b/application/Espo/Core/Api/ActionHandler.phpindex 76319de969..42a1d05cc3 100644--- a/application/Espo/Core/Api/ActionHandler.php+++ b/application/Espo/Core/Api/ActionHandler.php@@ -29,6 +29,7 @@namespace Espo\Core\Api;+use Espo\Core\Api\Route\ContentType;use Espo\Core\Exceptions\BadRequest;use Espo\Core\Exceptions\Conflict;use Espo\Core\Exceptions\Error;@@ -47,7 +48,7 @@ use Slim\Psr7\Factory\ResponseFactory;*/class ActionHandler implements RequestHandlerInterface{- private const DEFAULT_CONTENT_TYPE = 'application/json';+ private const string DEFAULT_CONTENT_TYPE = ContentType::APPLICATION_JSON;public function __construct(private Action $action,diff --git a/application/Espo/Core/Api/ControllerActionHandler.php b/application/Espo/Core/Api/ControllerActionHandler.phpindex e451bef915..3f1e8c5e5b 100644--- a/application/Espo/Core/Api/ControllerActionHandler.php+++ b/application/Espo/Core/Api/ControllerActionHandler.php@@ -29,6 +29,7 @@namespace Espo\Core\Api;+use Espo\Core\Api\Route\ContentType;use Espo\Core\Exceptions\NotFound;use Espo\Core\Utils\Config;use Psr\Http\Message\ResponseInterface;@@ -76,7 +77,7 @@ class ControllerActionHandler implements RequestHandlerInterfaceprivate function beforeProceed(): void{- $this->responseWrapped->setHeader('Content-Type', 'application/json');+ $this->responseWrapped->setHeader('Content-Type', ContentType::APPLICATION_JSON);}private function afterProceed(Response $responseWrapped): voiddiff --git a/application/Espo/Core/Api/ControllerActionProcessor.php b/application/Espo/Core/Api/ControllerActionProcessor.phpindex 4b7378fbd0..00ff1f7abc 100644--- a/application/Espo/Core/Api/ControllerActionProcessor.php+++ b/application/Espo/Core/Api/ControllerActionProcessor.php@@ -29,6 +29,7 @@namespace Espo\Core\Api;+use Espo\Core\Api\Route\ContentType;use Espo\Core\Exceptions\NotFound;use Espo\Core\Exceptions\NotFoundSilent;use Espo\Core\InjectableFactory;@@ -95,7 +96,7 @@ class ControllerActionProcessor$data = $request->getBodyContents();- if ($data && $this->getRequestContentType($request) === 'application/json') {+ if ($data && $this->getRequestContentType($request) === ContentType::APPLICATION_JSON) {$data = json_decode($data);}diff --git a/application/Espo/Core/Api/RequestWrapper.php b/application/Espo/Core/Api/RequestWrapper.phpindex ad0039dc5d..ac2ab4fcbd 100644--- a/application/Espo/Core/Api/RequestWrapper.php+++ b/application/Espo/Core/Api/RequestWrapper.php@@ -29,6 +29,7 @@namespace Espo\Core\Api;+use Espo\Core\Api\Route\ContentType;use Espo\Core\Utils\Json;use Espo\Core\Exceptions\BadRequest;use Espo\Core\Api\Request as ApiRequest;@@ -196,7 +197,7 @@ class RequestWrapper implements ApiRequest$contentType = $this->getContentType();- if ($contentType === 'application/json' && $contents) {+ if ($contentType === ContentType::APPLICATION_JSON && $contents) {$parsedBody = Json::decode($contents);if (is_array($parsedBody)) {@@ -215,7 +216,10 @@ class RequestWrapper implements ApiRequest}if (- in_array($contentType, ['application/x-www-form-urlencoded', 'multipart/form-data']) &&+ in_array($contentType, [+ ContentType::APPLICATION_X_WWW_FORM_URLENCODED,+ ContentType::MULTIPART_FORM_DATA,+ ]) &&$contents) {$parsedBody = $this->psr7Request->getParsedBody();diff --git a/application/Espo/Core/Api/ResponseComposer.php b/application/Espo/Core/Api/ResponseComposer.phpindex 14cfe5bca7..cdb6525edf 100644--- a/application/Espo/Core/Api/ResponseComposer.php+++ b/application/Espo/Core/Api/ResponseComposer.php@@ -29,6 +29,7 @@namespace Espo\Core\Api;+use Espo\Core\Api\Route\ContentType;use Slim\Psr7\Factory\ResponseFactory;use Espo\Core\Utils\Json;use stdClass;@@ -44,7 +45,7 @@ class ResponseComposer{return self::empty()->writeBody(Json::encode($data))- ->setHeader('Content-Type', 'application/json');+ ->setHeader('Content-Type', ContentType::APPLICATION_JSON);}/**diff --git a/application/Espo/Core/Api/Route/ContentType.php b/application/Espo/Core/Api/Route/ContentType.phpnew file mode 100644index 0000000000..e690e8f562--- /dev/null+++ b/application/Espo/Core/Api/Route/ContentType.php@@ -0,0 +1,41 @@+<?php+/************************************************************************+ * This file is part of EspoCRM.+ *+ * EspoCRM – Open Source CRM application.+ * Copyright (C) 2014-2026 EspoCRM, Inc.+ * Website: https://www.espocrm.com+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as published by+ * the Free Software Foundation, either version 3 of the License, or+ * (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ * The interactive user interfaces in modified source and object code versions+ * of this program must display Appropriate Legal Notices, as required under+ * Section 5 of the GNU Affero General Public License version 3.+ *+ * In accordance with Section 7(b) of the GNU Affero General Public License version 3,+ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word.+ ************************************************************************/++namespace Espo\Core\Api\Route;++/**+ * @since 10.1.0+ */+class ContentType+{+ public const string APPLICATION_X_WWW_FORM_URLENCODED = 'application/x-www-form-urlencoded';+ public const string MULTIPART_FORM_DATA = 'multipart/form-data';+ public const string APPLICATION_JSON = 'application/json';+ public const string TEXT_PLAIN = 'text/plain';+}diff --git a/application/Espo/Core/Webhook/Sender.php b/application/Espo/Core/Webhook/Sender.phpindex 560fcbf556..b6075d3e21 100644--- a/application/Espo/Core/Webhook/Sender.php+++ b/application/Espo/Core/Webhook/Sender.php@@ -29,6 +29,8 @@namespace Espo\Core\Webhook;+use Espo\Core\Api\Method;+use Espo\Core\Api\Route\ContentType;use Espo\Core\Exceptions\Error;use Espo\Core\Utils\Config;use Espo\Core\Utils\Json;@@ -150,8 +152,8 @@ class Sender?string $legacySignature,): RequestInterface {- $request = HttpClient\RequestCreator::create('POST', $url)- ->withHeader('Content-Type', 'application/json')+ $request = HttpClient\RequestCreator::create(Method::POST, $url)+ ->withHeader('Content-Type', ContentType::APPLICATION_JSON)->withHeader('Content-Length', (string) strlen($payload));if ($signature) {diff --git a/application/Espo/Tools/OpenApi/Api/GetSpec.php b/application/Espo/Tools/OpenApi/Api/GetSpec.phpindex f7b2e0904b..637b21dbe6 100644--- a/application/Espo/Tools/OpenApi/Api/GetSpec.php+++ b/application/Espo/Tools/OpenApi/Api/GetSpec.php@@ -34,6 +34,7 @@ use Espo\Core\Api\Action;use Espo\Core\Api\Request;use Espo\Core\Api\Response;use Espo\Core\Api\ResponseComposer;+use Espo\Core\Api\Route\ContentType;use Espo\Core\Exceptions\Forbidden;use Espo\Tools\OpenApi\Provider\Params;use Espo\Tools\OpenApi\ProviderFactory;@@ -68,7 +69,7 @@ class GetSpec implements Actionreturn ResponseComposer::empty()->writeBody($spec)- ->setHeader('Content-Type', 'application/json');+ ->setHeader('Content-Type', ContentType::APPLICATION_JSON);}/**