Last active
November 25, 2016 13:46
-
-
Save joelhinz/e959d54b4c24fef84cb6b8bb3ef48be9 to your computer and use it in GitHub Desktop.
mer ioc!
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 | |
// en global helper | |
function stats($object = null) | |
{ | |
$cache = App::make('statistics-cache'); | |
return $object ? $cache->resolve($object) : $cache; | |
} | |
// statistics-cache (tog bort det mesta för att visa själva poängen med det) | |
class StatisticsCache | |
{ | |
private $seasons; | |
public function __construct() | |
{ | |
$this->seasons = collect([]); | |
} | |
public function resolve($object) | |
{ | |
if (is_a($object, Season::class)) { | |
return $this->season($object); | |
} | |
return null; | |
} | |
public function season(Season $season) | |
{ | |
$key = $season->id; | |
if (!$this->seasons->has($key)) { | |
$this->seasons->put($key, new SeasonCache($season)); | |
} | |
return $this->seasons->get($key); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment