Skip to content

Commit

Permalink
feat!: Removed chosen guzzle client and let psr/http-client-implement…
Browse files Browse the repository at this point in the history
…ation and psr/http-factory-implementation choose their implementation based on project
  • Loading branch information
ambroisemaupate committed Dec 2, 2024
1 parent 36e6f43 commit 7d7d750
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 44 deletions.
13 changes: 8 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
"psr/http-client": "^1.0",
"psr/http-factory": "^1.0",
"php-http/discovery": "^1.19",
"composer/composer": ">=2.0",
"php-http/guzzle7-adapter": "*",
"guzzlehttp/guzzle": "^7.8",
"guzzlehttp/psr7": "*",
"symfony/dotenv": ">=5.4"
"composer/composer": ">=2.2",
"symfony/dotenv": ">=5.4",
"psr/http-client-implementation": "*",
"psr/http-factory-implementation": "*"
},
"require-dev": {
"nyholm/psr7": "^1.8",
"symfony/http-client": "^7.2"
},
"extra": {
"class": "RezoZero\\Xilofone\\Composer\\Plugin"
Expand Down
5 changes: 1 addition & 4 deletions src/Command/FetchXilofoneFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ protected function configure(): void
protected function execute(InputInterface $input, OutputInterface $output): int
{
$output->writeln('Fetching new translations files from Xilofone');
$composer = $this->getComposer();
if (null === $composer) {
throw new \RuntimeException('Composer is null');
}
$composer = $this->requireComposer();
$factory = new XilofoneFileProviderFactory($composer);
$xilofoneFileProvider = $factory->create();
$fileConfigurations = $factory->getFileConfigurations();
Expand Down
9 changes: 1 addition & 8 deletions src/Model/TranslatedFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,8 @@

final class TranslatedFile
{
private string $name;
private string $path;
private string $content;

public function __construct(string $name, string $path, string $content)
public function __construct(private string $name, private string $path, private string $content)
{
$this->name = $name;
$this->path = $path;
$this->content = $content;
}

public function getName(): string
Expand Down
28 changes: 6 additions & 22 deletions src/XilofoneFileProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,22 @@
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Http\Message\UriFactoryInterface;
use RezoZero\Xilofone\Composer\Model\File;
use RezoZero\Xilofone\Composer\Model\Project;
use RezoZero\Xilofone\Composer\Model\TranslatedFile;

final class XilofoneFileProvider
{
private string $username;
private string $password;
private string $host;
private ClientInterface $client;
private RequestFactoryInterface $requestFactory;
private UriFactoryInterface $uriFactory;
private StreamFactoryInterface $streamFactory;
private ?string $accessToken = null;

public function __construct(
ClientInterface $client,
RequestFactoryInterface $requestFactory,
UriFactoryInterface $uriFactory,
StreamFactoryInterface $streamFactory,
string $username,
#[\SensitiveParameter] string $password,
string $host = 'https://xilofone.rezo-zero.com'
private ClientInterface $client,
private RequestFactoryInterface $requestFactory,
private StreamFactoryInterface $streamFactory,
private string $username,
#[\SensitiveParameter] private string $password,
private string $host = 'https://xilofone.rezo-zero.com'
) {
$this->username = $username;
$this->password = $password;
$this->host = $host;
$this->client = $client;
$this->requestFactory = $requestFactory;
$this->uriFactory = $uriFactory;
$this->streamFactory = $streamFactory;
}

private function getAccessToken(): string
Expand Down
6 changes: 1 addition & 5 deletions src/XilofoneFileProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@

final class XilofoneFileProviderFactory
{
private Composer $composer;

public function __construct(Composer $composer)
public function __construct(private Composer $composer)
{
$this->composer = $composer;
}

private function getSingleFileConfiguration(array $config): array
Expand Down Expand Up @@ -92,7 +89,6 @@ public function create(): XilofoneFileProvider
Psr18ClientDiscovery::find(),
$psr17Factory,
$psr17Factory,
$psr17Factory,
$username,
$password,
$host
Expand Down

0 comments on commit 7d7d750

Please sign in to comment.