-
Notifications
You must be signed in to change notification settings - Fork 176
/
UploaderHelper.php
49 lines (38 loc) · 1.18 KB
/
UploaderHelper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
declare(strict_types=1);
namespace Oneup\UploaderBundle\Templating\Helper;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Templating\Helper\Helper;
class UploaderHelper extends Helper
{
public function __construct(protected RouterInterface $router, protected array $maxsize)
{
}
public function getName(): string
{
return 'oneup_uploader';
}
public function endpoint(string $key): string
{
return $this->router->generate(sprintf('_uploader_upload_%s', $key));
}
public function progress(string $key): string
{
return $this->router->generate(sprintf('_uploader_progress_%s', $key));
}
public function cancel(string $key): string
{
return $this->router->generate(sprintf('_uploader_cancel_%s', $key));
}
public function uploadKey(): string
{
return (string) \ini_get('session.upload_progress.name');
}
public function maxSize(string $key): int
{
if (!\array_key_exists($key, $this->maxsize)) {
throw new \InvalidArgumentException('No such mapping found to get maxsize for.');
}
return $this->maxsize[$key];
}
}