You are here

class IndeterminateBundleException in Lightning Media 8.3

Same name and namespace in other branches
  1. 8.4 src/Exception/IndeterminateBundleException.php \Drupal\lightning_media\Exception\IndeterminateBundleException
  2. 8 src/Exception/IndeterminateBundleException.php \Drupal\lightning_media\Exception\IndeterminateBundleException
  3. 8.2 src/Exception/IndeterminateBundleException.php \Drupal\lightning_media\Exception\IndeterminateBundleException

Thrown if no single media type can be determined from an input value.

Hierarchy

  • class \Drupal\lightning_media\Exception\IndeterminateBundleException extends \Drupal\lightning_media\Exception\LogicException implements \Drupal\lightning_media\Exception\IteratorAggregate, \Drupal\lightning_media\Exception\Countable

Expanded class hierarchy of IndeterminateBundleException

3 files declare their use of IndeterminateBundleException
BulkUploadForm.php in modules/lightning_media_bulk_upload/src/Form/BulkUploadForm.php
lightning_media.module in ./lightning_media.module
Core media asset support for Lightning.
MediaHelper.php in src/MediaHelper.php

File

src/Exception/IndeterminateBundleException.php, line 11

Namespace

Drupal\lightning_media\Exception
View source
class IndeterminateBundleException extends \LogicException implements \IteratorAggregate, \Countable {

  /**
   * The media types which matched the input value.
   *
   * @var \Drupal\media\MediaTypeInterface[]
   */
  private $types = [];

  /**
   * IndeterminateBundleException constructor.
   *
   * @param mixed $value
   *   The input value.
   * @param int $code
   *   (optional) The error code.
   * @param \Exception $previous
   *   (optional) The previous exception, if any.
   * @param \Drupal\media\MediaTypeInterface[] $types
   *   (optional) The media types which matched the input value.
   */
  public function __construct($value, $code = 0, \Exception $previous = NULL, array $types = []) {
    $message = sprintf($types ? 'Input matched multiple media types: %s' : 'Input did not match any media types: %s', $value instanceof EntityInterface ? $value
      ->label() : var_export($value, TRUE));

    /** @var \Drupal\media\MediaTypeInterface $media_type */
    foreach ($types as $media_type) {
      $key = $media_type
        ->id();
      $this->types[$key] = $media_type;
    }
    parent::__construct($message, $code, $previous);
  }

  /**
   * Checks if the input value matched a particular media type.
   *
   * @param string $type
   *   The media type ID to check.
   *
   * @return bool
   *   TRUE if the input value matched the media type, otherwise FALSE.
   */
  public function matched($type) {
    return array_key_exists($type, $this->types);
  }

  /**
   * {@inheritdoc}
   */
  public function __toString() {
    $count = count($this);
    if ($count > 0) {
      $types = array_map(function (MediaTypeInterface $media_type) {
        return $media_type
          ->id();
      }, $this->types);
      return "Input matched {$count} media types: " . implode(', ', $types);
    }
    return 'Input did not match any media types.';
  }

  /**
   * {@inheritdoc}
   */
  public function count() {
    return count($this->types);
  }

  /**
   * {@inheritdoc}
   */
  public function getIterator() {
    return new \ArrayIterator($this->types);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
IndeterminateBundleException::$types private property The media types which matched the input value.
IndeterminateBundleException::count public function
IndeterminateBundleException::getIterator public function
IndeterminateBundleException::matched public function Checks if the input value matched a particular media type.
IndeterminateBundleException::__construct public function IndeterminateBundleException constructor.
IndeterminateBundleException::__toString public function