QueueEntityResolver.php
TLDR
This file contains the QueueEntityResolver
class, which implements the EntityResolver
interface. It provides a method resolve()
to resolve the entity for a given ID.
Classes
QueueEntityResolver
The QueueEntityResolver
class is used to resolve entities for a given ID. It implements the EntityResolver
interface. The class has a single method resolve()
which takes two parameters: $type
(string) and $id
(mixed). It creates an instance of the $type
class and attempts to find an entity with the given $id
. If the entity is found, it is returned. If no entity is found, an EntityNotFoundException
is thrown.
<?php
namespace Illuminate\Database\Eloquent;
use Illuminate\Contracts\Queue\EntityNotFoundException;
use Illuminate\Contracts\Queue\EntityResolver as EntityResolverContract;
class QueueEntityResolver implements EntityResolverContract
{
/**
* Resolve the entity for the given ID.
*
* @param string $type
* @param mixed $id
* @return mixed
*
* @throws \Illuminate\Contracts\Queue\EntityNotFoundException
*/
public function resolve($type, $id)
{
$instance = (new $type)->find($id);
if ($instance) {
return $instance;
}
throw new EntityNotFoundException($type, $id);
}
}