Skip to content

Commit

Permalink
Update FileEditor.php
Browse files Browse the repository at this point in the history
  • Loading branch information
GIGABAIT93 committed Feb 15, 2023
1 parent db60bbd commit 92de8e0
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/FileEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,16 @@ public function closeFile()

public function appendAfterWord($word, $text)
{
$contents = file_get_contents($this->filename);
$position = strpos($contents, $word);
if ($position !== false) {
$start = substr($contents, 0, $position + strlen($word));
$end = substr($contents, $position + strlen($word));
file_put_contents($this->filename, $start . "\n" . $text . "\n" . $end);
if (file_exists($this->filename)) {
$contents = file_get_contents($this->filename);
$position = strpos($contents, $word);
if ($position !== false) {
$start = substr($contents, 0, $position + strlen($word));
$end = substr($contents, $position + strlen($word));
file_put_contents($this->filename, $start . "\n" . $text . "\n" . $end);
}
}

}

public function issetText($text)
Expand All @@ -53,6 +56,7 @@ public function issetText($text)

public static function appendAfter($file, $word, $text)
{
if (file_exists($file)) {
$contents = file_get_contents($file);
$isset = strpos($contents, $text) !== false;
if (!$isset) {
Expand All @@ -63,5 +67,6 @@ public static function appendAfter($file, $word, $text)
file_put_contents($file, $start . "\n" . $text . "\n" . $end);
}
}
}
}
}
}

0 comments on commit 92de8e0

Please sign in to comment.