-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BB-24798: Added support for Critical CSS in layout (#40191)
- added new assets group "critical_css" - added PublicDirectoryProvider for handling public directory paths - added ThemeProvider::getStylesOutputContent to dynamically inject Critical CSS content - added critical CSS to GrapesJS editor
- Loading branch information
1 parent
843e639
commit 31b3252
Showing
9 changed files
with
307 additions
and
11 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
src/Oro/Bundle/DistributionBundle/Provider/PublicDirectoryProvider.php
This file contains 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,31 @@ | ||
<?php | ||
|
||
namespace Oro\Bundle\DistributionBundle\Provider; | ||
|
||
/** | ||
* Provides the path to the public directory of the application. | ||
*/ | ||
class PublicDirectoryProvider | ||
{ | ||
public function __construct(private readonly string $projectDir) | ||
{ | ||
} | ||
|
||
public function getPublicDirectory(): string | ||
{ | ||
$defaultPublicDir = 'public'; | ||
$composerFilePath = $this->projectDir . DIRECTORY_SEPARATOR . 'composer.json'; | ||
|
||
if (!file_exists($composerFilePath)) { | ||
return $this->projectDir . DIRECTORY_SEPARATOR . $defaultPublicDir; | ||
} | ||
|
||
$composerConfig = json_decode(file_get_contents($composerFilePath), true); | ||
|
||
if (json_last_error() !== JSON_ERROR_NONE) { | ||
return $this->projectDir . DIRECTORY_SEPARATOR . $defaultPublicDir; | ||
} | ||
|
||
return $this->projectDir . DIRECTORY_SEPARATOR . ($composerConfig['extra']['public-dir'] ?? $defaultPublicDir); | ||
} | ||
} |
This file contains 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
74 changes: 74 additions & 0 deletions
74
src/Oro/Bundle/DistributionBundle/Tests/Unit/Provider/PublicDirectoryProviderTest.php
This file contains 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,74 @@ | ||
<?php | ||
|
||
namespace Oro\Bundle\DistributionBundle\Tests\Unit\Provider; | ||
|
||
use Oro\Bundle\DistributionBundle\Provider\PublicDirectoryProvider; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class PublicDirectoryProviderTest extends TestCase | ||
{ | ||
private string $projectDir; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->projectDir = sys_get_temp_dir() . '/test_project'; | ||
if (!is_dir($this->projectDir)) { | ||
mkdir($this->projectDir, 0777, true); | ||
} | ||
} | ||
|
||
protected function tearDown(): void | ||
{ | ||
$this->removeDirectory($this->projectDir); | ||
} | ||
|
||
public function testGetPublicDirectoryDefault(): void | ||
{ | ||
$provider = new PublicDirectoryProvider($this->projectDir); | ||
|
||
self::assertSame($this->projectDir . '/public', $provider->getPublicDirectory()); | ||
} | ||
|
||
public function testGetPublicDirectoryFromComposerConfig(): void | ||
{ | ||
$composerJsonPath = $this->projectDir . '/composer.json'; | ||
|
||
file_put_contents($composerJsonPath, json_encode(['extra' => ['public-dir' => 'custom_public']])); | ||
|
||
$provider = new PublicDirectoryProvider($this->projectDir); | ||
|
||
self::assertSame($this->projectDir . '/custom_public', $provider->getPublicDirectory()); | ||
} | ||
|
||
public function testGetPublicDirectoryInvalidJson(): void | ||
{ | ||
$composerJsonPath = $this->projectDir . '/composer.json'; | ||
|
||
file_put_contents($composerJsonPath, '{invalid json}'); | ||
|
||
$provider = new PublicDirectoryProvider($this->projectDir); | ||
|
||
self::assertSame($this->projectDir . '/public', $provider->getPublicDirectory()); | ||
} | ||
|
||
public function testGetPublicDirectoryWhenComposerFileDoesNotExist(): void | ||
{ | ||
$provider = new PublicDirectoryProvider($this->projectDir); | ||
|
||
self::assertSame($this->projectDir . '/public', $provider->getPublicDirectory()); | ||
} | ||
|
||
private function removeDirectory(string $directory): void | ||
{ | ||
if (!is_dir($directory)) { | ||
return; | ||
} | ||
|
||
$files = array_diff(scandir($directory), ['.', '..']); | ||
foreach ($files as $file) { | ||
$filePath = $directory . '/' . $file; | ||
is_dir($filePath) ? $this->removeDirectory($filePath) : unlink($filePath); | ||
} | ||
rmdir($directory); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/Oro/Bundle/FormBundle/Resources/views/layouts/default/config/assets.yml
This file contains 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 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
4 changes: 4 additions & 0 deletions
4
src/Oro/Bundle/UIBundle/Resources/views/layouts/default/config/assets.yml
This file contains 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 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 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.