-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExample.php
More file actions
45 lines (39 loc) · 1.32 KB
/
Copy pathExample.php
File metadata and controls
45 lines (39 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
/**
* @author Artemii Karkusha
* @copyright Copyright (c) (https://www.linkedin.com/in/artemiy-karkusha/)
*/
declare(strict_types=1);
namespace ArtemiiKarkusha\AdobeCommercePreparingToCertification\Controller\Di;
use JsonException;
use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\Controller\Result\RawFactory;
use ArtemiiKarkusha\AdobeCommercePreparingToCertification\Api\ExampleHowDiIsUsedInterface;
use Magento\Framework\Controller\ResultInterface;
class Example implements HttpGetActionInterface
{
/**
* @param RawFactory $rawFactory
* @param ExampleHowDiIsUsedInterface $exampleHowDiIsUsed
*/
public function __construct(
private RawFactory $rawFactory,
private ExampleHowDiIsUsedInterface $exampleHowDiIsUsed
) {
}
/**
* @inheritDoc
*/
public function execute(): ResultInterface
{
$rawResponse = $this->rawFactory->create();
try {
$exampleHowDiIsUsedContains = json_encode((array)$this->exampleHowDiIsUsed, JSON_THROW_ON_ERROR);
$rawResponse->setContents($exampleHowDiIsUsedContains);
} catch (JsonException $jsonException) {
$rawResponse->setContents($jsonException->getMessage());
}
return $rawResponse;
}
}