Persistent user-specific settings for CodeIgniter 4

Overview

Tatter\Preferences

Persistent user-specific settings for CodeIgniter 4

Coverage Status

Quick Start

  1. Install with Composer: > composer require --dev tatter/preferences
  2. Load the helper: helper('preferences');
  3. Use the function to get and set: $theme = preference('theme'); preference('theme', 'dark');

Description

Preferences is a wrapper for CodeIgniter Settings to provide user context to each setting. This allows you to get and set preferences on a per-user basis with a single command.

Installation

Install easily via Composer to take advantage of CodeIgniter 4's autoloading capabilities and always be up-to-date:

  • > composer require tatter/preferences

Or, install manually by downloading the source files and adding the directory to app/Config/Autoload.php.

Once the files are downloaded and included in the autoload, run any library migrations to ensure the database is set up correctly:

  • > php spark migrate -all

Preferences suggests the Composer provision for codeigniter4/authentication-implementation as describe in the CodeIgniter authentication guidelines. Without this each preference will be limited to the session duration so it is highly recommended you install and configure a supported package.

Usage

Preferences requires CodeIgniter Settings so you may use all the same classes and functions described in its documentation as well. To access the user-specific context settings call the preference() function anywhere you would normally use setting():

class Home extends Controller
{
    public function index()
    {
        return view('welcome', [
            'icon' => preference('Users.avatar'),
        ];
    }

    public function update_avatar()
    {
        if ($icon = $this->request->getPost('icon')) {
            prefernece('Users.avatar', $icon);
        }

        return redirect()->back();
    }
}

Note: Be sure to load the helper file (helper('preferences')) before using the helper function.

preference() will retrieve and store contextual settings for the current authenticated user. If no user is authenticated then it will fall back on the Session class with semi-persistent settings for as long as the session lasts.

Placeholder Config

In most cases each setting should have a corresponding Config file. Sometimes these settings will not fit under an existing logical grouping, so this library provides a "placeholder" Config (Tatter\Preferences\Config\Preferences). You may add your own version in *app/ to supply default values:

<?php

namespace Config;

class Preferences extends \Tatter\Preferences\Config\Preferences
{
    /**
     * Slug for the current user theme.
     */
    public string $theme = 'midnight';
}

Any function calls with the class unspecified will reference the Preferences class:

// Identical calls:
$theme = preference('Preferences.theme');
$theme = preference('theme');

Hint: Don't forget that libraries and modules can provide Config properties via Registrars

Troubleshooting

Preferences is a very "thin" library conjoining Settings and your authentication library of choice. Most likely any issues are related to one of the underlying libraries and should be directed there, but if you believe there is a problem or a feature request appropriate to this repository then feel free to open an Issue or Pull Request.

Comments
  • Bump actions/cache from 2 to 3.0.1

    Bump actions/cache from 2 to 3.0.1

    Bumps actions/cache from 2 to 3.0.1.

    Release notes

    Sourced from actions/cache's releases.

    v3.0.1

    • Added support for caching from GHES 3.5.
    • Fixed download issue for files > 2GB during restore.

    v3.0.0

    • This change adds a minimum runner version(node12 -> node16), which can break users using an out-of-date/fork of the runner. This would be most commonly affecting users on GHES 3.3 or before, as those runners do not support node16 actions and they can use actions from github.com via github connect or manually copying the repo to their GHES instance.

    • Few dependencies and cache action usage examples have also been updated.

    v2.1.7

    Support 10GB cache upload using the latest version 1.0.8 of @actions/cache

    v2.1.6

