-
Notifications
You must be signed in to change notification settings - Fork 10
Add HTML support (with options!) #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Kocal
wants to merge
3
commits into
sensiolabs:main
Choose a base branch
from
bakslashHQ:feat/html-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,5 +2,6 @@ | |
| /.php-cs-fixer.cache | ||
| /composer.lock | ||
| /phpunit.xml | ||
| /tests/Fixtures/config/ | ||
| /tests/Fixtures/var/ | ||
| /vendor/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| parameters: | ||
| ignoreErrors: | ||
| - | ||
| message: "#^PHPDoc tag @param references unknown parameter\\: \\$options$#" | ||
| count: 1 | ||
| path: src/Minifier/MinifierInterface.php | ||
|
|
||
| - | ||
| message: "#^Method Sensiolabs\\\\MinifyBundle\\\\Minifier\\\\MinifierInterface\\:\\:minify\\(\\) invoked with 3 parameters, 2 required\\.$#" | ||
| count: 1 | ||
| path: src/Minifier/TraceableMinifier.php |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| includes: | ||
| - phpstan-baseline.neon | ||
|
|
||
| parameters: | ||
| level: 9 | ||
| paths: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /* | ||
| * This file is part of the SensioLabs MinifyBundle package. | ||
| * | ||
| * (c) Simon André - Sensiolabs | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| namespace Sensiolabs\MinifyBundle\Minifier\Options; | ||
|
|
||
| use Sensiolabs\MinifyBundle\Minifier\MinifierInterface; | ||
|
|
||
| /** | ||
| * @author Hugo Alliaume <hugo@alliau.me> | ||
| */ | ||
| final class HtmlOptions implements OptionsInterface | ||
| { | ||
| /** | ||
| * @param bool $keepDocumentTags preserve html, head and body tags | ||
| */ | ||
| public function __construct( | ||
| public readonly bool $keepDocumentTags = false, | ||
| ) { | ||
| } | ||
|
|
||
| public function getType(): string | ||
| { | ||
| return MinifierInterface::TYPE_HTML; | ||
| } | ||
|
|
||
| public function toCliArgs(): array | ||
| { | ||
| $args = []; | ||
| if ($this->keepDocumentTags) { | ||
| $args[] = '--html-keep-document-tags'; | ||
| } | ||
|
|
||
| return $args; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /* | ||
| * This file is part of the SensioLabs MinifyBundle package. | ||
| * | ||
| * (c) Simon André - Sensiolabs | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| namespace Sensiolabs\MinifyBundle\Minifier\Options; | ||
|
|
||
| use Sensiolabs\MinifyBundle\Minifier\MinifierInterface; | ||
|
|
||
| /** | ||
| * @author Hugo Alliaume <hugo@alliau.me> | ||
| */ | ||
| interface OptionsInterface | ||
|
smnandre marked this conversation as resolved.
|
||
| { | ||
| /** | ||
| * @return MinifierInterface::TYPE_* | ||
| */ | ||
| public function getType(): string; | ||
|
|
||
| /** | ||
| * @return list<string> | ||
| */ | ||
| public function toCliArgs(): array; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
|
|
||
| use Sensiolabs\MinifyBundle\Exception\RuntimeException; | ||
| use Sensiolabs\MinifyBundle\Minifier\MinifierInterface; | ||
| use Sensiolabs\MinifyBundle\Minifier\Options\OptionsInterface; | ||
| use Symfony\Component\Process\Process; | ||
|
|
||
| /** | ||
|
|
@@ -27,9 +28,22 @@ public function __construct( | |
| ) { | ||
| } | ||
|
|
||
| public function minify(string $input, string $type): string | ||
| public function minify(string $input, string $type/* , ?OptionsInterface $options = null */): string | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add a comment / deprecartion here, this feels so legit i'd agree to release a 2.0 there if we generalise this |
||
| { | ||
| $process = new Process([$this->binaryPath, '--type', $type]); | ||
| $options = \func_num_args() > 2 ? \func_get_arg(2) : null; | ||
| if (null !== $options && !$options instanceof OptionsInterface) { | ||
| throw new RuntimeException(sprintf('Expected $options to be an instance of "%s", got "%s".', OptionsInterface::class, get_debug_type($options))); | ||
| } | ||
| if (null !== $options && $options->getType() !== $type) { | ||
| throw new RuntimeException(sprintf('Options type "%s" does not match minify type "%s".', $options->getType(), $type)); | ||
| } | ||
|
|
||
| $args = [$this->binaryPath, '--type', $type]; | ||
| if (null !== $options) { | ||
| $args = [...$args, ...$options->toCliArgs()]; | ||
| } | ||
|
|
||
| $process = new Process($args); | ||
| $process->setInput($input); | ||
|
|
||
| try { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /* | ||
| * This file is part of the SensioLabs MinifyBundle package. | ||
| * | ||
| * (c) Simon André - Sensiolabs | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| namespace Sensiolabs\MinifyBundle\Tests\Minifier\Options; | ||
|
|
||
| use PHPUnit\Framework\Attributes\CoversClass; | ||
| use PHPUnit\Framework\TestCase; | ||
| use Sensiolabs\MinifyBundle\Minifier\MinifierInterface; | ||
| use Sensiolabs\MinifyBundle\Minifier\Options\HtmlOptions; | ||
|
|
||
| #[CoversClass(HtmlOptions::class)] | ||
| class HtmlOptionsTest extends TestCase | ||
| { | ||
| public function testGetTypeReturnsHtml(): void | ||
| { | ||
| $this->assertSame(MinifierInterface::TYPE_HTML, (new HtmlOptions())->getType()); | ||
| } | ||
|
|
||
| public function testToCliArgsIsEmptyByDefault(): void | ||
| { | ||
| $this->assertSame([], (new HtmlOptions())->toCliArgs()); | ||
| } | ||
|
|
||
| public function testToCliArgsIncludesKeepDocumentTagsFlag(): void | ||
| { | ||
| $this->assertSame( | ||
| ['--html-keep-document-tags'], | ||
| (new HtmlOptions(keepDocumentTags: true))->toCliArgs(), | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.