Subversion-Projekte lars-tiefland.laravel_shop

Revision

Zur aktuellen Revision | Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 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
                if (isset($attributes[$key])) {
24
                    return new ArrayObject(json_decode(Crypt::decryptString($attributes[$key]), true));
25
                }
26
 
27
                return null;
28
            }
29
 
30
            public function set($model, $key, $value, $attributes)
31
            {
32
                if (! is_null($value)) {
33
                    return [$key => Crypt::encryptString(json_encode($value))];
34
                }
35
 
36
                return null;
37
            }
38
 
39
            public function serialize($model, string $key, $value, array $attributes)
40
            {
41
                return ! is_null($value) ? $value->getArrayCopy() : null;
42
            }
43
        };
44
    }
45
}