    • Catch unhandled "bad file descriptor" errors that sometimes occurs when the cache server returns non-successful response (actions/cache#596)

    v2.1.5

    • Fix permissions error seen when extracting caches with GNU tar that were previously created using BSD tar (actions/cache#527)

    v2.1.4

    • Make caching more verbose #650
    • Use GNU tar on macOS if available #701

    v2.1.3

    • Upgrades @actions/core to v1.2.6 for CVE-2020-15228. This action was not using the affected methods.
    • Fix error handling in uploadChunk where 400-level errors were not being detected and handled correctly

    v2.1.2

    • Adds input to limit the chunk upload size, useful for self-hosted runners with slower upload speeds
    • No-op when executing on GHES

    v2.1.1

    • Update @actions/cache package to v1.0.2 which allows cache action to use posix format when taring files.

    v2.1.0

    • Replaces the http-client with the Azure Storage SDK for NodeJS when downloading cache content from Azure. This should help improve download performance and reliability as the SDK downloads files in 4 MB chunks, which can be parallelized and retried independently
    • Display download progress and speed
    Changelog

    Sourced from actions/cache's changelog.

    3.0.1

    • Added support for caching from GHES 3.5.
    • Fixed download issue for files > 2GB during restore.
    Commits
    • 136d96b Enabling actions/cache for GHES based on presence of AC service (#774)
    • 7d4f40b Bumping up the version to fix download issue for files > 2 GB. (#775)
    • 2d8d0d1 Updated what's new. (#771)
    • 7799d86 Updated the usage and docs to the major version release. (#770)
    • 4b0cf6c Merge pull request #769 from actions/users/ashwinsangem/bump_major_version
    • 60c606a Update licensed files
    • b6e9a91 Revert "Updated to the latest version."
    • c842503 Updated to the latest version.
    • 2b7da2a Bumped up to a major version.
    • deae296 Merge pull request #651 from magnetikonline/fix-golang-windows-example
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies github_actions 
    opened by dependabot[bot] 1
  • Bump actions/cache from 2 to 3

    Bump actions/cache from 2 to 3

    Bumps actions/cache from 2 to 3.

    Release notes

    Sourced from actions/cache's releases.

    v3.0.0

    • This change adds a minimum runner version(node12 -> node16), which can break users using an out-of-date/fork of the runner. This would be most commonly affecting users on GHES 3.3 or before, as those runners do not support node16 actions and they can use actions from github.com via github connect or manually copying the repo to their GHES instance.

    • Few dependencies and cache action usage examples have also been updated.

    v2.1.7

    Support 10GB cache upload using the latest version 1.0.8 of @actions/cache

    v2.1.6

    • Catch unhandled "bad file descriptor" errors that sometimes occurs when the cache server returns non-successful response (actions/cache#596)

    v2.1.5

    • Fix permissions error seen when extracting caches with GNU tar that were previously created using BSD tar (actions/cache#527)

    v2.1.4

    • Make caching more verbose #650
    • Use GNU tar on macOS if available #701

    v2.1.3

    • Upgrades @actions/core to v1.2.6 for CVE-2020-15228. This action was not using the affected methods.
    • Fix error handling in uploadChunk where 400-level errors were not being detected and handled correctly

    v2.1.2

    • Adds input to limit the chunk upload size, useful for self-hosted runners with slower upload speeds
    • No-op when executing on GHES

    v2.1.1

    • Update @actions/cache package to v1.0.2 which allows cache action to use posix format when taring files.

    v2.1.0

    • Replaces the http-client with the Azure Storage SDK for NodeJS when downloading cache content from Azure. This should help improve download performance and reliability as the SDK downloads files in 4 MB chunks, which can be parallelized and retried independently
    • Display download progress and speed
    Commits
    • 4b0cf6c Merge pull request #769 from actions/users/ashwinsangem/bump_major_version
    • 60c606a Update licensed files
    • b6e9a91 Revert "Updated to the latest version."
    • c842503 Updated to the latest version.
    • 2b7da2a Bumped up to a major version.
    • deae296 Merge pull request #651 from magnetikonline/fix-golang-windows-example
    • c7c46bc Merge pull request #707 from duxtland/main
    • 6535c5f Regenerated examples.md TOC
    • 3fdafa4 Update GitHub Actions status badge markdown in README.md
    • 341e6d7 Merge branch 'actions:main' into fix-golang-windows-example
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies github_actions 
    opened by dependabot[bot] 1
  • Bump actions/checkout from 2 to 3

    Bump actions/checkout from 2 to 3

    Bumps actions/checkout from 2 to 3.

    Release notes

    Sourced from actions/checkout's releases.

    v3.0.0

    • Update default runtime to node16

    v2.4.0

    • Convert SSH URLs like org-<ORG_ID>@github.com: to https://github.com/ - pr

    v2.3.5

    Update dependencies

    v2.3.4

    v2.3.3

    v2.3.2

    Add Third Party License Information to Dist Files

    v2.3.1

    Fix default branch resolution for .wiki and when using SSH

    v2.3.0

    Fallback to the default branch

    v2.2.0

    Fetch all history for all tags and branches when fetch-depth=0

    v2.1.1

    Changes to support GHES (here and here)

    v2.1.0

    Changelog

    Sourced from actions/checkout's changelog.

    Changelog

    v2.3.1

    v2.3.0

    v2.2.0

    v2.1.1

    • Changes to support GHES (here and here)

    v2.1.0

    v2.0.0

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies github_actions 
    opened by dependabot[bot] 1
  • Suggest Authentication

    Suggest Authentication

    Loosens the requirement of codeigniter4/authentication-implementation to a suggestion, using the Session fallback when the helper function is missing.

    opened by MGatner 1
  • How to use helper function to get PhpStan happy.

    How to use helper function to get PhpStan happy.

    I have used preference helper in my Controller function like:

    preference('App.theme', $this->request->getPost('theme'));
    

    but I'm getting error within PhpStan static analyze with Lvl. 6 like:

    Line   app/Controllers/SettingsController.php                              
     ------ -------------------------------------------------------------------- 
      56     Function preference not found.                                      
             💡 Learn more at https://phpstan.org/user-guide/discovering-symbols 
    

    Can you help me how to solve this error ?

    Thank you.

    opened by jozefrebjak 1
Releases(v1.0.0-rc.4)
  • v1.0.0-rc.4(Nov 24, 2021)

    Switches the authentication dependency to a suggestion, using Session as a complete fallback when no library is found.

    Hopefully the last RC before the final production release!

    What's Changed

    • Suggest Authentication by @MGatner in https://github.com/tattersoftware/codeigniter4-preferences/pull/9

    Full Changelog: https://github.com/tattersoftware/codeigniter4-preferences/compare/v1.0.0-rc.3...v1.0.0-rc.4

    Source code(tar.gz)
    Source code(zip)
  • v1.0.0-rc.3(Nov 23, 2021)

    • Provides a placeholder config file with corresponding docs
    • Adds support for said config file via helper shorthands: preference('foo')

    What's Changed

    • Placeholder Config by @MGatner in https://github.com/tattersoftware/codeigniter4-preferences/pull/8

    Full Changelog: https://github.com/tattersoftware/codeigniter4-preferences/compare/v1.0.0-rc.2...v1.0.0-rc.3

    Source code(tar.gz)
    Source code(zip)
  • v1.0.0-rc.2(Nov 23, 2021)

    Adds a fallback to Session for unauthenticated requests.

    What's Changed

    • Session by @MGatner in https://github.com/tattersoftware/codeigniter4-preferences/pull/7

    Full Changelog: https://github.com/tattersoftware/codeigniter4-preferences/compare/v1.0.0-rc.1...v1.0.0-rc.2

    Source code(tar.gz)
    Source code(zip)
  • v1.0.0-rc.1(Nov 19, 2021)

Owner
Tatter Software
Web app development for problem solving
Tatter Software
Open Source Point of Sale is a web based point of sale application written in PHP using CodeIgniter framework.

Open Source Point of Sale is a web based point of sale application written in PHP using CodeIgniter framework. It uses MySQL as the data back end and has a Bootstrap 3 based user interface.

opensourcepos 2.7k Jan 2, 2023
A learning management system (LMS) is a software application or web-based technology used to plan, implement and assess a specific learning process.

vidyaprabodhan-gov-php-project A learning management system (LMS) is a software application or web-based technology used to plan, implement and assess

Narayan Pote 1 Dec 23, 2021
Integration of the popular Bootstrap CSS framework for CodeIgniter 4

Tatter\Bootstrap Integration of the popular Bootstrap CSS framework for CodeIgniter 4 Description This library leverages Tatter\Assets to automate ass

Tatter Software 1 Nov 27, 2021
Customer Relationship Management (CRM) portal using PHP Codeigniter 4 & Tailwind CSS framework.

CRM Portal Customer Relationship Management (CRM) portal using PHP Codeigniter 4 & Tailwind CSS framework. Screenshots User (Dashboard) Admin (Employe

Dawood Khan Masood 5 Feb 2, 2022
CI4-Lic is a software license manager modul for Codeigniter 4, connecting to WordPress license server based on the Software License Manager Plugin.

CI4-Lic CI4-Lic is a software license manager modul for Codeigniter 4, connecting to WordPress license server based on Software License Manager Plugin

George Lewe 1 Jan 15, 2022
ZAP CRM is Customer Relationship Management portal built using PHP Codeigniter 4 & Tailwind CSS framework.

ZAP CRM ZAP CRM is Customer Relationship Management portal built using PHP Codeigniter 4 & Tailwind CSS framework. Screenshots User (Dashboard) Admin

Dawood Khan Masood 5 Feb 2, 2022
Admidio is a free open source user management system for websites of organizations and groups

Admidio is a free open source user management system for websites of organizations and groups. The system has a flexible role model so that it’s possible to reflect the structure and permissions of your organization.

Admidio 214 Jan 1, 2023
User input collection of recipes that can be filtered to meet certain criteria or to return a random recipe.

How to use: Install xampp: https://www.apachefriends.org/index.html and PHP Unzip the repo in the C:/xampp/htdocs directory Run xampp and turn on the

kristiyan 1 Jan 27, 2022
UserFrosting is a secure, modern user management system written in PHP and built on top of the Slim Microframework, Twig templating engine, and Eloquent ORM.

UserFrosting 4.6 Branch Version Build Coverage Style master hotfix develop https://www.userfrosting.com If you simply want to show that you like this

UserFrosting 1.6k Jan 1, 2023
Roundcube Webmail is a browser-based multilingual IMAP client with an application-like user interface.

Roundcube Webmail roundcube.net ATTENTION This is just a snapshot from the GIT repository and is NOT A STABLE version of Roundcube. It's not recommend

Roundcube Webmail Project 4.7k Dec 28, 2022
A wiki to ease developers' work by providing a user authentication librariesthat can be used as middleware within a web application to authenticate

A wiki to ease developers' work by providing a user authentication librariesthat can be used as middleware within a web application to authenticate (their application user) requests.

Zuri Training 6 Aug 8, 2022
yxorP is a PHP-based proxy application that is very lightweight and easily customizable per user needs.

Web Proxy Guzzler + SAAS(y) Cockpit (GUI Dashboard incl.). Feature Rich, Multi-tenancy, Headless, Plug & Play, Augmentation & Content Spinning Web Proxy with Caching - PHP CURL+Composer are Optional. Leveraging SAAS architecture to provide multi-tenancy, multiple threads, caching, and an article spinner service.

4D/ҵ.com Dashboards 9 Aug 14, 2022
DataTables server-side for CodeIgniter, supported both for CodeIgniter 3 and CodeIgniter 4.

CodeIgniter DataTables DataTables server-side for CodeIgniter, supported both for CodeIgniter 3 and CodeIgniter 4. Note: This library only handle the

Nur Muhammad 14 Dec 15, 2022
Persistent settings in Laravel

Laravel Settings Persistent, application-wide settings for Laravel. Despite the package name, this package works with Laravel 4, 5, 6, 7 and 8! Common

Andreas Lutro 855 Dec 27, 2022
Persistent settings package for Laravel 5.

Package is looking for maintainers Please contact me if interested. Persistent Settings for Laravel 5 Persistent settings package for Laravel 5. Drive

Edvinas Kručas 228 Dec 13, 2022
Simple user settings facade for Hyperf. Settings are stored as JSON in a single database column, so you can easily add it to an existing table.

hyperf-user-settings Simple user settings util for hyperf Settings are stored as JSON in a single database column, so you can easily add it to an exis

lysice 1 Oct 15, 2021
A PocketMine-MP plugin which let's you whitelist specific commands on specific worlds.

LevelLimiter A PocketMine-MP plugin which let's you whitelist specific commands on specific worlds. Config.yml Set up the commands and the whitelisted

MCA7 7 Aug 6, 2022
Utility PHP class to simplify interacting with persistent dismissible WordPress notices, promos, and banners

Persistent Dismissible A class for encapsulating the logic required to maintain a relationship between the database, a dismissible UI element (with an

Sandhills Development, LLC 22 Oct 11, 2022
Corruption prevention mechanism against EU public governance institutions - reporting prevalence over persistent storage.

c2c-mvc.pbgroupeu A small scale - based on Composer dependencies - MVC - ORM application project. It can be used on low-intensity resources consumptio

Povilas Brilius 1 Oct 18, 2021