-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #51847 [AssetMapper] Allowing for files to be written to some…
… non-local location (weaverryan) This PR was squashed before being merged into the 6.4 branch. Discussion ---------- [AssetMapper] Allowing for files to be written to some non-local location | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | Fix #50221 | License | MIT Hi! An attempt at making AssetMapper flexible enough to support non-local filesystems. The "hook point" would be that you could replace the `asset_mapper.local_public_assets_filesystem` service with your own that implements `PublicAssetsFilesystemInterface`. I'm not worried about making the hook point *super* user-friendly: I just want the system to support this now, as trying to add this later (when we need to protect BC) will be harder. Cheers! Commits ------- 48a2d68 [AssetMapper] Allowing for files to be written to some non-local location
- Loading branch information
Showing
19 changed files
with
347 additions
and
166 deletions.
There are no files selected for viewing
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
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
52 changes: 52 additions & 0 deletions
52
src/Symfony/Component/AssetMapper/CompiledAssetMapperConfigReader.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,52 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\AssetMapper; | ||
|
||
use Symfony\Component\Filesystem\Path; | ||
|
||
/** | ||
* Reads and writes compiled configuration files for asset mapper. | ||
*/ | ||
class CompiledAssetMapperConfigReader | ||
{ | ||
public function __construct(private readonly string $directory) | ||
{ | ||
} | ||
|
||
public function configExists(string $filename): bool | ||
{ | ||
return is_file(Path::join($this->directory, $filename)); | ||
} | ||
|
||
public function loadConfig(string $filename): array | ||
{ | ||
return json_decode(file_get_contents(Path::join($this->directory, $filename)), true, 512, \JSON_THROW_ON_ERROR); | ||
} | ||
|
||
public function saveConfig(string $filename, array $data): string | ||
{ | ||
$path = Path::join($this->directory, $filename); | ||
@mkdir(\dirname($path), 0777, true); | ||
file_put_contents($path, json_encode($data, \JSON_PRETTY_PRINT | \JSON_THROW_ON_ERROR)); | ||
|
||
return $path; | ||
} | ||
|
||
public function removeConfig(string $filename): void | ||
{ | ||
$path = Path::join($this->directory, $filename); | ||
|
||
if (is_file($path)) { | ||
unlink($path); | ||
} | ||
} | ||
} |
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.