Skip to content

Instantly share code, notes, and snippets.

@metalagman
Created November 9, 2017 10:02
Show Gist options
  • Save metalagman/22d4e4b507ed4d3e52027a81af5c1221 to your computer and use it in GitHub Desktop.
Save metalagman/22d4e4b507ed4d3e52027a81af5c1221 to your computer and use it in GitHub Desktop.
<?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