class UriHelper (View source)

Methods

static string
addOptionsToUriString(string $url, array|string $options, bool $shortNames = true)

Allows you to add stack options to a Rokka URL.

static UriInterface
addOptionsToUri(UriInterface $uri, array|string $options, bool $shortNames = true)

Allows you to add stack options to a Rokka URL.

static UriInterface
composeUri(array|UriComponents $components, UriInterface $uri = null, bool $shortNames = true)

Generate a rokka uri with an array or an UriComponent returned by decomposeUri().

static UriComponents|null
decomposeUri(UriInterface $uri)

Return components of a rokka URL.

static UriInterface
getSrcSetUrlString(string $url, string $size, string|null $custom = null, bool $setWidthInUrl = true)

No description

static UriInterface
getSrcSetUrl(UriInterface $url, string $size, string|null $custom = null, bool $setWidthInUrl = true)

Returns a rokka URL to be used in srcset style attributes.

static UriInterface
signUrl(string|UriInterface $url, string $signKey, DateTimeInterface $until = null, int $roundDateUpTo = 300)

Signs a Rokka URL with an option valid until date.

Details

static string addOptionsToUriString(string $url, array|string $options, bool $shortNames = true)

Allows you to add stack options to a Rokka URL.

Useful eg. if you just want to add "options-dpr-2" to an existing URL. Returns the original URL, if it can't parse it as valid Rokka URL.

Parameters

string $url

The rokka image render URL

array|string $options

The options you want to add as string

bool $shortNames

if short names (like o for option or v for variables) should be used

Return Value

string

Exceptions

RuntimeException

See also

UriHelper::addOptionsToUri

static UriInterface addOptionsToUri(UriInterface $uri, array|string $options, bool $shortNames = true)

Allows you to add stack options to a Rokka URL.

Useful eg. if you just want to add "options-dpr-2" to an existing URL Returns the original URL, if it can't parse it as valid Rokka URL.

Example with string as input

UriHelper::addOptionsToUri($uri, 'options-dpr-2--resize-upscale-false');

Example with array

UriHelper::addOptionsToUri($uri,
  [
   'options' => ['dpr' => 2],
   'operations' =>
     [
       [
         'name' => 'resize',
         'options' => ['upscale' => 'false']
       ],
     ],
  ]);

Parameters

UriInterface $uri

The rokka image render URL

array|string $options

The options you want to add as string

bool $shortNames

if short names (like o for option or v for variables) should be used

Return Value

UriInterface

Exceptions

RuntimeException

static UriInterface composeUri(array|UriComponents $components, UriInterface $uri = null, bool $shortNames = true)

Since: 1.2.0

Generate a rokka uri with an array or an UriComponent returned by decomposeUri().

The array looks like

['stack' => 'stackname', #or StackUri object
 'hash' => 'hash',
 'filename' => 'filename-for-url',
 'format' => 'image format', # eg. jpg
]

Parameters

array|UriComponents $components
UriInterface $uri

If this is provided, it will change the path for that object and return

bool $shortNames

if short names (like o for option or v for variables) should be used

Return Value

UriInterface

Exceptions

RuntimeException

static UriComponents|null decomposeUri(UriInterface $uri)

Since: 1.2.0

Return components of a rokka URL.

Parameters

UriInterface $uri

Return Value

UriComponents|null

Exceptions

RuntimeException

static UriInterface getSrcSetUrlString(string $url, string $size, string|null $custom = null, bool $setWidthInUrl = true)

No description

Parameters

string $url

The original rokka render URL to be adjusted

string $size

The size of the image, eg '300w' or '2x'

string|null $custom

Any rokka options you'd like to add, or are a dpi identifier like '2x'

bool $setWidthInUrl

If false, don't set the width as stack operation option, we provide it in $custom, usually as parameter

Return Value

UriInterface

Exceptions

RuntimeException

static UriInterface getSrcSetUrl(UriInterface $url, string $size, string|null $custom = null, bool $setWidthInUrl = true)

Returns a rokka URL to be used in srcset style attributes.

$size can be eg. "2x" or "500w" $custom can be any rokka options you want to optionally add, or also a dpi identifier like "2x"

This method will then generate the right rokka URLs to get what you want, see \Rokka\Client\Tests\UriHelperTest::provideGetSrcSetUrl for some examples and the expected returns.

Parameters

UriInterface $url

The original rokka render URL to be adjusted

string $size

The size of the image, eg '300w' or '2x'

string|null $custom

Any rokka options you'd like to add, or are a dpi identifier like '2x'

bool $setWidthInUrl

If false, don't set the width as stack operation option, we provide it in $custom, usually as parameter

Return Value

UriInterface

Exceptions

RuntimeException

static UriInterface signUrl(string|UriInterface $url, string $signKey, DateTimeInterface $until = null, int $roundDateUpTo = 300)

Signs a Rokka URL with an option valid until date.

It also rounds up the date to the next 5 minutes (300 seconds) to improve CDN caching, can be changed

Parameters

string|UriInterface $url
string $signKey
DateTimeInterface $until

Until when is it valid

int $roundDateUpTo

To which seconds the date should be rounded up

Return Value

UriInterface

Exceptions

Exception