* Constructor.
*
* @param string $resource The file path to the resource
+ *
+ * @throws \InvalidArgumentException
*/
public function __construct($resource)
{
$this->resource = realpath($resource) ?: (file_exists($resource) ? $resource : false);
+
+ if (false === $this->resource) {
+ throw new \InvalidArgumentException(sprintf('The file "%s" does not exist.', $resource));
+ }
}
/**
*/
public function __toString()
{
- return (string) $this->resource;
+ return $this->resource;
}
/**
- * {@inheritdoc}
+ * @return string The canonicalized, absolute path to the resource
*/
public function getResource()
{
*/
public function isFresh($timestamp)
{
- if (false === $this->resource || !file_exists($this->resource)) {
- return false;
- }
-
- return filemtime($this->resource) <= $timestamp;
+ return file_exists($this->resource) && @filemtime($this->resource) <= $timestamp;
}
public function serialize()