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
Custom namer for Uri #1310
Labels
Comments
+1 I also think this would be a welcomed feature. Until then on way to achieve what you describe is to decorate the used Storage and add custom code for each mapping like so: //...
#[AsDecorator(decorates: FileSystemStorage::class)]
class PrivateUriAwareStorage implements StorageInterface
{
public function __construct(
#[MapDecorated] private readonly StorageInterface $decorated,
private readonly UrlGeneratorInterface $urlGenerator
) {
}
public function resolveUri($obj, ?string $fieldName = null, ?string $className = null): ?string
{
if ($obj instanceof Entity && 'filedName' === $fieldName && null !== $obj->getId()) {
return $this->urlGenerator->generate(
'name_of_route',
['id' => $obj->getId()],
UrlGeneratorInterface::ABSOLUTE_URL,
);
}
return $this->decorated->resolveUri($obj, $fieldName, $className);
}
public function upload($obj, PropertyMapping $mapping): void
{
$this->decorated->upload($obj, $mapping);
}
public function remove($obj, PropertyMapping $mapping): ?bool
{
return $this->decorated->remove($obj, $mapping);
}
public function resolvePath($obj, ?string $fieldName = null, ?string $className = null, ?bool $relative = false): ?string
{
return $this->decorated->resolvePath($obj, $fieldName, $className, $relative);
}
public function resolveStream($obj, string $fieldName, ?string $className = null)
{
return $this->decorated->resolveStream($obj, $fieldName, $className);
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Feature Request
Summary
It would be nice to have the option for a namer for the url as well, and not just one for the upload file structure and download url
Given that we can use a Uri prefix we could use a controller to download the file without necessarily having the url matching the directory structure of the upload because they are 2 different things, the url one would be public facing and the directory namer is internal facing
Right now because of this shortcoming we have to use the same url structure as the file system structure and possibly run more queries than we have to to retrieve the file id from the url
I'm proposing an override option like uri_directory_namer and uri_namer that would be used instead if defined
The text was updated successfully, but these errors were encountered: