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

No description

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

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

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, null|string $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'

null|string $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, null|string $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'

null|string $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