-
-
Notifications
You must be signed in to change notification settings - Fork 530
/
GlideUrlBuilder.php
63 lines (54 loc) · 1.65 KB
/
GlideUrlBuilder.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
namespace Statamic\Imaging;
use Exception;
use League\Glide\Urls\UrlBuilderFactory;
use Statamic\Facades\URL;
use Statamic\Support\Str;
class GlideUrlBuilder extends ImageUrlBuilder
{
/**
* @var array
*/
protected $options;
/**
* @param array $options
*/
public function __construct(array $options = [])
{
$this->options = $options;
}
/**
* Build the URL.
*
* @param \Statamic\Contracts\Assets\Asset|string $item
* @param array $params
* @param string|null $filename
* @return string
* @throws \Exception
*/
public function build($item, $params, $filename = null)
{
$this->item = $item;
switch ($this->itemType()) {
case 'url':
$path = 'http/'.base64_encode($item);
break;
case 'asset':
$path = 'asset/'.base64_encode($this->item->containerId().'/'.$this->item->path());
break;
case 'id':
$path = 'asset/'.base64_encode(str_replace('::', '/', $this->item));
break;
case 'path':
$path = URL::encode($this->item);
break;
default:
throw new Exception('Cannot build a Glide URL without a URL, path, or asset.');
}
$builder = UrlBuilderFactory::create($this->options['route'], $this->options['key']);
if ($filename) {
$path .= Str::ensureLeft(URL::encode($filename), '/');
}
return URL::prependSiteRoot($builder->getUrl($path, $params));
}
}