PHPackages                             marktic/settings - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. marktic/settings

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

marktic/settings
================

Multi-tenant settings management package

029↓50%PHP

Since Feb 25Pushed 2mo agoCompare

[ Source](https://github.com/marktic/settings)[ Packagist](https://packagist.org/packages/marktic/settings)[ RSS](/packages/marktic-settings/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (3)Used By (0)

Marktic Settings
================

[](#marktic-settings)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ddde30da8408c71f068cf633484f0fbae77aed17a1590a85097a88d67c3326b3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d61726b7469632f73657474696e67732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/marktic/settings)[![Tests](https://camo.githubusercontent.com/98ad850f344b96308a28759045733109cf3dd1e63929c0cf0f78a9d47a8481d7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d61726b7469632f73657474696e67732f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/marktic/settings/actions/workflows/run-tests.yml)[![License](https://camo.githubusercontent.com/f9a8f5f817d640567fb13956c859085900e64e00b0af900c2ddc90360bc90c4c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d61726b7469632f73657474696e67732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/marktic/settings)

A multi-tenant settings management package for PHP 8.2+ applications. Supports typed values (string, JSON, integer, float, boolean), grouped settings, tenant-scoped configuration, and multiple storage adapters (database, cache file).

Features
--------

[](#features)

- **Typed settings**: PHP property types (`string`, `bool`, `int`, `float`, `array`) automatically determine the cast — no manual configuration needed
- **Class-based settings**: Define settings as plain PHP classes extending `AbstractSettings`; properties with default values are automatically used as fallbacks
- **Grouped settings**: Each settings class declares its group via `group()`
- **Multi-tenant support**: Scope settings to any tenant by passing a tenant record to `SettingsManager::get()`
- **Instance caching**: `SettingsManager::get()` always returns the same object for the same class+tenant combination
- **Multiple storages**: Persist settings to a relational database (`DatabaseStorage`) or a JSON cache file (`FileStorage`)
- **Mapper**: `SettingMapper` handles low-level conversion between `SettingDto` and database/array representations
- **Trait-based integration**: Use `HasSettingsRecordTrait` to add per-model setting capabilities
- **Timestamps**: Every stored setting entry tracks `created_at` and `updated_at`

Installation
------------

[](#installation)

```
composer require marktic/settings
```

Register the service provider (if not using auto-discovery):

```
// config/app.php (Laravel)
'providers' => [
    Marktic\Settings\MktSettingsServiceProvider::class,
],
```

Run migrations:

```
php artisan migrate
```

Usage
-----

[](#usage)

### Defining a Settings Class

[](#defining-a-settings-class)

```
use Marktic\Settings\AbstractSettings;

class GeneralSettings extends AbstractSettings
{
    // PHP property types determine the storage cast automatically:
    // string → SettingType::String
    // bool   → SettingType::Boolean
    // int    → SettingType::Integer
    // float  → SettingType::Float
    // array  → SettingType::Json (stored as JSON)

    public string $site_name = 'My App';

    public bool $site_active = true;

    public int $max_items = 20;

    public float $tax_rate = 0.2;

    public array $supported_locales = ['en'];

    // Determines the group used in storage
    public static function group(): string
    {
        return 'general';
    }

    // Returns the named storage to use, or null for the package default
    public static function repository(): ?string
    {
        return null;
    }
}
```

### Setting up the SettingsManager

[](#setting-up-the-settingsmanager)

```
use Marktic\Settings\Hydrator\SettingsHydrator;use Marktic\Settings\Mapper\SettingMapper;use Marktic\Settings\MktSettingsManager;use Marktic\Settings\Storages\FileStorage;use Marktic\Settings\Utility\MktSettingsModels;

// Database storage (requires bytic/orm set up)
$storage = MktSettingsModels::createDatabaseStorage();

// File storage (no database required)
$storage = new FileStorage('/path/to/settings.json', new SettingMapper());

$manager = new MktSettingsManager($storage, new SettingsHydrator());

// Register optional named storages referenced by repository()
$manager->addStorage('file', new FileStorage('/path/to/file.json', new SettingMapper()));
```

### Retrieving and Saving Settings

[](#retrieving-and-saving-settings)

```
// Get hydrated settings (default values are used if nothing is stored yet)
$settings = $manager->get(GeneralSettings::class);
echo $settings->site_name; // "My App"

// Repeated calls return the SAME object instance
$settings1 = $manager->get(GeneralSettings::class);
$settings2 = $manager->get(GeneralSettings::class);
var_dump($settings1 === $settings2); // true

// Modify and save
$settings->site_name = 'New Name';
$settings->max_items = 50;
$manager->save($settings);
```

### Tenant-Scoped Settings

[](#tenant-scoped-settings)

```
use Marktic\Settings\SettingsTenantInterface;

// Your model can implement SettingsTenantInterface
class Organization implements SettingsTenantInterface
{
    public function getSettingTenantType(): string
    {
        return static::class;
    }

    public function getSettingTenantId(): string|int|null
    {
        return $this->id;
    }
}

$org = Organization::find(42);

// Each tenant gets its own isolated instance and storage scope
$tenantSettings = $manager->get(GeneralSettings::class, $org);
$tenantSettings->site_name = 'Org Site';

$manager->save($tenantSettings);

// Another tenant is isolated
$otherOrg = Organization::find(99);
$otherSettings = $manager->get(GeneralSettings::class, $otherOrg);
echo $otherSettings->site_name; // "My App" (its own defaults)
```

### Low-level: Using Storages Directly

[](#low-level-using-storages-directly)

```
use Marktic\Settings\Mapper\SettingMapper;use Marktic\Settings\Settings\Dto\SettingDto;use Marktic\Settings\Settings\Enums\SettingType;use Marktic\Settings\Storages\FileStorage;

$storage = new FileStorage('/path/to/settings.json', new SettingMapper());

$dto = new SettingDto();
$dto->name = 'site.title';
$dto->group = 'general';
$dto->type = SettingType::String;
$dto->setValue('My Application');

$storage->save($dto);

$found = $storage->find('site.title', 'general');
echo $found->getCastValue(); // "My Application"
```

Database Schema
---------------

[](#database-schema)

Table: `mkt_settings`

ColumnTypeDescription`id``BIGINT UNSIGNED`Primary key`name``VARCHAR(191)`Setting name/key`group``VARCHAR(100)`Logical group, default: `"default"``value``TEXT`Raw stored value`type``VARCHAR(20)`Value type: `string`, `json`, `integer`, `float`, `boolean``tenant_type``VARCHAR(191)`Tenant class/type (nullable)`tenant_id``BIGINT UNSIGNED`Tenant identifier (nullable)`created_at``DATETIME`Creation timestamp`updated_at``DATETIME`Last update timestampA unique index on `(name, group, tenant_type, tenant_id)` ensures no duplicate settings per scope.

Architecture
------------

[](#architecture)

```
src/
├── AbstractSettings.php     # Base class for user-defined settings (extend this)
├── SettingsManager.php      # Manager: get(class, tenant?) with caching + save()
├── SettingsTenantInterface.php  # Interface for tenant objects
├── Settings/
│   ├── Models/              # ORM Record (Setting) + RecordManager (Settings)
│   ├── Dto/                 # SettingDto — low-level value object
│   ├── Enums/               # SettingType — typed enum with cast/encode
│   ├── Mapper/              # SettingMapper — DTO ↔ DB / array conversion
│   ├── Hydrator/            # SettingsHydrator — reflection-based property mapping
│   └── Storages/            # SettingStorageInterface, DatabaseStorage, FileStorage
├── AbstractBase/            # Base Record and Repository classes
├── ModelsRelated/           # Cross-cutting HasSettings traits
├── Utility/                 # SettingsModels (ModelFinder), PackageConfig
└── SettingsServiceProvider.php

```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

See [CHANGELOG.md](CHANGELOG.md) for recent changes.

License
-------

[](#license)

The MIT License (MIT). See [LICENSE](LICENSE).

---

Inspiration
-----------

[](#inspiration)

This package was inspired by and takes ideas from the following open-source projects:

- **[spatie/laravel-settings](https://github.com/spatie/laravel-settings)** — DTO-based settings with casts, migrations support, and per-repository design.
- **[akaunting/laravel-setting](https://github.com/akaunting/laravel-setting)** — Simple key-value settings with driver-based persistence.
- **[phemellc/yii2-settings](https://github.com/phemellc/yii2-settings)** — Group-based settings with ActiveRecord integration for Yii2.
- **[jbtronics/settings-bundle](https://github.com/jbtronics/settings-bundle)** — Attribute-driven settings with storage adapters and Symfony DI integration.
- **[ScriptingBeating/laravel-global-settings](https://github.com/ScriptingBeating/laravel-global-settings)** — Global application settings with a simple API.
- **[appstract/laravel-options](https://github.com/appstract/laravel-options)** — Fluent options/settings stored in the database.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance56

Moderate activity, may be stable

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity15

Early-stage or recently created project

 Bus Factor1

Top contributor holds 58.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/bee4d69e72d2a9819fbbb63e3d81c904273f04bbcce9e0105c0f40fba73ef73d?d=identicon)[gabrielsolomon](/maintainers/gabrielsolomon)

---

Top Contributors

[![gabrielsolomon](https://avatars.githubusercontent.com/u/17990591?v=4)](https://github.com/gabrielsolomon "gabrielsolomon (14 commits)")[![Copilot](https://avatars.githubusercontent.com/in/1143301?v=4)](https://github.com/Copilot "Copilot (10 commits)")

### Embed Badge

![Health badge](/badges/marktic-settings/health.svg)

```
[![Health](https://phpackages.com/badges/marktic-settings/health.svg)](https://phpackages.com/packages/marktic-settings)
```

###  Alternatives

[abbotton/ios-png-parser

A PHP-based tool for parsing IOS application icons in IPA files

2015.4k1](/packages/abbotton-ios-png-parser)[daodao97/hyperf-watch

hyperf develop hot reload

226.6k2](/packages/daodao97-hyperf-watch)[headsnet/money-bundle

Integrates moneyphp/money into your Symfony application

1116.2k](/packages/headsnet-money-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
