TypeifyTypeNotMatchException
Thrown when no type is selected or the current type is not registered, and you try to get/set parameters (e.g. get(), getLabel(), or trait setters without a selected type).
Namespace
JobMetric\Typeify\Exceptions\TypeifyTypeNotMatchException
Constructor
public function __construct(string $service, string $type, int $code = 400, ?Throwable $previous = null)
- $service – The service class name (e.g. your
PostTypeclass). - $type – The type key (may be empty when no type is set).
- $code – HTTP-style code (default 400).
- $previous – Optional previous throwable.
Message
"Type [$type] is not match in service [$service]."
When It Is Thrown
- When you call
get(),getLabel(),getDescription(), or any trait getter/setter without having calleddefine('key')ortype('key')first. - When you call
ensureTypeExists('key')and the type is not registered.
Example
$postType = new PostType();
$postType->getLabel();
This throws TypeifyTypeNotMatchException because no type was selected.
$postType->define('blog');
$postType->ensureTypeExists('news');
This throws when news is not defined.