PHPackages                             tlucas/phpjstore - 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. [Database &amp; ORM](/categories/database)
4. /
5. tlucas/phpjstore

AbandonedArchivedLibrary[Database &amp; ORM](/categories/database)

tlucas/phpjstore
================

v1.1.4(9y ago)1146MITPHPPHP ^7.0

Since Apr 22Pushed 9y ago1 watchersCompare

[ Source](https://github.com/tjwlucas/phpjstore)[ Packagist](https://packagist.org/packages/tlucas/phpjstore)[ RSS](/packages/tlucas-phpjstore/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (7)DependenciesVersions (8)Used By (0)

phpjstore
=========

[](#phpjstore)

[![Latest Stable Version](https://camo.githubusercontent.com/4d33c9e7437d90c595fce41faddafb7f0a4f235519d268de038f690527d87737/68747470733a2f2f706f7365722e707567782e6f72672f746c756361732f7068706a73746f72652f762f737461626c65)](https://packagist.org/packages/tlucas/phpjstore)[![Latest Unstable Version](https://camo.githubusercontent.com/57f41e1421202a82f93e7d66fdc30d2188566d738e8a8f68a823f69a4eccbe67/68747470733a2f2f706f7365722e707567782e6f72672f746c756361732f7068706a73746f72652f762f756e737461626c65)](https://packagist.org/packages/tlucas/phpjstore)[![License](https://camo.githubusercontent.com/103605dd7194f41c1e0e6587e905b68c0d8895e4d64a540846079200f60b7ac0/68747470733a2f2f706f7365722e707567782e6f72672f746c756361732f7068706a73746f72652f6c6963656e7365)](https://packagist.org/packages/tlucas/phpjstore)

Phpjstore provides a class to save and access schemaless data in a flatfile JSON backend.

- [phpjstore](#phpjstore)
    - [Requirements](#requirements)
    - [Installation/Setup](#installationsetup)
        - [Basic usage](#basic-usage)
        - [Globals](#globals)
    - [Admin](#admin)
        - [Scripts/styles](#scriptsstyles)
        - [Endpoint](#endpoint)
        - [Data schema](#data-schema)
        - [Forms](#forms)

Requirements
------------

[](#requirements)

Phpjstore iself doesn't require any dependencies.

The admin interface uses the Jeremy Dorn's [json-editor](https://github.com/jdorn/json-editor/) (included in the package), [jquery](https://github.com/jquery/jquery), and [Bootstrap 3](https://github.com/twbs/bootstrap). Both of these can be included directly in your page (using CDN)

Installation/Setup
------------------

[](#installationsetup)

Using composer:

```
composer require tlucas/phpjstore

```

In your project file (e.g. `project.php`) you wish to use it in make sure you have

```
require_once('vendor/autoload.php');
use jstore\jstore;

```

Then you can instantiate a data store object with

```
$store = new jstore('mydata');

```

Which will store all the data in the `mydata` directory (relative to your current script).

### Basic usage

[](#basic-usage)

To interact with a data object, first you need to create a data object. This is done, using the `$store` object defined above, by calling the `get()` method:

```
$data = $store->get('somekey');

```

This has now created an object `$data` containing the data stored using the `somekey` key. If that key doesn't yet exist, this will be an empty data object.

Once you have the object in `$object` you can set some values using `set()`:

```
$data->set(['firstkey' => 'firstvalue', 'secondkey' => 'secondvalue']);

```

This will only set the specified values (it will not affect the other values stored in the object) so if we then do:

```
$data->set(['thirdkey' => 'thirdvalue']);

```

This is also equivalent to

```
$data->thirdkey = 'thirdvalue';

```

All three values will now be held on that object.

If we want to delete the first variable we set earlier:

```
$data->delete('firstkey');

```

So now, our stored object looks like this (if we do `echo $data;`):

```
{
    "firstkey": "firstvalue",
    "secondkey": "secondvalue",
    "thirdkey": "thirdvalue"
}

```

To access these values:

```
echo $data->firstkey;

```

Will print `firstvalue`.

If you prefer to work with arrays,

```
$data->toArray();

```

will return the array:

```
Array
(
    [firstkey] => firstvalue
    [secondkey] => secondvalue
    [thirdkey] => thirdvalue
)

```

At the moment, the object has only been modified in memory, so to save the changes permanently, just call:

```
$data->save();

```

### Globals

[](#globals)

Phpjstore includes some shortcuts to the above functions for storing and retrieving global variables:

To set a global variable:

```
$store->setGlobal(['varname' => 'varvalue']);

```

(Note: this *will* immediately save the variable to the storage backend)

And to retrieve the variable we just set:

```
$store->getGlobal('varname');

```

To list all Globals that are stored in this way:

```
$store->getGlobals();

```

Which will return a list of the keys.

To delete one of these stored variables:

```
$store->deleteGlobal('varname');

```

(Note: again, this *will* immediately save the variable to the storage backend)

Admin
-----

[](#admin)

Phpjstore includes a data management interface based around jdorn's fantastic [json-editor](https://github.com/jdorn/json-editor/).

Before using it, it requires a little setup.

### Scripts/styles

[](#scriptsstyles)

First, the interface uses a javascript file to be included once, along with jquery, somewhere before it is called. It also uses [Bootstrap 3](https://github.com/twbs/bootstrap) for styling, so that must also be available on the page.

Phpjstore includes some helper fuctions to do these for you, if you don't already use them in your page:

```
echo jstore::script();

```

Will include jsut the [json-editor](https://github.com/jdorn/json-editor/) script. If you also need to include jquery, use:

```
echo jstore::script($jquery=True);

```

To include Bootstrap:

```
echo jstore::bootstrap3();

```

### Endpoint

[](#endpoint)

In order to save the data provided in the form you will need to set an endpoint for submission. This is done by adding

```
$store->registerEndpoint();

```

To the top of the file which is acting as your endpoint. This can be the same file, or a different file, but it must be placed before any output is sent.

If you placed this endpoing in a *separate* file (e.g. `/path/to/submit.php`), you will need to point your admin scripts to send their submissions to that file:

```
$store->adminpost = '/path/to/submit.php';

```

***Important:***Be aware that ***anyone*** who has access to the endpoint you set here ***will be able to modify your data***, so make sure you protect it, either by putting the file in a restricted directory (Using `.htaccess` on Apache, for instance) or eclosing the method call in an authentication check, using whatever authentication system you choose):

```
if( /* User is authenticated */ ){
	$store->registerEndpoint();
}

```

### Data schema

[](#data-schema)

The final step before adding the interface is setting up the schema for your data. While the *stored* data don't depend on any schema (you can just save variables straight to them, and it will create the fields as required). The [json-editor](https://github.com/jdorn/json-editor/) interface requires a schema to build the apppropriate forms.

To set up a schema, simply go to your `mydata` directory (as defined when initialising the `jstore` instance, and inside the `schema` directory create a file called `somekey.json`. In that file, define a schema as defined [here](https://github.com/jdorn/json-editor/#json-schema-support). (When you first set up jstore, there will be an `example.json` schema already there, for reference).

### Forms

[](#forms)

Now we have done all that, we are ready to display the admin form!

To display the form for the `somekey` schema you created above:

```
echo $store->admin('somekey');

```

(Or to use the example schema provided: `echo $store->admin('example');`)

And you're done! You should have a fully functional form to modify your stored data.

You can list all the schemas you have defined by running:

```
$store->getSchemas();

```

So if you wanted an admin page which automatically gave you a form to allow you to edit all of your defined schemas, you could run:

```
foreach($store->getSchemas() as $schema){
	echo $store->admin($schema);
}

```

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

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 ~4 days

Total

7

Last Release

3330d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/79045?v=4)[tlucas](/maintainers/tlucas)[@tlucas](https://github.com/tlucas)

---

Top Contributors

[![tjwlucas](https://avatars.githubusercontent.com/u/20072739?v=4)](https://github.com/tjwlucas "tjwlucas (51 commits)")

### Embed Badge

![Health badge](/badges/tlucas-phpjstore/health.svg)

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

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k117.2M117](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)

PHPackages © 2026

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