Bear Framework provides a simple yet powerful object storage API. You can use it to store, modify, request and list any data (text, images, videos, etc.). Initialize it by setting a data driver. The default data driver (FileDataDriver) stores the objects in files using atomic operations. Every data item is stored in a separate file.

use BearFramework\App;

$app App::get();

// Enables a file based storage for the data items.

// Creates a new data item.
$item $app->data->make('users/1''{"name":"John Smith","email":""}');

// Stores the data item.

// Retrieve a data item.
$item $app->data->get('users/1');
$item->key// Will output 'users/1'
echo $item->value// Will output '{"name":"John Smith","email":""}'

// Append data to a data item (will be created if missing).

// Duplicatea a data item

// Renames a data item

// Deletes a data item

// Retrieves a list of all data items.


Metadata support is available too. It is a great way to store sizes, dates or other object details.

use BearFramework\App;

$app App::get();

// Creates a new data item.
$item $app->data->make('users/1''{"name":"John Smith","email":""}');
$item->metadata['lastLoginDate'] = '2019-12-12';

// Stores the data item.

// Retrieve the data item and then access the metadata.
$item $app->data->get('users/1');
$item->metadata['lastLoginDate']; // Will output '2019-12-12'

// Request only the metadata
echo $app->data->getMetadata('users/1''lastLoginDate'); // Will output '2019-12-12'

// Set new metadata value
echo $app->data->setMetadata('users/1''lastLoginDate''2019-12-20');

// Delete metadata
echo $app->data->deleteMetadata('users/1''lastLoginDate');

File access

The data objects can be accessed and modified using the build in PHP file functions. Just prefix the keys with 'appdata://'

// Stores or updates a data item.
file_put_contents('appdata://users/1''{"name":"John Smith","email":""}');

// Retrieves the content of a data item.
echo file_get_contents('appdata://users/1');

Allow public access

Object's public URLs can be easily requested too.

use BearFramework\App;

$app App::get();

// Makes the appdata://products/images public.

// Creates a new image.

// Generates a new public URL for the data item specified.
echo $app->assets->getURL('appdata://products/images/1.jpg'); // Will output ''

Learn more

Handle HTTP requests
Retrieve information about the HTTP request
Store frequently used data for later usage

The information on this page is created for version 1.1 of Bear Framework and may not be applicable for other versions of the framework.