Skip to content

Commit

Permalink
feat: support prestashop 1.7 (#239)
Browse files Browse the repository at this point in the history
Resolves #232

Co-authored-by: Edie Lemoine <edie@myparcel.nl>
  • Loading branch information
wthijmen and EdieLemoine authored Mar 20, 2024
1 parent 3965452 commit 6554b5d
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 5 deletions.
12 changes: 8 additions & 4 deletions config/pdk.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
use MyParcelNL\PrestaShop\Migration\Pdk\PdkSettingsMigration;
use MyParcelNL\PrestaShop\Pdk\Account\Repository\PsPdkAccountRepository;
use MyParcelNL\PrestaShop\Pdk\Action\Backend\Account\PsUpdateAccountAction;
use MyParcelNL\PrestaShop\Pdk\Api\Adapter\Guzzle5ClientAdapter;
use MyParcelNL\PrestaShop\Pdk\Api\Adapter\Guzzle7ClientAdapter;
use MyParcelNL\PrestaShop\Pdk\Api\Service\PsBackendEndpointService;
use MyParcelNL\PrestaShop\Pdk\Api\Service\PsFrontendEndpointService;
Expand Down Expand Up @@ -152,10 +153,13 @@
/**
* Miscellaneous
*/
ClientAdapterInterface::class => get(Guzzle7ClientAdapter::class),
LoggerInterface::class => get(PsLogger::class),
MigrationServiceInterface::class => get(PsMigrationService::class),
ScriptServiceInterface::class => get(PsScriptService::class),
ClientAdapterInterface::class => factory(function () {
return _PS_VERSION_ >= 8 ? Pdk::get(Guzzle7ClientAdapter::class) : Pdk::get(Guzzle5ClientAdapter::class);
}),

LoggerInterface::class => get(PsLogger::class),
MigrationServiceInterface::class => get(PsMigrationService::class),
ScriptServiceInterface::class => get(PsScriptService::class),

InstallerServiceInterface::class => factory(function () {
/** @var \MyParcelNL\PrestaShop\Pdk\Installer\Service\PsPreInstallService $preInstallService */
Expand Down
44 changes: 44 additions & 0 deletions src/Pdk/Api/Adapter/Guzzle5ClientAdapter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

namespace MyParcelNL\PrestaShop\Pdk\Api\Adapter;

use GuzzleHttp\Client;
use MyParcelNL\Pdk\Api\Contract\ClientAdapterInterface;
use MyParcelNL\Pdk\Api\Contract\ClientResponseInterface;
use MyParcelNL\Pdk\Api\Response\ClientResponse;

class Guzzle5ClientAdapter implements ClientAdapterInterface
{
/**
* @var \GuzzleHttp\Client
*/
private $client;

/**
* @param \GuzzleHttp\Client $client
*/
public function __construct(Client $client)
{
$this->client = $client;
}

/**
* @param string $httpMethod
* @param string $uri
* @param array $options
*
* @return \MyParcelNL\Pdk\Api\Contract\ClientResponseInterface
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function doRequest(string $httpMethod, string $uri, array $options = []): ClientResponseInterface
{
$clientRequest = $this->client->createRequest($httpMethod, $uri, $options);

$clientResponse = $this->client->send($clientRequest);
$statusCode = $clientResponse->getStatusCode() ?? 0;

return new ClientResponse($clientResponse->getBody()->getContents(), $statusCode, $clientResponse->getHeaders());
}
}
5 changes: 4 additions & 1 deletion src/Pdk/Installer/Service/PsPreInstallService.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ private function prepareEntityManager(): void

$docParser = new DocParser();
$reader = new AnnotationReader($docParser);
$reader = new PsrCachedReader($reader, new ArrayAdapter());

if (class_exists(PsrCachedReader::class)) {
$reader = new PsrCachedReader($reader, new ArrayAdapter());
}

$driver = new AnnotationDriver($reader, ["{$appInfo->path}src/Entity"]);

Expand Down

0 comments on commit 6554b5d

Please sign in to comment.