Created
November 9, 2017 10:02
-
-
Save metalagman/22d4e4b507ed4d3e52027a81af5c1221 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @author Alexey Samoylov <alexey.samoylov@gmail.com> | |
*/ | |
namespace common\components; | |
use yii\data\DataProviderInterface; | |
class MapDataProvider implements DataProviderInterface | |
{ | |
/** @var DataProviderInterface */ | |
protected $next; | |
/** @var callable */ | |
protected $callback; | |
public function __construct(DataProviderInterface $provider, callable $callback) | |
{ | |
$this->next = $provider; | |
$this->callback = $callback; | |
} | |
public function getCount() | |
{ | |
return $this->next->getCount(); | |
} | |
public function getKeys() | |
{ | |
return $this->next->getKeys(); | |
} | |
public function getPagination() | |
{ | |
return $this->next->getPagination(); | |
} | |
public function getSort() | |
{ | |
return $this->next->getSort(); | |
} | |
public function getTotalCount() | |
{ | |
return $this->next->getTotalCount(); | |
} | |
public function prepare($forcePrepare = false) | |
{ | |
return $this->next->prepare($forcePrepare); | |
} | |
public function getModels() | |
{ | |
$models = $this->next->getModels(); | |
return call_user_func($this->callback, $models); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment