Source of file ProviderCache.php
Size: 1,229 Bytes - Last Modified: 2021-12-23T10:02:17+00:00
/var/www/docs.ssmods.com/process/src/code/Providers/ProviderCache.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 | <?php namespace Seeder; /** * Class ProviderCache * @package Seeder */ class ProviderCache extends Provider { /** * @var */ public $provider; /** * @var */ private $cacheSize; /** * @var array */ private $cache = array(); /** * @param $provider * @param $cacheSize */ public function __construct($provider, $cacheSize) { parent::__construct(); $this->provider = $provider; $this->setCacheSize($cacheSize); } /** * @param $field * @param $state * @return mixed */ public function generate($field, $state) { if (count($this->cache) < $this->cacheSize) { $result = $this->provider->generate($field, $state); $this->cache[] = $result; return $result; } $key = array_rand($this->cache); return $this->cache[$key]; } /** * @param $size */ public function setCacheSize($size) { $this->cacheSize = max($size, 1); } /** * @param $field * @param $state * @returns null */ protected function generateField($field, $state) { // error } } |