IndeterminateBundleException.php in Lightning Media 8.4
File
src/Exception/IndeterminateBundleException.php
View source
<?php
namespace Drupal\lightning_media\Exception;
use Drupal\Core\Entity\EntityInterface;
use Drupal\media\MediaTypeInterface;
class IndeterminateBundleException extends \LogicException implements \IteratorAggregate, \Countable {
private $types = [];
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));
foreach ($types as $media_type) {
$key = $media_type
->id();
$this->types[$key] = $media_type;
}
parent::__construct($message, $code, $previous);
}
public function matched($type) {
return array_key_exists($type, $this->types);
}
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.';
}
public function count() {
return count($this->types);
}
public function getIterator() {
return new \ArrayIterator($this->types);
}
}