| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Created for IG Monitoring. |
||
| 4 | * User: jakim <[email protected]> |
||
| 5 | * Date: 11.01.2018 |
||
| 6 | */ |
||
| 7 | |||
| 8 | namespace app\components\http; |
||
| 9 | |||
| 10 | |||
| 11 | use yii\base\Component; |
||
| 12 | use yii\di\Instance; |
||
| 13 | |||
| 14 | class UserAgent extends Component |
||
| 15 | { |
||
| 16 | public $cache = 'cache'; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @return mixed |
||
| 20 | * @throws \yii\base\InvalidConfigException |
||
| 21 | */ |
||
| 22 | public function random() |
||
| 23 | { |
||
| 24 | /** @var \yii\caching\Cache $cache */ |
||
| 25 | $cache = Instance::ensure($this->cache); |
||
| 26 | |||
| 27 | $items = $cache->getOrSet(__METHOD__, function() { |
||
| 28 | return (new \jakim\ua\UserAgent())->fetch(); |
||
| 29 | }, 60 * 60 * 24 * 30); |
||
| 30 | |||
| 31 | shuffle($items); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 32 | |||
| 33 | return $items['0']; |
||
| 34 | } |
||
| 35 | } |