File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3434// 日付付きの JSON ファイルとして保存(例: docs/v2/20250826.json)
3535// 最新データとして today.json にも保存
3636$ storage = new ProgramStorage ();
37- $ storage ->save ($ programs , "docs/ {$ version }/ " . $ date ->format ('Ymd ' ) . '.json ' );
37+ $ storage ->save ($ programs , "docs/ {$ version }/ " . $ date ->format ('Y ' ) . ' / ' . $ date -> format ( ' Ymd ' ) . '.json ' );
3838$ storage ->save ($ programs , "docs/ {$ version }/today.json " );
Original file line number Diff line number Diff line change @@ -56,7 +56,16 @@ final class ProgramStorage
5656 public function save (array $ programs , string $ path ): void
5757 {
5858 $ contents = json_encode (['programs ' => $ programs ]);
59- if ($ contents !== false && file_put_contents ($ path , $ contents ) === false ) {
59+ if ($ contents === false ) {
60+ throw new \RuntimeException ("Failed to encode programs to JSON " );
61+ }
62+
63+ $ dir = dirname ($ path );
64+ if (!is_dir ($ dir ) && !mkdir ($ dir , 0777 , true ) && !is_dir ($ dir )) {
65+ throw new \RuntimeException ("Failed to create directory: {$ dir }" );
66+ }
67+
68+ if (file_put_contents ($ path , $ contents ) === false ) {
6069 throw new \RuntimeException ("Failed to save programs to {$ path }" );
6170 }
6271 }
You can’t perform that action at this time.
0 commit comments