-
Notifications
You must be signed in to change notification settings - Fork 11k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
90 changed files
with
1,066 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace Illuminate\Database\Eloquent\Casts; | ||
|
||
use ArrayObject as BaseArrayObject; | ||
use Illuminate\Contracts\Support\Arrayable; | ||
use JsonSerializable; | ||
|
||
class ArrayObject extends BaseArrayObject implements Arrayable, JsonSerializable | ||
{ | ||
/** | ||
* Get a collection containing the underlying array. | ||
* | ||
* @return \Illuminate\Support\Collection | ||
*/ | ||
public function collect() | ||
{ | ||
return collect($this->getArrayCopy()); | ||
} | ||
|
||
/** | ||
* Get the instance as an array. | ||
* | ||
* @return array | ||
*/ | ||
public function toArray() | ||
{ | ||
return $this->getArrayCopy(); | ||
} | ||
|
||
/** | ||
* Get the array that should be JSON serialized. | ||
* | ||
* @return array | ||
*/ | ||
public function jsonSerialize() | ||
{ | ||
return $this->getArrayCopy(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Illuminate\Database\Eloquent\Casts; | ||
|
||
use Illuminate\Contracts\Database\Eloquent\Castable; | ||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes; | ||
|
||
class AsArrayObject implements Castable | ||
{ | ||
/** | ||
* Get the caster class to use when casting from / to this cast target. | ||
* | ||
* @param array $arguments | ||
* @return object|string | ||
*/ | ||
public static function castUsing(array $arguments) | ||
{ | ||
return new class implements CastsAttributes { | ||
public function get($model, $key, $value, $attributes) | ||
{ | ||
return new ArrayObject(json_decode($attributes[$key], true)); | ||
} | ||
|
||
public function set($model, $key, $value, $attributes) | ||
{ | ||
return [$key => json_encode($value)]; | ||
} | ||
|
||
public function serialize($model, string $key, $value, array $attributes) | ||
{ | ||
return $value->getArrayCopy(); | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Illuminate\Database\Eloquent\Casts; | ||
|
||
use Illuminate\Contracts\Database\Eloquent\Castable; | ||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes; | ||
use Illuminate\Support\Collection; | ||
|
||
class AsCollection implements Castable | ||
{ | ||
/** | ||
* Get the caster class to use when casting from / to this cast target. | ||
* | ||
* @param array $arguments | ||
* @return object|string | ||
*/ | ||
public static function castUsing(array $arguments) | ||
{ | ||
return new class implements CastsAttributes { | ||
public function get($model, $key, $value, $attributes) | ||
{ | ||
return new Collection(json_decode($attributes[$key], true)); | ||
} | ||
|
||
public function set($model, $key, $value, $attributes) | ||
{ | ||
return [$key => json_encode($value)]; | ||
} | ||
}; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/Illuminate/Database/Eloquent/Casts/AsEncryptedArrayObject.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Illuminate\Database\Eloquent\Casts; | ||
|
||
use Illuminate\Contracts\Database\Eloquent\Castable; | ||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes; | ||
use Illuminate\Support\Facades\Crypt; | ||
|
||
class AsEncryptedArrayObject implements Castable | ||
{ | ||
/** | ||
* Get the caster class to use when casting from / to this cast target. | ||
* | ||
* @param array $arguments | ||
* @return object|string | ||
*/ | ||
public static function castUsing(array $arguments) | ||
{ | ||
return new class implements CastsAttributes { | ||
public function get($model, $key, $value, $attributes) | ||
{ | ||
return new ArrayObject(json_decode(Crypt::decryptString($attributes[$key]), true)); | ||
} | ||
|
||
public function set($model, $key, $value, $attributes) | ||
{ | ||
return [$key => Crypt::encryptString(json_encode($value))]; | ||
} | ||
|
||
public function serialize($model, string $key, $value, array $attributes) | ||
{ | ||
return $value->getArrayCopy(); | ||
} | ||
}; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/Illuminate/Database/Eloquent/Casts/AsEncryptedCollection.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace Illuminate\Database\Eloquent\Casts; | ||
|
||
use Illuminate\Contracts\Database\Eloquent\Castable; | ||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes; | ||
use Illuminate\Support\Collection; | ||
use Illuminate\Support\Facades\Crypt; | ||
|
||
class AsEncryptedCollection implements Castable | ||
{ | ||
/** | ||
* Get the caster class to use when casting from / to this cast target. | ||
* | ||
* @param array $arguments | ||
* @return object|string | ||
*/ | ||
public static function castUsing(array $arguments) | ||
{ | ||
return new class implements CastsAttributes { | ||
public function get($model, $key, $value, $attributes) | ||
{ | ||
return new Collection(json_decode(Crypt::decryptString($attributes[$key]), true)); | ||
} | ||
|
||
public function set($model, $key, $value, $attributes) | ||
{ | ||
return [$key => Crypt::encryptString(json_encode($value))]; | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.