Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/DataLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@

use Overblog\PromiseAdapter\PromiseAdapterInterface;

/**
* @template TPromise
*
* @implements DataLoaderInterface<TPromise>
*/
class DataLoader implements DataLoaderInterface
{
/**
Expand Down Expand Up @@ -51,10 +56,13 @@ class DataLoader implements DataLoaderInterface
private static $promiseAdapters;

/**
* @var PromiseAdapterInterface
* @var PromiseAdapterInterface<TPromise>
*/
private $promiseAdapter;

/**
* @param PromiseAdapterInterface<TPromise> $promiseFactory
*/
public function __construct(callable $batchLoadFn, PromiseAdapterInterface $promiseFactory, ?Option $options = null)
{
$this->batchLoadFn = $batchLoadFn;
Expand All @@ -65,9 +73,7 @@ public function __construct(callable $batchLoadFn, PromiseAdapterInterface $prom
self::$instances[$this] = null;
}

/**
* {@inheritdoc}
*/
/** @return TPromise */
public function load($key)
{
$this->checkKey($key, __METHOD__);
Expand Down Expand Up @@ -122,9 +128,7 @@ static function () {
return $promise;
}

/**
* {@inheritdoc}
*/
/** @return TPromise */
public function loadMany($keys)
{
if (!is_array($keys) && !$keys instanceof \Traversable) {
Expand Down Expand Up @@ -219,6 +223,7 @@ protected function process()
}
}

/** @return PromiseAdapterInterface<TPromise> */
protected function getPromiseAdapter()
{
return $this->promiseAdapter;
Expand Down
7 changes: 5 additions & 2 deletions src/DataLoaderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@

namespace Overblog\DataLoader;

/**
* @template TPromise
*/
interface DataLoaderInterface
{
/**
* Loads a key, returning a `Promise` for the value represented by that key.
*
* @param mixed $key
*
* @return mixed return a Promise
* @return TPromise a Promise
*/
public function load($key);

Expand All @@ -35,7 +38,7 @@ public function load($key);
* ]);
* @param array $keys
*
* @return mixed return a Promise
* @return TPromise a Promise
*/
public function loadMany($keys);

Expand Down
Loading