Skip to content

Commit 1bd705a

Browse files
authored
Merge pull request #1330 from phpDocumentor/feature/file-system-modified
Add lastModified to filesystem
2 parents 28bd83f + 2772b3d commit 1bd705a

4 files changed

Lines changed: 24 additions & 0 deletions

File tree

packages/filesystem/src/FileSystem.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,7 @@ public function listContents(string $directory = '', bool $recursive = false): a
5656
public function find(SpecificationInterface $specification): iterable;
5757

5858
public function isDirectory(string $path): bool;
59+
60+
/** return the unix timestamp file was modified. */
61+
public function lastModified(string $path): int;
5962
}

packages/filesystem/src/FlySystemAdapter.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,9 @@ public function isDirectory(string $path): bool
9797
{
9898
return $this->filesystem->isDirectory($path);
9999
}
100+
101+
public function lastModified(string $path): int
102+
{
103+
return $this->filesystem->lastModified($path);
104+
}
100105
}

packages/filesystem/src/FlysystemV1/FlysystemV1.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Flyfinder\Finder;
1717
use Flyfinder\Specification\SpecificationInterface;
1818
use League\Flysystem\FilesystemInterface;
19+
use phpDocumentor\FileSystem\FileNotFoundException;
1920
use phpDocumentor\FileSystem\FileSystem;
2021
use phpDocumentor\FileSystem\StorageAttributes;
2122

@@ -85,4 +86,14 @@ public function isDirectory(string $path): bool
8586

8687
return $metadata['type'] === 'dir';
8788
}
89+
90+
public function lastModified(string $path): int
91+
{
92+
$timestamp = $this->filesystem->getTimestamp($path);
93+
if ($timestamp === false) {
94+
throw new FileNotFoundException('File not found: ' . $path);
95+
}
96+
97+
return $timestamp;
98+
}
8899
}

packages/filesystem/src/FlysystemV3/FlysystemV3.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,9 @@ public function find(SpecificationInterface $specification): iterable
7979
yield new FileAttributes($file);
8080
}
8181
}
82+
83+
public function lastModified(string $path): int
84+
{
85+
return $this->filesystem->lastModified($path);
86+
}
8287
}

0 commit comments

Comments
 (0)