Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] Rename CastsAttributes contract methods #31075

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface CastsAttributes
* @param array $attributes
* @return mixed
*/
public function get($model, string $key, $value, array $attributes);
public function fromDatabase($model, string $key, $value, array $attributes);

/**
* Transform the attribute to its underlying model values.
Expand All @@ -24,5 +24,5 @@ public function get($model, string $key, $value, array $attributes);
* @param array $attributes
* @return array
*/
public function set($model, string $key, $value, array $attributes);
public function toDatabase($model, string $key, $value, array $attributes);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ interface CastsInboundAttributes
* @param array $attributes
* @return array
*/
public function set($model, string $key, $value, array $attributes);
public function toDatabase($model, string $key, $value, array $attributes);
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,46 +133,46 @@ public function __construct($algorithm = 'sha256')
$this->algorithm = $algorithm;
}

public function set($model, $key, $value, $attributes)
public function toDatabase($model, $key, $value, $attributes)
{
return [$key => hash($this->algorithm, $value)];
}
}

class ReverseCaster implements CastsAttributes
{
public function get($model, $key, $value, $attributes)
public function fromDatabase($model, $key, $value, $attributes)
{
return strrev($value);
}

public function set($model, $key, $value, $attributes)
public function toDatabase($model, $key, $value, $attributes)
{
return [$key => strrev($value)];
}
}

class AddressCaster implements CastsAttributes
{
public function get($model, $key, $value, $attributes)
public function fromDatabase($model, $key, $value, $attributes)
{
return new Address($attributes['address_line_one'], $attributes['address_line_two']);
}

public function set($model, $key, $value, $attributes)
public function toDatabase($model, $key, $value, $attributes)
{
return ['address_line_one' => $value->lineOne, 'address_line_two' => $value->lineTwo];
}
}

class JsonCaster implements CastsAttributes
{
public function get($model, $key, $value, $attributes)
public function fromDatabase($model, $key, $value, $attributes)
{
return json_decode($value, true);
}

public function set($model, $key, $value, $attributes)
public function toDatabase($model, $key, $value, $attributes)
{
return json_encode($value);
}
Expand Down