You are here

public function ImageStyle::getPathToken in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/image/src/Entity/ImageStyle.php \Drupal\image\Entity\ImageStyle::getPathToken()

Generates a token to protect an image style derivative.

This prevents unauthorized generation of an image style derivative, which can be costly both in CPU time and disk space.

Parameters

string $uri: The URI of the original image of this style.

Return value

string An eight-character token which can be used to protect image style derivatives against denial-of-service attacks.

Overrides ImageStyleInterface::getPathToken

1 call to ImageStyle::getPathToken()
ImageStyle::buildUrl in core/modules/image/src/Entity/ImageStyle.php
Returns the URL of this image derivative for an original image path or URI.

File

core/modules/image/src/Entity/ImageStyle.php, line 331
Contains \Drupal\image\Entity\ImageStyle.

Class

ImageStyle
Defines an image style configuration entity.

Namespace

Drupal\image\Entity

Code

public function getPathToken($uri) {

  // Return the first 8 characters.
  return substr(Crypt::hmacBase64($this
    ->id() . ':' . $this
    ->addExtension($uri), $this
    ->getPrivateKey() . $this
    ->getHashSalt()), 0, 8);
}