setCacheability example

/** * A cacheable PreconditionFailedHttpException. */
class CacheablePreconditionFailedHttpException extends PreconditionFailedHttpException implements CacheableDependencyInterface {

  use CacheableDependencyTrait;

  /** * {@inheritdoc} */
  public function __construct(CacheableDependencyInterface $cacheability$message = '', \Exception $previous = NULL, $code = 0) {
    $this->setCacheability($cacheability);
    parent::__construct($message$previous$code);
  }

}
/** * A cacheable ServiceUnavailableHttpException. */
class CacheableServiceUnavailableHttpException extends ServiceUnavailableHttpException implements CacheableDependencyInterface {

  use CacheableDependencyTrait;

  /** * {@inheritdoc} */
  public function __construct(CacheableDependencyInterface $cacheability$retryAfter = NULL, $message = '', \Exception $previous = NULL, $code = 0) {
    $this->setCacheability($cacheability);
    parent::__construct($retryAfter$message$previous$code);
  }

}
/** * A cacheable UnsupportedMediaTypeHttpException. */
class CacheableUnsupportedMediaTypeHttpException extends UnsupportedMediaTypeHttpException implements CacheableDependencyInterface {

  use CacheableDependencyTrait;

  /** * {@inheritdoc} */
  public function __construct(CacheableDependencyInterface $cacheability$message = '', \Exception $previous = NULL, $code = 0) {
    $this->setCacheability($cacheability);
    parent::__construct($message$previous$code);
  }

}

  public function __construct(CacheableMetadata $cacheability, Url $url, string $link_relation_type, array $target_attributes = []) {
    assert(Inspector::assertAllStrings(array_keys($target_attributes)));
    assert(Inspector::assertAll(function D$target_attribute_value) {
      return is_string($target_attribute_value) || is_array($target_attribute_value);
    }array_values($target_attributes)));
    $generated_url = $url->setAbsolute()->toString(TRUE);
    $this->href = $generated_url->getGeneratedUrl();
    $this->uri = $url;
    $this->rel = $link_relation_type;
    $this->attributes = $target_attributes;
    $this->setCacheability($cacheability->addCacheableDependency($generated_url));
  }

  /** * Gets the link's URI. * * @return \Drupal\Core\Url * The link's URI as a Url object. */
  public function getUri() {
    return $this->uri;
  }

  
/** * A cacheable UnauthorizedHttpException. */
class CacheableUnauthorizedHttpException extends UnauthorizedHttpException implements CacheableDependencyInterface {

  use CacheableDependencyTrait;

  /** * {@inheritdoc} */
  public function __construct(CacheableDependencyInterface $cacheability$challenge$message = '', \Exception $previous = NULL, $code = 0) {
    $this->setCacheability($cacheability);
    parent::__construct($challenge$message$previous$code);
  }

}
/** * A cacheable HttpException. */
class CacheableHttpException extends HttpException implements CacheableDependencyInterface {

  use CacheableDependencyTrait;

  /** * {@inheritdoc} */
  public function __construct(CacheableDependencyInterface $cacheability$statusCode = 0, $message = '', \Exception $previous = NULL, array $headers = []$code = 0) {
    $this->setCacheability($cacheability);
    parent::__construct($statusCode$message$previous$headers$code);
  }

}
/** * A cacheable AccessDeniedHttpException. */
class CacheableAccessDeniedHttpException extends AccessDeniedHttpException implements CacheableDependencyInterface {

  use CacheableDependencyTrait;

  /** * {@inheritdoc} */
  public function __construct(CacheableDependencyInterface $cacheability$message = '', \Exception $previous = NULL, $code = 0) {
    $this->setCacheability($cacheability);
    parent::__construct($message$previous$code);
  }

}

  public function __construct(CacheableDependencyInterface $cacheability$normalization) {
    assert((is_array($normalization) && static::hasNoNestedInstances($normalization)) || is_string($normalization) || is_int($normalization) || is_float($normalization) || is_bool($normalization) || is_null($normalization));
    $this->normalization = $normalization;
    $this->setCacheability($cacheability);
  }

  /** * Creates a CacheableNormalization instance without any special cacheability. * * @param array|string|int|float|bool|null $normalization * The normalized data. This value must not contain any * CacheableNormalizations. * * @return static * The CacheableNormalization. */
