cacheFile = $file; $this->parser = new Yaml(); $this->app = $app; $this->registry = $this->parser->parse($file) ? : array(); } protected function exists($name) { return isset($this->registry[$name]); } public function flushAll() { foreach ($this->registry as $cacheKey => $service_name) { $this->get($cacheKey, $service_name)->getDriver()->flushAll(); } file_put_contents($this->cacheFile->getPathname(), ''); return $this; } public function get($cacheKey, $service_name) { try { $configuration = $this->app['phraseanet.configuration']->getService($service_name); $service = Builder::create($this->app, $configuration); $driver = $service->getDriver(); $write = true; } catch (\Exception $e) { $configuration = new ParameterBag( array('type' => 'Cache\\ArrayCache') ); $service = Builder::create($this->app, $configuration); $driver = $service->getDriver(); $write = false; } if ($this->hasChange($cacheKey, $service_name)) { $service->getDriver()->flushAll(); if ($write) { $this->registry[$cacheKey] = $service_name; $this->save($cacheKey, $service_name); } } return $service; } protected function hasChange($name, $driver) { return $this->exists($name) ? $this->registry[$name] !== $driver : true; } protected function save($name, $driver) { $date = new \DateTime(); $this->registry[$name] = $driver; $datas = sprintf("#LastUpdate: %s\n", $date->format(DATE_ISO8601)) . $this->parser->dump($this->registry, 6); file_put_contents($this->cacheFile->getPathname(), $datas); } }