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

Add MLL\LaravelUtils\Casts\Coordinates96Well from mll-lab/microplate #14

Merged
merged 2 commits into from
Apr 24, 2024
Merged
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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ See [GitHub releases](https://github.com/mll-lab/laravel-utils/releases).

## Unreleased

## v5.0.0

### Added

- Add `MLL\LaravelUtils\Casts\Coordinates96Well` from `mll-lab/microplate`

### Changed

- Require `mll-lab/php-utils`

## v4.12.1

### Changed
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"require": {
"php": "^8.1",
"illuminate/support": "^9.51 || ^10 || ^11",
"mll-lab/php-utils": "^1.13",
"mll-lab/str_putcsv": "^1",
"ramsey/uuid": "^4.7",
"thecodingmachine/safe": "^1 || ^2"
Expand Down
38 changes: 38 additions & 0 deletions src/Casts/Coordinates96Well.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php declare(strict_types=1);

namespace MLL\LaravelUtils\Casts;

use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
use Illuminate\Database\Eloquent\Model;
use MLL\Utils\Microplate\Coordinates;
use MLL\Utils\Microplate\CoordinateSystem96Well;

/** @implements CastsAttributes<Coordinates<CoordinateSystem96Well>, Coordinates<CoordinateSystem96Well>> */
class Coordinates96Well implements CastsAttributes
{
/**
* @param Model $model
* @param string $key
* @param array<array-key, mixed> $attributes
*
* @return Coordinates<CoordinateSystem96Well>
*/
public function get($model, $key, $value, $attributes): Coordinates
{
assert(is_string($value));

return Coordinates::fromString($value, new CoordinateSystem96Well());
}

/**
* @param Model $model
* @param string $key
* @param array<array-key, mixed> $attributes
*/
public function set($model, $key, $value, $attributes): string
{
assert($value instanceof Coordinates);

return $value->toString();
}
}
Loading