From 42f6dab4ce6eb4c54a563bf34253e7a0f1acbf76 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Tue, 23 Jun 2020 16:46:18 +0300 Subject: [PATCH] entry point changes --- application/Espo/Core/Application.php | 6 ++++-- application/Espo/Core/EntryPointManager.php | 9 ++++++--- application/Espo/EntryPoints/Avatar.php | 14 +++++--------- application/Espo/EntryPoints/ChangePassword.php | 4 ++-- application/Espo/EntryPoints/ConfirmOptIn.php | 6 +++--- application/Espo/EntryPoints/Download.php | 9 ++++----- application/Espo/EntryPoints/Image.php | 13 +++++-------- application/Espo/EntryPoints/LogoImage.php | 16 ++++++---------- application/Espo/EntryPoints/Pdf.php | 11 ++++++----- application/Espo/EntryPoints/Portal.php | 10 ++++------ .../Crm/EntryPoints/CampaignTrackOpened.php | 9 ++++----- .../Espo/Modules/Crm/EntryPoints/CampaignUrl.php | 10 +++++----- .../Crm/EntryPoints/EventConfirmation.php | 6 +++--- .../Modules/Crm/EntryPoints/SubscribeAgain.php | 8 ++++---- .../Espo/Modules/Crm/EntryPoints/Unsubscribe.php | 8 ++++---- 15 files changed, 65 insertions(+), 74 deletions(-) diff --git a/application/Espo/Core/Application.php b/application/Espo/Core/Application.php index c9412e036d..fd7b3c65b9 100644 --- a/application/Espo/Core/Application.php +++ b/application/Espo/Core/Application.php @@ -126,8 +126,10 @@ class Application $apiAuth = new ApiAuth($auth, $authRequired, true); $slim->add($apiAuth); - $slim->hook('slim.before.dispatch', function () use ($entryPoint, $entryPointManager, $container, $data) { - $entryPointManager->run($entryPoint, $data); + $request = $slim->request(); + + $slim->hook('slim.before.dispatch', function () use ($entryPointManager, $entryPoint, $request, $data) { + $entryPointManager->run($entryPoint, $request, $data); }); $slim->run(); diff --git a/application/Espo/Core/EntryPointManager.php b/application/Espo/Core/EntryPointManager.php index 8ad485f10d..41e06912b9 100644 --- a/application/Espo/Core/EntryPointManager.php +++ b/application/Espo/Core/EntryPointManager.php @@ -38,9 +38,12 @@ use Espo\Core\{ EntryPoints\NoAuth, }; +use Slim\Http\Request; + class EntryPointManager { - private $injectableFactory; + protected $injectableFactory; + protected $classFinder; public function __construct(InjectableFactory $injectableFactory, ClassFinder $classFinder) { @@ -80,7 +83,7 @@ class EntryPointManager return $className::$notStrictAuth ?? false; } - public function run(string $name, array $data = []) + public function run(string $name, Request $request, array $data = []) { $className = $this->getClassName($name); if (!$className) { @@ -89,7 +92,7 @@ class EntryPointManager $entryPoint = $this->injectableFactory->create($className); - $entryPoint->run($data); + $entryPoint->run($request, $data); } protected function getClassName(string $name) : ?string diff --git a/application/Espo/EntryPoints/Avatar.php b/application/Espo/EntryPoints/Avatar.php index f740d21c93..1e86315e3b 100644 --- a/application/Espo/EntryPoints/Avatar.php +++ b/application/Espo/EntryPoints/Avatar.php @@ -71,14 +71,15 @@ class Avatar extends Image implements NotStrictAuth, return $colorList[$index]; } - public function run() + public function run($request) { - if (empty($_GET['id'])) { + $userId = $request->get('id'); + $size = $request->get('size') ?? null; + + if (!$userId) { throw new BadRequest(); } - $userId = $_GET['id']; - $user = $this->entityManager->getEntity('User', $userId); if (!$user) { header('Content-Type: image/png'); @@ -94,11 +95,6 @@ class Avatar extends Image implements NotStrictAuth, $id = $user->get('avatarId'); - $size = null; - if (!empty($_GET['size'])) { - $size = $_GET['size']; - } - if (!empty($id)) { $this->show($id, $size, true); } else { diff --git a/application/Espo/EntryPoints/ChangePassword.php b/application/Espo/EntryPoints/ChangePassword.php index df7ff463ec..b8ebbeaeb3 100644 --- a/application/Espo/EntryPoints/ChangePassword.php +++ b/application/Espo/EntryPoints/ChangePassword.php @@ -57,9 +57,9 @@ class ChangePassword implements EntryPoint, NoAuth $this->entityManager = $entityManager; } - public function run() + public function run($request) { - $requestId = $_GET['id'] ?? null; + $requestId = $request->get('id'); if (!$requestId) throw new BadRequest(); diff --git a/application/Espo/EntryPoints/ConfirmOptIn.php b/application/Espo/EntryPoints/ConfirmOptIn.php index 9a0c4b76b5..f8571705a8 100644 --- a/application/Espo/EntryPoints/ConfirmOptIn.php +++ b/application/Espo/EntryPoints/ConfirmOptIn.php @@ -55,11 +55,11 @@ class ConfirmOptIn implements EntryPoint, NoAuth $this->serviceFactory = $serviceFactory; } - public function run() + public function run($request) { - if (empty($_GET['id'])) throw new BadRequest(); + $id = $request->get('id'); - $id = $_GET['id']; + if (!$id) throw new BadRequest(); $data = $this->serviceFactory->create('LeadCapture')->confirmOptIn($id); diff --git a/application/Espo/EntryPoints/Download.php b/application/Espo/EntryPoints/Download.php index aac4d1dac6..43d539a348 100644 --- a/application/Espo/EntryPoints/Download.php +++ b/application/Espo/EntryPoints/Download.php @@ -65,12 +65,11 @@ class Download implements EntryPoint $this->entityManager = $entityManager; } - public function run() + public function run($request) { - if (empty($_GET['id'])) { - throw new BadRequest(); - } - $id = $_GET['id']; + $id = $request->get('id'); + + if (!$id) throw new BadRequest(); $attachment = $this->entityManager->getEntity('Attachment', $id); diff --git a/application/Espo/EntryPoints/Image.php b/application/Espo/EntryPoints/Image.php index 19fe3619d4..492dae510b 100644 --- a/application/Espo/EntryPoints/Image.php +++ b/application/Espo/EntryPoints/Image.php @@ -73,16 +73,13 @@ class Image implements EntryPoint, protected $allowedFieldList = null; - public function run() + public function run($request) { - if (empty($_GET['id'])) { - throw new BadRequest(); - } - $id = $_GET['id']; + $id = $request->get('id'); + $size = $request->get('size') ?? null; - $size = null; - if (!empty($_GET['size'])) { - $size = $_GET['size']; + if (!$id) { + throw new BadRequest(); } $this->show($id, $size, false); diff --git a/application/Espo/EntryPoints/LogoImage.php b/application/Espo/EntryPoints/LogoImage.php index 5fe62b39d6..3cd8928cec 100644 --- a/application/Espo/EntryPoints/LogoImage.php +++ b/application/Espo/EntryPoints/LogoImage.php @@ -49,25 +49,21 @@ class LogoImage extends Image implements NoAuth, protected $allowedFieldList = ['companyLogo']; - public function run() + public function run($request) { + $id = $request->get('id'); + $size = $request->get('size') ?? null; + $this->imageSizes['small-logo'] = [181, 44]; - if (!empty($_GET['id'])) { - $id = $_GET['id']; - } else { + if (!$id) { $id = $this->config->get('companyLogoId'); } - if (empty($id)) { + if (!$id) { throw new NotFound(); } - $size = null; - if (!empty($_GET['size'])) { - $size = $_GET['size']; - } - $this->show($id, $size); } } diff --git a/application/Espo/EntryPoints/Pdf.php b/application/Espo/EntryPoints/Pdf.php index b128a22074..6d070eadb5 100644 --- a/application/Espo/EntryPoints/Pdf.php +++ b/application/Espo/EntryPoints/Pdf.php @@ -52,14 +52,15 @@ class Pdf implements EntryPoint $this->serviceFactory = $serviceFactory; } - public function run() + public function run($request) { - if (empty($_GET['entityId']) || empty($_GET['entityType']) || empty($_GET['templateId'])) { + $entityId = $request->get('entityId'); + $entityType = $request->get('entityType'); + $templateId = $request->get('templateId'); + + if (!$entityId || !$entityType || !$templateId) { throw new BadRequest(); } - $entityId = $_GET['entityId']; - $entityType = $_GET['entityType']; - $templateId = $_GET['templateId']; $entity = $this->entityManager->getEntity($entityType, $entityId); $template = $this->entityManager->getEntity('Template', $templateId); diff --git a/application/Espo/EntryPoints/Portal.php b/application/Espo/EntryPoints/Portal.php index 5839787dc1..bb361426b8 100644 --- a/application/Espo/EntryPoints/Portal.php +++ b/application/Espo/EntryPoints/Portal.php @@ -53,13 +53,11 @@ class Portal implements EntryPoint, NoAuth $this->config = $config; } - public function run($data = []) + public function run($request, $data = []) { - if (!empty($_GET['id'])) { - $id = $_GET['id']; - } else if (!empty($data['id'])) { - $id = $data['id']; - } else { + $id = $request->get('id') ?? $data['id'] ?? null; + + if (!$id) { $url = $_SERVER['REQUEST_URI']; $id = explode('/', $url)[count(explode('/', $_SERVER['SCRIPT_NAME'])) - 1]; diff --git a/application/Espo/Modules/Crm/EntryPoints/CampaignTrackOpened.php b/application/Espo/Modules/Crm/EntryPoints/CampaignTrackOpened.php index 0099f5db30..d8fed8cfa5 100644 --- a/application/Espo/Modules/Crm/EntryPoints/CampaignTrackOpened.php +++ b/application/Espo/Modules/Crm/EntryPoints/CampaignTrackOpened.php @@ -57,13 +57,12 @@ class CampaignTrackOpened implements EntryPoint, NoAuth $this->serviceFactory = $serviceFactory; } - public function run() + public function run($request) { - if (empty($_GET['id'])) { - throw new BadRequest(); - } + $id = $request->get('id'); + if (!$id) throw new BadRequest(); - $queueItemId = $_GET['id']; + $queueItemId = $id; $queueItem = $this->entityManager->getEntity('EmailQueueItem', $queueItemId); diff --git a/application/Espo/Modules/Crm/EntryPoints/CampaignUrl.php b/application/Espo/Modules/Crm/EntryPoints/CampaignUrl.php index ba2678df93..5c1f2a7a26 100644 --- a/application/Espo/Modules/Crm/EntryPoints/CampaignUrl.php +++ b/application/Espo/Modules/Crm/EntryPoints/CampaignUrl.php @@ -73,12 +73,12 @@ class CampaignUrl implements EntryPoint, NoAuth $this->metadata = $metadata; } - public function run() + public function run($request) { - $queueItemId = $_GET['queueItemId'] ?? null; - $trackingUrlId = $_GET['id'] ?? null; - $emailAddress = $_GET['emailAddress'] ?? null; - $hash = $_GET['hash'] ?? null; + $queueItemId = $request->get('queueItemId') ?? null; + $trackingUrlId = $request->get('id') ?? null; + $emailAddress = $request->get('emailAddress') ?? null; + $hash = $request->get('hash') ?? null; if (!$trackingUrlId) throw new Exceptions\BadRequest(); $trackingUrl = $this->entityManager->getEntity('CampaignTrackingUrl', $trackingUrlId); diff --git a/application/Espo/Modules/Crm/EntryPoints/EventConfirmation.php b/application/Espo/Modules/Crm/EntryPoints/EventConfirmation.php index 6a934f1b3d..bbf5172077 100644 --- a/application/Espo/Modules/Crm/EntryPoints/EventConfirmation.php +++ b/application/Espo/Modules/Crm/EntryPoints/EventConfirmation.php @@ -59,10 +59,10 @@ class EventConfirmation implements EntryPoint, NoAuth $this->hookManager = $hookManager; } - public function run() + public function run($request) { - $uid = $_GET['uid'] ?? null; - $action = $_GET['action'] ?? null; + $uid = $request->get('uid') ?? null; + $action = $request->get('action') ?? null; if (empty($uid) || empty($action)) { throw new BadRequest(); diff --git a/application/Espo/Modules/Crm/EntryPoints/SubscribeAgain.php b/application/Espo/Modules/Crm/EntryPoints/SubscribeAgain.php index 1bdaecf5f1..5206fed671 100644 --- a/application/Espo/Modules/Crm/EntryPoints/SubscribeAgain.php +++ b/application/Espo/Modules/Crm/EntryPoints/SubscribeAgain.php @@ -75,11 +75,11 @@ class SubscribeAgain implements EntryPoint, NoAuth $this->hasher = $hasher; } - public function run() + public function run($request) { - $id = $_GET['id'] ?? null; - $emailAddress = $_GET['emailAddress'] ?? null; - $hash = $_GET['hash'] ?? null; + $id = $request->get('id') ?? null; + $emailAddress = $request->get('emailAddress') ?? null; + $hash = $request->get('hash') ?? null; if ($emailAddress && $hash) { $this->processWithHash($emailAddress, $hash); diff --git a/application/Espo/Modules/Crm/EntryPoints/Unsubscribe.php b/application/Espo/Modules/Crm/EntryPoints/Unsubscribe.php index a0553b02bc..dcb8fa96f8 100644 --- a/application/Espo/Modules/Crm/EntryPoints/Unsubscribe.php +++ b/application/Espo/Modules/Crm/EntryPoints/Unsubscribe.php @@ -79,11 +79,11 @@ class Unsubscribe implements EntryPoint, NoAuth $this->serviceFactory = $serviceFactory; } - public function run() + public function run($request) { - $id = $_GET['id'] ?? null; - $emailAddress = $_GET['emailAddress'] ?? null; - $hash = $_GET['hash'] ?? null; + $id = $request->get('id') ?? null; + $emailAddress = $request->get('emailAddress') ?? null; + $hash = $request->get('hash') ?? null; if ($emailAddress && $hash) { $this->processWithHash($emailAddress, $hash);