Download the PHP package nhwin/settings without Composer

On this page you can find all versions of the php package nhwin/settings. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package settings

Nhwin Settings

Gói quản lý cấu hình động cho Laravel, lưu dữ liệu theo scope + group + key dưới dạng JSON, có cache theo nhóm và tích hợp tùy chọn với Filament.

Tương thích

Constraint phát hành:

Thành phần Phiên bản hỗ trợ
PHP 8.3+
Laravel 11.28+, 12.x hoặc 13.x
Filament 4.x hoặc 5.x
Livewire 3.x với Filament 4; 4.x với Filament 5

Các tổ hợp đã được chạy đầy đủ tại máy phát triển:

PHP Laravel Filament Livewire Kết quả
8.3.6 11.39.1 4.0.0 3.5.0 prefer-lowest, Composer, Pint, PHPStan và Pest đều đạt
8.3.6 11.39.1 5.0.0 4.1.0 prefer-lowest, Composer, Pint, PHPStan và Pest đều đạt
8.3.6 12.64.0 4.12.1 3.8.2 Composer, Pint, PHPStan và Pest đều đạt
8.3.6 12.64.0 5.7.1 4.3.3 Composer, Pint, PHPStan và Pest đều đạt
8.3.6 13.21.1 4.12.1 3.8.2 Composer, Pint, PHPStan và Pest đều đạt
8.3.6 13.21.1 5.7.1 4.3.3 Composer, Pint, PHPStan và Pest đều đạt

Constraint Composer cho phép PHP 8.3 trở lên. Workflow CI hiện cấu hình PHP 8.3/8.4; chỉ các tổ hợp liệt kê trong bảng trên mới được xác minh đầy đủ tại máy phát triển. Workflow còn có các job prefer-lowest riêng cho lower bound Laravel 11.28 với Filament 4/5. Không cần khai báo trực tiếp Livewire trong ứng dụng; Filament sẽ chọn major phù hợp.

Cài đặt

Xuất config và migration, sau đó chạy migration:

Hoặc dùng lệnh cài đặt của package:

Tên bảng mặc định là settings. Có thể đổi table_name trong config/settings.php trước khi migrate.

Đọc và ghi cơ bản

Helper cũ được giữ nguyên:

Facade cũng giữ toàn bộ API cũ:

Trong Blade, directive sẽ escape HTML giống {{ }}:

Gọi settings() không truyền khóa để lấy manager:

Dữ liệu lồng nhau

Phần đầu là group, phần thứ hai là root key, các phần còn lại là đường dẫn lồng nhau:

Giá trị null đã lưu sẽ trả về null; default chỉ được dùng khi đường dẫn không tồn tại.

Database repository mặc định thực hiện nested read-modify-write trong transaction và khóa root row, nên sibling mutations dựa trên state committed mới nhất. Custom repository chỉ implement SettingsRepository vẫn tương thích và dùng fallback cũ; implement thêm AtomicSettingsRepository để cung cấp cùng bảo đảm concurrency.

Ghi hàng loạt

setMany() thực hiện một transaction, một lần upsert() cho cả group và một lần xóa cache sau commit:

Trang Filament cũng dùng API này, không gọi set() lặp lại cho từng field.

Cache

Cache được lưu theo toàn bộ group với khóa:

Cấu hình trong config/settings.php:

ttl tính theo phút. null hoặc 0 nghĩa là cache vĩnh viễn. Cache chỉ bị vô hiệu hóa sau khi transaction ghi DB commit thành công; rollback không làm lộ dữ liệu dở dang.

Getter kiểm tra kiểu

Nếu kiểu đã lưu không đúng, package ném Nhwin\Settings\Exceptions\InvalidSettingType và không đưa giá trị nhạy cảm vào thông báo lỗi.

float() nhận số JSON kiểu integer hoặc float rồi luôn trả về float; chuỗi số như "5.5" bị từ chối. Boolean cast trong definition nhận true, false, 1, 0 và các chuỗi không phân biệt hoa thường "1", "0", "true", "false", "yes", "no", "on", "off"; giá trị mơ hồ bị từ chối.

Definition tùy chọn

Definition casts chuẩn hóa và kiểm tra kiểu của giá trị group đã lưu: string chỉ nhận string, integer chỉ nhận int, float nhận int/float rồi trả float, boolean dùng tập biểu diễn rõ ràng, và array chỉ nhận array. Typed getters kiểm tra kiểu tại thời điểm application code yêu cầu một kiểu cụ thể; chúng không thay thế definition normalization.

Settings động vẫn là mặc định. Khi cần default, cast và danh sách mã hóa, tạo definition:

Đăng ký trong config/settings.php:

Mã hóa secret

Mã hóa một giá trị cụ thể bằng Laravel Encrypter:

DB chỉ chứa ciphertext. Với path được khai báo trong SettingsDefinition::encrypted():

Form Filament được fill bằng giá trị trống thay vì plaintext secret; password field do generator tạo chỉ dehydrate khi có input mới. Payload hỏng sẽ ném DecryptException; events và audit entries thay đệ quy từng secret bằng [encrypted] nhưng vẫn giữ các sibling không nhạy cảm.

