-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #108 from kbond/zs-uri
- Loading branch information
Showing
20 changed files
with
162 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/.github export-ignore | ||
/tests export-ignore | ||
/bin export-ignore | ||
phpunit.dist.xml export-ignore |
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,10 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
use Symfony\Bundle\FrameworkBundle\Console\Application; | ||
use Zenstruck\Tests\Fixtures\TestKernel; | ||
|
||
require_once __DIR__ . '/../tests/bootstrap.php'; | ||
|
||
$application = new Application(new TestKernel('test', true)); | ||
$application->run(); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
use Psr\Container\ContainerInterface; | ||
use Psr\Container\NotFoundExceptionInterface; | ||
use Zenstruck\Filesystem\Exception\UnsupportedFeature; | ||
use Zenstruck\Filesystem\Flysystem\UrlGeneration\TransformUrlGenerator; | ||
|
||
/** | ||
* @author Kevin Bond <[email protected]> | ||
|
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
59 changes: 59 additions & 0 deletions
59
src/Filesystem/Flysystem/UrlGeneration/VersionUrlGenerator.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,59 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the zenstruck/filesystem package. | ||
* | ||
* (c) Kevin Bond <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Zenstruck\Filesystem\Flysystem\UrlGeneration; | ||
|
||
use League\Flysystem\Config; | ||
use League\Flysystem\UrlGeneration\PublicUrlGenerator; | ||
use Zenstruck\Filesystem\Node\File; | ||
use Zenstruck\Filesystem\Node\Mapping; | ||
use Zenstruck\Uri\ParsedUri; | ||
|
||
/** | ||
* @author Kevin Bond <[email protected]> | ||
*/ | ||
final class VersionUrlGenerator implements PublicUrlGenerator | ||
{ | ||
/** | ||
* @param Mapping::LAST_MODIFIED|Mapping::SIZE|Mapping::CHECKSUM $metadata | ||
*/ | ||
public function __construct( | ||
private PublicUrlGenerator $inner, | ||
private string $metadata = Mapping::LAST_MODIFIED, | ||
private string $queryParameter = 'v', | ||
) { | ||
} | ||
|
||
public function publicUrl(string $path, Config $config): string | ||
{ | ||
if (false === ($version = $config->get('version') ?? $this->metadata)) { | ||
return $this->inner->publicUrl($path, $config); | ||
} | ||
|
||
$file = $config->get('_file'); | ||
|
||
if (!$file instanceof File) { | ||
throw new \LogicException(\sprintf('"%s::publicUrl()" requires the "_file" option to be set to a "%s" instance.', self::class, File::class)); | ||
} | ||
|
||
$value = match ($version) { | ||
Mapping::LAST_MODIFIED => $file->lastModified()->getTimestamp(), | ||
Mapping::SIZE => $file->size(), | ||
Mapping::CHECKSUM => $file->checksum(), | ||
default => throw new \InvalidArgumentException(\sprintf('Unknown version "%s".', $version)), | ||
}; | ||
|
||
return ParsedUri::new($this->inner->publicUrl($path, $config)) | ||
->withQueryParam($this->queryParameter, $value) | ||
->toString() | ||
; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
|
||
use League\Flysystem\Config; | ||
use League\Glide\Urls\UrlBuilder; | ||
use Zenstruck\Filesystem\Flysystem\TransformUrlGenerator; | ||
use Zenstruck\Filesystem\Flysystem\UrlGeneration\TransformUrlGenerator; | ||
|
||
/** | ||
* @author Jakub Caban <[email protected]> | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
namespace Zenstruck\Filesystem\Symfony\Routing; | ||
|
||
use League\Flysystem\Config; | ||
use Zenstruck\Filesystem\Flysystem\TransformUrlGenerator; | ||
use Zenstruck\Filesystem\Flysystem\UrlGeneration\TransformUrlGenerator; | ||
|
||
/** | ||
* @author Kevin Bond <[email protected]> | ||
|
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 |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
use Psr\Container\ContainerInterface; | ||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | ||
use Zenstruck\Uri\Bridge\Symfony\Routing\SignedUrlGenerator; | ||
use Zenstruck\Uri\Bridge\Symfony\ZenstruckUriBundle; | ||
|
||
/** | ||
* @author Kevin Bond <[email protected]> | ||
|
@@ -54,7 +55,7 @@ final protected function generate(string $path, array $routeParameters, ?bool $s | |
} | ||
|
||
if (!$this->container->has(SignedUrlGenerator::class)) { | ||
throw new \LogicException('zenstruck/url is required to sign urls. Install with "composer require zenstruck/uri" and be sure the bundle is enabled.'); | ||
throw new \LogicException(\sprintf('%s needs to be enabled to sign urls.', ZenstruckUriBundle::class)); | ||
} | ||
|
||
$builder = $this->container->get(SignedUrlGenerator::class)->build($this->route, $routeParameters); | ||
|
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
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