diff options
| author | Sam Light <samlight1994@gmail.com> | 2024-06-16 21:38:06 +0100 | 
|---|---|---|
| committer | Sam Light <samlight1994@gmail.com> | 2024-06-16 21:38:06 +0100 | 
| commit | 75b5f823043990ef9ddd4a120d420552fd00f0c5 (patch) | |
| tree | f0fc43c23e7d035e029f1f8c1482d60d475ca733 /src/SvgCollection.php | |
| parent | 53a18d36f6fef9dc5e24e3efea88d3a50c95e22c (diff) | |
Create a version hash and add to svg url
Diffstat (limited to 'src/SvgCollection.php')
| -rw-r--r-- | src/SvgCollection.php | 18 | 
1 files changed, 16 insertions, 2 deletions
diff --git a/src/SvgCollection.php b/src/SvgCollection.php index 63d7508..fdf0664 100644 --- a/src/SvgCollection.php +++ b/src/SvgCollection.php @@ -27,8 +27,13 @@ class SvgCollection      public function getSvgUrl(string $svg): string      { -        $this->getState()->addSvg($svg); -        return route('laralight-svg.serve-svg', $this->getName()) . "#{$svg}"; +        $state = $this->getState(); +        $state->addSvg($svg); +        $hash = $state->getHash(); +        return route( +            'laralight-svg.serve-svg', +            ['collection' => $this->getName(), 'v' => $hash] +        ) . "#{$svg}";      }      protected function getState(): SvgCollectionState @@ -70,11 +75,15 @@ class SvgCollection              if ($file !== null && $compiler->addSvg($pendingSvg, $file)) {                  $added[] = $pendingSvg;              } +            else { +                \Log::error("Failed to add {$pendingSvg} to svg sprite"); +            }          }          $state->clearPending(false);          $state->concatExisting($added, false);          $state->setFullSvg($compiler->getSvg(), false); +        $state->updateHash();          $state->push();      } @@ -87,4 +96,9 @@ class SvgCollection          return null;      } +    public function clearState(): void +    { +        $this->getState()->clear(); +    } +  }  | 