Tạo trang Filament

Lệnh tối thiểu:

Các tùy chọn:

Page sinh ra tương thích Filament 4/5 và kế thừa AbstractPageSettings. Base page hỗ trợ beforeFill, afterFill, beforeValidate, afterValidate, beforeSave, afterSave, afterCommit, hai hook mutate, transaction, unsaved-change alert và phím Ctrl/Cmd + S. afterSave chạy bên trong transaction; afterCommit chạy sau commit và có thể đọc state đã commit.

Settings Hub

Internal pages passed to pages() or SettingsPageDefinition::make() must extend AbstractPageSettings, so plugin, definition, and direct-route authorization are always applied. Use SettingsPageDefinition::external() for destinations whose authorization is managed elsewhere.

Đăng ký plugin trong Panel Provider:

Có thể khai báo metadata thủ công:

Đích ngoài Filament cũng được hỗ trợ:

Class cũ SettingPlugin vẫn hoạt động nhưng đã deprecated; nên chuyển sang SettingsPlugin.

Quyền truy cập và nhiều panel

Không bắt buộc Filament Shield:

Quyền cuối cùng là giao của ba lớp: callback plugin, callback trên SettingsPageDefinition, và hook native của page. Khi một definition trả về false, card trong Hub và navigation bị ẩn, đồng thời direct route bị chặn qua AbstractPageSettings::canAccess().

Để thêm rule riêng cho page mà vẫn giữ toàn bộ lớp bảo vệ, override hook sau thay vì thay thế canAccess():

Mỗi panel phải có plugin instance riêng; registry không rò cấu hình giữa panel:

Scope và multi-tenancy

Scope mặc định là global:

Không hard-code tenant_id. Có thể thay resolver:

Manager dùng scoped container binding và resolve default scope lười ở từng operation. Vì vậy cùng một Octane/Swoole/RoadRunner worker có thể chuyển tenant giữa các request mà không giữ scope cũ. forScope() luôn trả clone có explicit scope và không mutate manager mặc định.

Xóa setting

Xóa nested chỉ bỏ đúng path và giữ sibling; root row được xóa khi cấu trúc còn lại rỗng. Xóa luôn chạy trong transaction, phân tách theo scope và chỉ invalidate cache/phát event sau commit thành công.

Events

Sau commit thành công, package phát:

Event chứa scope, group, key thay đổi và old/new value an toàn. Hãy xử lý việc reload mail config, xóa theme cache hoặc tạo sitemap trong listener của ứng dụng, không đặt side effect vào core package.

Các identifier scope, group và root key phải khác rỗng, không chứa control character và tối đa 255 ký tự để khớp các cột string hiện tại; group/root key không nhận dấu chấm vì dấu chấm dành cho phân tách setting path. Mỗi nested segment có cùng giới hạn và toàn bộ setting key tối đa 1024 ký tự.

Audit trail là tùy chọn và không thêm cột vào bảng settings. Mặc định Nhwin\Settings\Contracts\SettingsAuditRecorder được bind vào recorder no-op. Ứng dụng có thể bind contract này vào implementation riêng để nhận SettingsAuditEntry; actor mặc định là null và có thể được bổ sung bởi recorder của ứng dụng. settings.audit.granularity nhận setting (mặc định, tránh record trùng khi bulk update), group hoặc both. Mọi secret trong entry vẫn được redact.

Nâng cấp từ phiên bản cũ

  1. Dùng PHP 8.3+ và chọn Laravel 11/12/13 tương thích.
  2. Chạy composer update nhwin/settings filament/filament --with-all-dependencies.
  3. Publish migration mới và chạy php artisan migrate. Migration thêm scope = global cho dữ liệu hiện hữu và đổi unique key thành (scope, group, key).
  4. Không cần đổi settings(), facade Setting, @settings, getGroup() hoặc getGroupLastUpdatedAt().
  5. Page cũ chỉ cần sửa import sai lịch sử thành Nhwin\Settings\Abstracts\AbstractPageSettings nếu từng được sinh bởi bản lỗi.
  6. Đổi Nhwin\Settings\Filament\Plugins\SettingPlugin sang SettingsPlugin khi thuận tiện.
  7. Kiểm tra mọi code từng dựa vào hành vi nested set cũ; nested set nay chỉ cập nhật đúng nhánh và giữ sibling.

Phát triển và kiểm thử

CI được cấu hình cho ma trận PHP 8.3/8.4, Laravel 11/12/13 và Filament 4/5. Filament 5 được ghép với Livewire 4.1+ trong job tương ứng. Cấu hình workflow không được xem là bằng chứng một tổ hợp đã pass nếu chưa có lần chạy thành công.

Giấy phép

MIT. Xem LICENSE.


All versions of settings with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
laravel/framework Version ^11.28|^12.0|^13.0
filament/filament Version ^4.0|^5.0
spatie/laravel-package-tools Version ^1.92
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package nhwin/settings contains the following files

Loading the files please wait ...