4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Config\Resource;
15 * FileResource represents a resource stored on the filesystem.
17 * The resource can be a file or a directory.
19 * @author Fabien Potencier <fabien@symfony.com>
21 class FileResource implements SelfCheckingResourceInterface, \Serializable
31 * @param string $resource The file path to the resource
33 * @throws \InvalidArgumentException
35 public function __construct($resource)
37 $this->resource = realpath($resource) ?: (file_exists($resource) ? $resource : false);
39 if (false === $this->resource) {
40 throw new \InvalidArgumentException(sprintf('The file "%s" does not exist.', $resource));
47 public function __toString()
49 return $this->resource;
53 * @return string The canonicalized, absolute path to the resource
55 public function getResource()
57 return $this->resource;
63 public function isFresh($timestamp)
65 return file_exists($this->resource) && @filemtime($this->resource) <= $timestamp;
68 public function serialize()
70 return serialize($this->resource);
73 public function unserialize($serialized)
75 $this->resource = unserialize($serialized);