From c4e645d6c29884b6cb0c75775ea21380befe8c75 Mon Sep 17 00:00:00 2001 From: Zach DeCook Date: Sat, 27 Aug 2022 13:28:18 +0000 Subject: validation: use bible passage parser to validate verse references --- laravel/app/Song.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'laravel/app/Song.php') diff --git a/laravel/app/Song.php b/laravel/app/Song.php index a6cb0c0..0f7248a 100644 --- a/laravel/app/Song.php +++ b/laravel/app/Song.php @@ -4,6 +4,7 @@ namespace App; use Illuminate\Database\Eloquent\Model; use App\Http\Controllers\SongController; +use TechWilk\BibleVerseParser\BiblePassageParser; class Song extends Model { @@ -34,7 +35,7 @@ class Song extends Model public function setKeyAttribute($value) { - if (!$value) return; + if (!$value) return $this->attributes['key'] = null; if ($value[0]>="A"&&$value[0]<="G"){ $this->attributes['key'] = $value; } else { @@ -65,6 +66,15 @@ class Song extends Model file_put_contents("public/text/{$this->id}.txt", $text); } } + + public function setVerseAttribute($text) + { + if (!$text) return $this->attributes['verse'] = null; + $parser = new BiblePassageParser(); + // Can throw an exception. + return $this->attributes['verse'] = implode("; ", $parser->parse($text)); + } + public function getChordsAttribute($txt = null) { $txt = $txt ?? $this->text; -- cgit 1.4.1