Skip to content

Instantly share code, notes, and snippets.

@joelhinz
Last active November 25, 2016 13:46
Show Gist options
  • Save joelhinz/e959d54b4c24fef84cb6b8bb3ef48be9 to your computer and use it in GitHub Desktop.
Save joelhinz/e959d54b4c24fef84cb6b8bb3ef48be9 to your computer and use it in GitHub Desktop.
mer ioc!
<?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