Skip to content

Commit aa968dc

Browse files
committed
Also pass $key to Document::fromString()
`Document`s sometimes need to know their ID, and passing the `$key` to `::fromString()` appears to be the least intrusive option to satisfy this need.
1 parent 846afdc commit aa968dc

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

classes/Document.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ interface Document
4141
*
4242
* @return ?static
4343
*/
44-
public static function fromString(string $contents);
44+
public static function fromString(string $contents, string $key);
4545

4646
/**
4747
* Returns the storage representation of the model object

classes/DocumentStore.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public function retrieve(string $key, string $class): ?Document
115115
fclose($stream);
116116
}
117117
}
118-
return $class::fromString($contents ?? "");
118+
return $class::fromString($contents ?? "", $key);
119119
}
120120

121121
/**
@@ -152,7 +152,7 @@ public function update(string $key, string $class): ?Document
152152
$contents = "";
153153
}
154154
}
155-
$document = $class::fromString($contents ?? "");
155+
$document = $class::fromString($contents ?? "", $key);
156156
if ($stream) {
157157
if ($document === null) {
158158
flock($stream, LOCK_UN);

docs/tutorial/persistent_data.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ methods:
5757
{
5858
private $times = [];
5959
60-
public static function fromString(string $contents)
60+
public static function fromString(string $contents, string $key)
6161
{
6262
$that = new static();
6363
$lines = explode("\n", $contents);
@@ -78,7 +78,7 @@ methods:
7878
}
7979
}
8080
81-
`Online::fromString()` parses the file, and stores the relevant
81+
`Online::fromString()` parses the `$contents`, and stores the relevant
8282
data in `Online::$times`, while `Online::toString()` reassembles
8383
the string representation from the private property.
8484
Next, we implement the three pieces of logic, namely to

0 commit comments

Comments
 (0)