vendor/metadata/src/Metadata/Cache/FileCache.php
changeset 0 7f95f8617b0b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/metadata/src/Metadata/Cache/FileCache.php	Sat Sep 24 15:40:41 2011 +0200
@@ -0,0 +1,46 @@
+<?php
+
+namespace Metadata\Cache;
+
+use Metadata\ClassMetadata;
+
+class FileCache implements CacheInterface
+{
+    private $dir;
+
+    public function __construct($dir)
+    {
+        if (!is_dir($dir)) {
+            throw new \InvalidArgumentException(sprintf('The directory "%s" does not exist.', $dir));
+        }
+        if (!is_writable($dir)) {
+            throw new \InvalidArgumentException(sprintf('The directory "%s" is not writable.', $dir));
+        }
+
+        $this->dir = rtrim($dir, '\\/');
+    }
+
+    public function loadClassMetadataFromCache(\ReflectionClass $class)
+    {
+        $path = $this->dir.'/'.strtr($class->getName(), '\\', '-').'.cache.php';
+        if (!file_exists($path)) {
+            return null;
+        }
+
+        return include $path;
+    }
+
+    public function putClassMetadataInCache(ClassMetadata $metadata)
+    {
+        $path = $this->dir.'/'.strtr($metadata->name, '\\', '-').'.cache.php';
+        file_put_contents($path, '<?php return unserialize('.var_export(serialize($metadata), true).');');
+    }
+
+    public function evictClassMetadataFromCache(\ReflectionClass $class)
+    {
+        $path = $this->dir.'/'.strtr($class->getName(), '\\', '-').'.cache.php';
+        if (file_exists($path)) {
+            unlink($path);
+        }
+    }
+}
\ No newline at end of file