-
-
Notifications
You must be signed in to change notification settings - Fork 641
Expand file tree
/
Copy pathGlideUrlBuilder.php
More file actions
74 lines (64 loc) · 2.08 KB
/
Copy pathGlideUrlBuilder.php
File metadata and controls
74 lines (64 loc) · 2.08 KB
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
64
65
66
67
68
69
70
71
72
73
74
<?php
namespace Statamic\Imaging;
use Exception;
use League\Glide\Urls\UrlBuilderFactory;
use Statamic\Contracts\Assets\Asset;
use Statamic\Facades\URL;
use Statamic\Imaging\Manipulators\GlideManipulator;
use Statamic\Support\Str;
/**
* @deprecated URL building is now done in dedicated manipulator classes.
* @see GlideManipulator
*/
class GlideUrlBuilder extends ImageUrlBuilder
{
/**
* @var array
*/
protected $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)
{
$this->item = $item;
switch ($this->itemType()) {
case 'url':
$path = 'http/'.base64_encode($item);
$filename = Str::afterLast($item, '/');
break;
case 'asset':
$path = 'asset/'.base64_encode($this->item->containerId().'/'.$this->item->path());
$filename = Str::afterLast($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 (isset($filename)) {
$path .= Str::ensureLeft(URL::encode($filename), '/');
}
if (isset($params['mark']) && $params['mark'] instanceof Asset) {
$asset = $params['mark'];
$params['mark'] = 'asset::'.base64_encode($asset->containerId().'/'.$asset->path());
}
return URL::prependSiteRoot($builder->getUrl($path, $params));
}
}