PHPackages                             drey/prefs - 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. drey/prefs

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

drey/prefs
==========

Store and retrieve user preferences

1.0.2(10y ago)029MITPHPPHP &gt;=5.3.0

Since May 4Pushed 10y ago1 watchersCompare

[ Source](https://github.com/dreylago/prefs)[ Packagist](https://packagist.org/packages/drey/prefs)[ RSS](/packages/drey-prefs/feed)WikiDiscussions master Synced 6d ago

READMEChangelogDependenciesVersions (4)Used By (0)

Prefs
=====

[](#prefs)

Store and retrieve user preferences.

1. Remember form default values according to the last submit (for instance, repeat the date limits or the selection of an account in a dropdown list, according to the last search).
2. Customize the look and feel of a website.
3. etc.

Usage
-----

[](#usage)

### Database in file system

[](#database-in-file-system)

```
    use drey\Prefs\Factory;

    # Obtain a Prefs object
    # with file system storage and username
    $prefs = Factory::fileSystem('/path/to/directory','bob')

    # set preference "color" for current user (bob)
    $prefs->set('color','red');

    # get color preference of current user
    $color = $prefs->get('color');

    # $color is set to 'red'
```

### Database in a RDMB

[](#database-in-a-rdmb)

Change the DB medium accordingly, using a pdo factory.

```
    use drey\Prefs\Factory;

    # obtain a PDO object
    $pdo = myConnect();

    # Obtain a Prefs object
    # with RDBM storage and username
    $prefs = Factory::pdo($pdo,'bob')

    # set preference "color" for current user (bob)
    $prefs->set('color','red');

    # get color preference of current user
    $color = $prefs->get('color');

    # $color is set to 'red'
```

The table schema for MySQL should be (see directory `sql/`):

```
        CREATE TABLE `prefs`  (
          `name` varchar(255) NOT NULL,
          `value` varchar(255) NOT NULL,
          `username` varchar(32) NOT NULL,
          PRIMARY KEY (`name`,`username`),
          KEY (`username`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
```

### Default values

[](#default-values)

If key is not found, a default value can be provided.

```
    $bird = $prefs->get('bird','eagle');

    # $bird is set to 'eagle' if key 'bird' not found
```

### Specify preferences for other users

[](#specify-preferences-for-other-users)

To assign/read the preferences of other users:

```
    $prefs->set('fruit','lemmon','alice');
    # ...
    $prefs->get('fruit','pear','alice')
```

### Global preferences

[](#global-preferences)

A global username could be used to handle preferences for all users. All users must agree on the global username (for instance '\*').

```
    # one user
    $prefs->set('closing_date',$form->closing_date,'*');

    (...)

    # other users
    $closing_date = $prefs->get('closing_date',date('Y-m-d'),'*');

```

### Populate form fields:

[](#populate-form-fields)

Populate fields with default values if a field in our model has not any value and we are creating a new record.

```
    # before showing the form get the last value entered
    if ($model->isNewRecord && !$model->date) {
        $model->date = $prefs->get('invoice_date',date('Y-m-d'));
    }

    # after post, update value entered
    if (post) {
        $prefs->set('invoice_date',$model->date);
    }
```

Installing with composer
------------------------

[](#installing-with-composer)

The package exists in Packagist repository as `drey/prefs`.

See [drey/prefs](https://packagist.org/packages/drey/prefs).

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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.

###  Release Activity

Cadence

Every ~342 days

Total

3

Last Release

3711d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/876487b4ce47c7e5828f30331095305d661754cf92aeade28162b8405c7ab957?d=identicon)[drey](/maintainers/drey)

---

Top Contributors

[![dreylago](https://avatars.githubusercontent.com/u/3028271?v=4)](https://github.com/dreylago "dreylago (47 commits)")

### Embed Badge

![Health badge](/badges/drey-prefs/health.svg)

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

PHPackages © 2026

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