Skip to content

Commit

Permalink
Refactor to use Symfony dependency injection + use Cookiejar fabarea#32
Browse files Browse the repository at this point in the history
  • Loading branch information
stissot authored and PowerKiKi committed Aug 25, 2022
1 parent 0873569 commit 33f385f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 28 deletions.
21 changes: 10 additions & 11 deletions Classes/Controller/BackendMessageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,24 @@
*/
class BackendMessageController extends ActionController
{
protected BodyConverter $typeConverter;

public function __construct(BodyConverter $bodyConverter) {
$this->typeConverter = $bodyConverter;
}

public function initializeAction(): void
{
// Configure property mapping to retrieve the file object.
if ($this->arguments->hasArgument('body')) {

/** @var BodyConverter $typeConverter */
$typeConverter = GeneralUtility::makeInstance(BodyConverter::class);

$propertyMappingConfiguration = $this->arguments->getArgument('body')->getPropertyMappingConfiguration();
$propertyMappingConfiguration->setTypeConverter($typeConverter);
$propertyMappingConfiguration->setTypeConverter($this->typeConverter);
}
}

/**
* @param int $pageId
*/
public function composeAction(array $matches = [], $pageId = 0): void
public function composeAction(array $matches = []): void
{
$pageId = $this->request->hasArgument('pageId') ? $this->request->getArgument('pageId') : 0;
$recipientDataType = ConfigurationUtility::getInstance()->get('recipient_data_type');

// Instantiate the Matcher object according different rules.
Expand All @@ -72,11 +71,11 @@ public function composeAction(array $matches = [], $pageId = 0): void
}

/**
* @param bool $parseMarkdown
* @Validate("Fab\Messenger\Domain\Validator\NotEmptyValidator", param="subject")
*/
public function enqueueAction(string $subject, string $body, string $sender, array $matches = [], $parseMarkdown = false): void
public function enqueueAction(string $subject, string $body, string $sender, array $matches = []): void
{
$parseMarkdown = $this->request->hasArgument('parseMarkdown') ? (bool) $this->request->getArgument('parseMarkdown') : false;
$recipientDataType = ConfigurationUtility::getInstance()->get('recipient_data_type');

// Instantiate the Matcher object according different rules.
Expand Down
1 change: 0 additions & 1 deletion Classes/Controller/MessageSentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public function sendAgainAction(array $matches = []): string

/** @var Message $message */
$message = GeneralUtility::makeInstance(Message::class);

$isSent = $message->setBody($contentObject['body'])
->setSubject($contentObject['subject'])
->setSender($this->normalizeEmails($contentObject['sender']))
Expand Down
11 changes: 4 additions & 7 deletions Classes/PagePath/PagePath.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,10 @@ public static function getUrl($pageId, $parameters): string

$requestFactory = GeneralUtility::makeInstance(RequestFactory::class);
// Send TYPO3 cookies as this may affect path generation
$additionalOptions = [
'headers' => [
'Cookie' => 'fe_typo_user=' . $_COOKIE['fe_typo_user'],
],
'cookies' => true,
];
$response = $requestFactory->request($url, 'GET', $additionalOptions);
$jar = \GuzzleHttp\Cookie\CookieJar::fromArray([
'fe_typo_user' => $_COOKIE['fe_typo_user'],
], $_SERVER['HTTP_HOST']);
$response = $requestFactory->request($url, 'GET', ['cookies' => $jar]);
$result = $response->getBody()->getContents();

$urlParts = parse_url($result);
Expand Down
17 changes: 8 additions & 9 deletions Classes/TypeConverter/BodyConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ class BodyConverter extends AbstractTypeConverter
protected $priority = 1;

/**
* @var RequestFactoryInterface
* @var RequestFactory
*/
protected $requestFactory;

public function __construct(RequestFactoryInterface $requestFactory) {
public function __construct(
RequestFactoryInterface $requestFactory
) {
$this->requestFactory = $requestFactory;
}

Expand All @@ -62,14 +64,11 @@ public function convertFrom($source, $targetType, array $convertedChildPropertie
$baseUrl = PagePath::getSiteBaseUrl($source);

// Send TYPO3 cookies as this may affect path generation
$additionalOptions = [
'headers' => [
'Cookie' => 'fe_typo_user=' . $_COOKIE['fe_typo_user'],
],
'cookies' => true,
];
$jar = \GuzzleHttp\Cookie\CookieJar::fromArray([
'fe_typo_user' => $_COOKIE['fe_typo_user'],
], $_SERVER['HTTP_HOST']);
$url = $baseUrl . 'index.php?id=' . $source;
$response = $this->requestFactory->request($url, 'GET', $additionalOptions);
$response = $this->requestFactory->request($url, 'GET', ['cookies' => $jar]);
if ($response->getStatusCode() === 200) {
$content = $response->getBody()->getContents();
$body = preg_match("/<body[^>]*>(.*?)<\/body>/is", $content, $matches);
Expand Down
5 changes: 5 additions & 0 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
services:
_defaults:
autowire: true
autoconfigure: true
public: true

0 comments on commit 33f385f

Please sign in to comment.