Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# AGENTS.md

## Scope
This repository is a Symfony bundle. Follow Symfony best practices and keep changes consistent with the bundle’s existing architecture.

## Engineering Expectations
- Prefer dependency injection over service container access.
- Keep public APIs stable and documented.
- Follow PSR-4 autoloading: `src/` for production code, `tests/` for test code.
- Keep configuration under `config/` and avoid hard-coding environment-specific values.
- Use Symfony contracts and components already listed in `composer.json`.

## Tests and Static Analysis
Run these from the repo root:

```sh
composer install
```

```sh
vendor/bin/phpunit -c phpunit.dist.xml
```

```sh
vendor/bin/phpstan analyse -c phpstan.dist.neon
```

## Notes
- PHPUnit uses `Sensiolabs\MinifyBundle\Tests\Fixtures\MinifyBundleTestKernel` via `phpunit.dist.xml`.
- PHPStan level is configured in `phpstan.dist.neon` and excludes `src/SensiolabsMinifyBundle.php`.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ sensiolabs_minify:

# the local path where the downloaded binary is stored
download_directory: '%kernel.project_dir%/var/minify'

# the Minify version to download (default: null for latest)
version: null
```

You can customize this configuration to use a local binary:
Expand Down
1 change: 1 addition & 0 deletions config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
->set('.sensiolabs_minify.minifier.minify_installer', MinifyInstaller::class)
->args([
abstract_arg('download_path'),
abstract_arg('download_version'),
service('http_client')->nullOnInvalid(),
])

Expand Down
5 changes: 5 additions & 0 deletions src/MinifyInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ final class MinifyInstaller implements MinifierInstallerInterface

public function __construct(
private readonly string $installDirectory,
private readonly ?string $defaultVersion = null,
?HttpClientInterface $httpClient = null,
) {
if (null === $httpClient && !class_exists(HttpClient::class)) {
Expand All @@ -48,6 +49,10 @@ public function install(string $version = self::VERSION_LATEST, bool $force = fa
return;
}

if (self::VERSION_LATEST === $version && null !== $this->defaultVersion && '' !== $this->defaultVersion) {
$version = $this->defaultVersion;
}

$this->download($version);
}

Expand Down
5 changes: 5 additions & 0 deletions src/SensiolabsMinifyBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function loadExtension(array $config, ContainerConfigurator $container, C
$container->services()
->get('.sensiolabs_minify.minifier.minify_installer')
->arg(0, $config['minify']['download_directory'])
->arg(1, $config['minify']['version'])

->get('.sensiolabs_minify.minifier.minify_factory')
->arg(0, $config['minify']['local_binary'])
Expand Down Expand Up @@ -120,6 +121,10 @@ public function configure(DefinitionConfigurator $definition): void
->info('Directory to store the downloaded binary')
->defaultValue('%kernel.project_dir%/var/minify')
->end()
->scalarNode('version')
->info('Minify version to download (null for latest)')
->defaultNull()
->end()
->end()
->end()
->end()
Expand Down
2 changes: 1 addition & 1 deletion tests/MinifyInstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function testExceptionIsThrownWhenBinaryCannotBeDownloaded(): void
{
$httpClient = $this->createMock(HttpClientInterface::class);
$httpClient->method('request')->willReturn($this->createMockResponse(500));
$installer = new MinifyInstaller('/tmp/minify/'.rand(5, 999), $httpClient);
$installer = new MinifyInstaller('/tmp/minify/'.rand(5, 999), null, $httpClient);

$this->expectException(InstallException::class);
$installer->install();
Expand Down
Loading