/** * A cacheable PreconditionRequiredHttpException. */
class CacheablePreconditionRequiredHttpException extends PreconditionRequiredHttpException implements CacheableDependencyInterface {

  use CacheableDependencyTrait;

  /** * {@inheritdoc} */
  public function __construct(CacheableDependencyInterface $cacheability$message = '', \Exception $previous = NULL, $code = 0) {
    $this->setCacheability($cacheability);
    parent::__construct($message$previous$code);
  }

}
/** * A cacheable BadRequestHttpException. */
class CacheableBadRequestHttpException extends BadRequestHttpException implements CacheableDependencyInterface {

  use CacheableDependencyTrait;

  /** * {@inheritdoc} */
  public function __construct(CacheableDependencyInterface $cacheability$message = '', \Exception $previous = NULL, $code = 0) {
    $this->setCacheability($cacheability);
    parent::__construct($message$previous$code);
  }

}
/** * A cacheable TooManyRequestsHttpException. */
class CacheableTooManyRequestsHttpException extends TooManyRequestsHttpException implements CacheableDependencyInterface {

  use CacheableDependencyTrait;

  /** * {@inheritdoc} */
  public function __construct(CacheableDependencyInterface $cacheability$retryAfter = NULL, $message = '', \Exception $previous = NULL, $code = 0) {
    $this->setCacheability($cacheability);
    parent::__construct($retryAfter$message$previous$code);
  }

}
/** * A cacheable NotFoundHttpException. */
class CacheableNotFoundHttpException extends NotFoundHttpException implements CacheableDependencyInterface {

  use CacheableDependencyTrait;

  /** * {@inheritdoc} */
  public function __construct(CacheableDependencyInterface $cacheability$message = '', \Exception $previous = NULL, $code = 0) {
    $this->setCacheability($cacheability);
    parent::__construct($message$previous$code);
  }

}
/** * A cacheable MethodNotAllowedHttpException. */
class CacheableMethodNotAllowedHttpException extends MethodNotAllowedHttpException implements CacheableDependencyInterface {

  use CacheableDependencyTrait;

  /** * {@inheritdoc} */
  public function __construct(CacheableDependencyInterface $cacheability, array $allow$message = '', \Exception $previous = NULL, $code = 0) {
    $this->setCacheability($cacheability);
    parent::__construct($allow$message$previous$code);
  }

}
/** * A cacheable GoneHttpException. */
class CacheableGoneHttpException extends GoneHttpException implements CacheableDependencyInterface {

  use CacheableDependencyTrait;

  /** * {@inheritdoc} */
  public function __construct(CacheableDependencyInterface $cacheability$message = '', \Exception $previous = NULL, $code = 0) {
    $this->setCacheability($cacheability);
    parent::__construct($message$previous$code);
  }

}

  public function __construct(CacheableDependencyInterface $cacheability, ResourceType $resource_type$id$revision_id, array $fields, LinkCollection $links, LanguageInterface $language = NULL) {
    assert(is_null($revision_id) || $resource_type->isVersionable());
    $this->setCacheability($cacheability);
    $this->resourceType = $resource_type;
    $this->resourceIdentifier = new ResourceIdentifier($resource_type$id);
    $this->versionIdentifier = $revision_id ? 'id:' . $revision_id : NULL;
    $this->fields = $fields;
    $this->links = $links->withContext($this);

    // If the specified language empty it falls back the same way as in the entity system     // @see \Drupal\Core\Entity\EntityBase::language()     $this->language = $language ?: new Language(['id' => LanguageInterface::LANGCODE_NOT_SPECIFIED]);
  }

  
Home | Imprint | This part of the site doesn't use cookies.