Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Oct 10, 2024
1 parent acd5e18 commit 1fe87f7
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 39 deletions.
42 changes: 42 additions & 0 deletions src/Casts/SettingValue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Cone\Root\Casts;

use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
use Illuminate\Database\Eloquent\Model;

class SettingValue implements CastsAttributes
{
/**
* The setting key.
*/
protected string $key;

/**
* Create a new controller instance.
*/
public function __construct(string $key)
{
$this->key = $key;
}

/**
* Cast the given value.
*
* @param array<string, mixed> $attributes
*/
public function get(Model $model, string $key, mixed $value, array $attributes): mixed
{
return $value;
}

/**
* Prepare the given value for storage.
*
* @param array<string, mixed> $attributes
*/
public function set(Model $model, string $key, mixed $value, array $attributes): mixed
{
return $value;
}
}
11 changes: 11 additions & 0 deletions src/Models/Setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Cone\Root\Models;

use Cone\Root\Casts\SettingValue;
use Cone\Root\Database\Factories\SettingFactory;
use Cone\Root\Interfaces\Models\Setting as Contract;
use Cone\Root\Traits\InteractsWithProxy;
Expand Down Expand Up @@ -45,4 +46,14 @@ protected static function newFactory(): SettingFactory
{
return SettingFactory::new();
}

/**
* Get the attributes that should be cast.
*/
protected function casts(): array
{
return [
'value' => SettingValue::class.':'.$this->key,
];
}
}
30 changes: 0 additions & 30 deletions src/Settings/Group.php

This file was deleted.

5 changes: 0 additions & 5 deletions src/Settings/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ class Registry implements Contract
*/
protected Repository $repository;

/**
* The settings groups.
*/
protected array $groups = [];

/**
* Create a new registry instance.
*/
Expand Down
29 changes: 25 additions & 4 deletions src/Settings/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,39 @@
namespace Cone\Root\Settings;

use Cone\Root\Interfaces\Settings\Repository as Contract;
use Cone\Root\Models\Setting;

class Repository implements Contract
{
protected array $cache = [];
protected array $casts = [];

public function __construct()
{
//
}

// get
// set
// delete
public function model(): Setting
{
return Setting::proxy();
}

public function get()
{
//
}

public function set()
{
//
}

public function delete()
{
//
}

public function cast(string $key, string $type)
{
//
}
}

0 comments on commit 1fe87f7

Please sign in to comment.