"Fossies" - the Fresh Open Source Software Archive

Member "framework-8.65.0/src/Illuminate/Database/Eloquent/Casts/AsEncryptedArrayObject.php" (19 Oct 2021, 1089 Bytes) of package /linux/www/laravel-framework-8.65.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "AsEncryptedArrayObject.php" see the Fossies "Dox" file reference documentation.

    1 <?php
    2 
    3 namespace Illuminate\Database\Eloquent\Casts;
    4 
    5 use Illuminate\Contracts\Database\Eloquent\Castable;
    6 use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
    7 use Illuminate\Support\Facades\Crypt;
    8 
    9 class AsEncryptedArrayObject implements Castable
   10 {
   11     /**
   12      * Get the caster class to use when casting from / to this cast target.
   13      *
   14      * @param  array  $arguments
   15      * @return object|string
   16      */
   17     public static function castUsing(array $arguments)
   18     {
   19         return new class implements CastsAttributes
   20         {
   21             public function get($model, $key, $value, $attributes)
   22             {
   23                 return new ArrayObject(json_decode(Crypt::decryptString($attributes[$key]), true));
   24             }
   25 
   26             public function set($model, $key, $value, $attributes)
   27             {
   28                 return [$key => Crypt::encryptString(json_encode($value))];
   29             }
   30 
   31             public function serialize($model, string $key, $value, array $attributes)
   32             {
   33                 return $value->getArrayCopy();
   34             }
   35         };
   36     }
   37 }