class UriHelper (View source)

Methods

static string
addOptionsToUriString(string $url, array|string $options)

Allows you to add stack options to a Rokka URL.

static UriInterface
addOptionsToUri(UriInterface $uri, array|string $options)

Allows you to add stack options to a Rokka URL.

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

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, null|string $custom = null)

No description

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

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

Details

static string addOptionsToUriString(string $url, array|string $options)

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

Return Value

string

See also

UriHelper::addOptionsToUri

static UriInterface addOptionsToUri(UriInterface $uri, array|string $options)

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

Return Value

UriInterface

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

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

Return Value

UriInterface

static UriComponents|null decomposeUri(UriInterface $uri)

Since: 1.2.0

Return components of a rokka URL.

Parameters

UriInterface $uri

Return Value

UriComponents|null

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

No description

Parameters

string $url

The original rokka render URL to be adjusted

string $size

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

null|string $custom

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

Return Value

UriInterface

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

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'

null|string $custom

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

Return Value

UriInterface