35 protected const SIZE =
'size';
36 protected const SHA1 =
'sha1';
39 private $fileStateByPath;
42 $this->fileStateByPath = [];
53 $this->fileStateByPath[
$path] = [
56 self::SHA1 => $sha1Base36
66 $this->fileStateByPath[
$path] = [
67 self::EXISTS =>
false,
81 return self::resolveFileProperty(
$path, self::EXISTS, $curExistenceFunc );
92 return self::resolveFileProperty(
$path, self::SIZE, $curSizeFunc );
103 return self::resolveFileProperty(
$path, self::SHA1, $curSha1Func );
112 private function resolveFileProperty(
$path, $property, $curValueFunc ) {
113 if ( isset( $this->fileStateByPath[
$path] ) ) {
115 $value = $this->fileStateByPath[
$path][$property];
116 if ( $value instanceof Closure ) {
118 $this->fileStateByPath[
$path][$property] = $value;
122 $value = $curValueFunc(
$path );
133 $snapshot =
new self();
134 foreach ( $paths as
$path ) {
135 if ( isset( $this->fileStateByPath[
$path] ) ) {
136 $snapshot->fileStateByPath[
$path] = $this->fileStateByPath[
$path];
Helper class for tracking counterfactual file states when pre-checking file operation batches.
resolveFileSha1Base36(string $path, $curSha1Func)
Get the hypothetical SHA-1 hash of a file given predicated and current state of files.
resolveFileSize(string $path, $curSizeFunc)
Get the hypothetical size of a file given predicated and current state of files.
assumeFileExists(string $path, $size, $sha1Base36)
Predicate that a file exists at the path.
resolveFileExistence(string $path, $curExistenceFunc)
Get the hypothetical existance a file given predicated and current state of files.
assumeFileDoesNotExist(string $path)
Predicate that no file exists at the path.