src/Traits/ImageTrait.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Traits;
  3. trait ImageTrait {
  4.     public function pathFromImage(array $image null): string
  5.     {
  6.         if (is_null($image) or !is_array($image)) {
  7.             return '';
  8.         }
  9.         if (!array_key_exists('path'$image)) {
  10.             return '';
  11.         }
  12.         $path $image['path'];
  13.         if (is_null($path)) {
  14.             return '';
  15.         }
  16.         return $path;
  17.     }
  18.     public function altFromImage(array $image null): string
  19.     {
  20.         if (is_null($image) or !is_array($image)) {
  21.             return '';
  22.         }
  23.         if (!array_key_exists('alt'$image)) {
  24.             return '';
  25.         }
  26.         $path $image['alt'];
  27.         if (is_null($path)) {
  28.             return '';
  29.         }
  30.         return $path;
  31.     }
  32.     public function altFromPath($path)
  33.     {
  34.         if ($path === '') {
  35.             return $path;
  36.         }
  37.         $data explode('/'$path);
  38.         $filename end($data);
  39.         $dirname explode('.'$filename);
  40.         $dirname $dirname[0];
  41.         return str_replace('-'' '$dirname);
  42.     }
  43. }