Skip to content

Commit

Permalink
Merge pull request #43 from fire015/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
fire015 authored Mar 12, 2019
2 parents 1266ba5 + 4cd00b2 commit b507136
Show file tree
Hide file tree
Showing 24 changed files with 290 additions and 290 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ language: php
sudo: false

php:
- 5.6
- 7.0
- 7.1
- 7.2
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Change Log
==========

### 12/03/2019 - 2.2
* Bump minimum PHP version to 7.0
* Update PHPUnit to version 6
* Removed data type validation for storing
* Added param and return types

### 09/06/2017 - 2.1.1
* Update `Database::writeTempToFile` to correctly close the file pointer and free up memory

Expand Down
42 changes: 10 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,11 @@ $users = new Flintstone('users', ['dir' => '/path/to/database/dir/']);

### Requirements

- PHP 5.6+
- PHP 7.0+

### Data types

Flintstone can store the following data types:

* Strings
* Integers
* Floats
* Arrays
* Null
Flintstone can store any data type that can be formatted into a string. By default this uses `serialize()`. See [Changing the formatter](#changing-the-formatter) for more details.

### Options

Expand All @@ -64,40 +58,24 @@ Flintstone can store the following data types:
```php
<?php

// Set options
$options = ['dir' => '/path/to/database/dir/'];

// Load the databases
$users = new Flintstone('users', $options);
$settings = new Flintstone('settings', $options);
// Load a database
$users = new Flintstone('users', ['dir' => '/path/to/database/dir/']);

// Set keys
// Set a key
$users->set('bob', ['email' => 'bob@site.com', 'password' => '123456']);
$users->set('joe', ['email' => 'joe@site.com', 'password' => 'test']);
$settings->set('site_offline', 1);
$settings->set('site_back', '3 days');

// Retrieve keys
// Get a key
$user = $users->get('bob');
echo 'Bob, your email is ' . $user['email'];

$offline = $settings->get('site_offline');
if ($offline == 1) {
echo 'Sorry, the website is offline<br />';
echo 'We will be back in ' . $settings->get('site_back');
}

// Retrieve all key names
$keys = $users->getKeys(); // returns array('bob', 'joe', ...)
$keys = $users->getKeys(); // returns array('bob')

foreach ($keys as $username) {
$user = $users->get($username);
echo $username.', your email is ' . $user['email'];
echo $username.', your password is ' . $user['password'];
}
// Retrieve all data
$data = $users->getAll(); // returns array('bob' => array('email' => 'bob@site.com', 'password' => '123456'));

// Delete a key
$users->delete('joe');
$users->delete('bob');

// Flush the database
$users->flush();
Expand Down
50 changes: 25 additions & 25 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
{
"name": "fire015/flintstone",
"type": "library",
"description": "A key/value database store using flat files for PHP",
"keywords": ["flintstone", "database", "cache", "files", "memory"],
"homepage": "http://www.xeweb.net/flintstone/",
"license": "MIT",
"authors": [
{
"name": "Jason M",
"email": "emailfire@gmail.com"
}
],
"require": {
"php": ">=5.6"
},
"autoload": {
"psr-4": {
"Flintstone\\": "src/"
}
},
"require-dev" : {
"phpunit/phpunit": "^5.0"
}
}
{
"name": "fire015/flintstone",
"type": "library",
"description": "A key/value database store using flat files for PHP",
"keywords": ["flintstone", "database", "cache", "files", "memory"],
"homepage": "http://www.xeweb.net/flintstone/",
"license": "MIT",
"authors": [
{
"name": "Jason M",
"email": "emailfire@gmail.com"
}
],
"require": {
"php": ">=7.0"
},
"autoload": {
"psr-4": {
"Flintstone\\": "src/"
}
},
"require-dev" : {
"phpunit/phpunit": "^6"
}
}
1 change: 0 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="true"
verbose="true"
>
<filter>
Expand Down
9 changes: 0 additions & 9 deletions src/Cache/ArrayCache.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
<?php

/*
* This file is part of the Flintstone package.
*
* (c) Jason M <emailfire@gmail.com>
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/

namespace Flintstone\Cache;

class ArrayCache implements CacheInterface
Expand Down
9 changes: 0 additions & 9 deletions src/Cache/CacheInterface.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
<?php

/*
* This file is part of the Flintstone package.
*
* (c) Jason M <emailfire@gmail.com>
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/

namespace Flintstone\Cache;

interface CacheInterface
Expand Down
37 changes: 14 additions & 23 deletions src/Config.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
<?php

/*
* This file is part of the Flintstone package.
*
* (c) Jason M <emailfire@gmail.com>
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/

namespace Flintstone;

use Flintstone\Cache\ArrayCache;
Expand Down Expand Up @@ -48,15 +39,15 @@ public function __construct(array $config = [])
*
* @return array
*/
protected function normalizeConfig(array $config)
protected function normalizeConfig(array $config): array
{
$defaultConfig = [
'dir' => getcwd(),
'ext' => '.dat',
'gzip' => false,
'cache' => true,
'formatter' => null,
'swap_memory_limit' => 2097152, // 2MB
'swap_memory_limit' => 2097152, // 2MB
];

return array_replace($defaultConfig, $config);
Expand All @@ -67,7 +58,7 @@ protected function normalizeConfig(array $config)
*
* @return string
*/
public function getDir()
public function getDir(): string
{
return $this->config['dir'];
}
Expand All @@ -79,7 +70,7 @@ public function getDir()
*
* @throws Exception
*/
public function setDir($dir)
public function setDir(string $dir)
{
if (!is_dir($dir)) {
throw new Exception('Directory does not exist: ' . $dir);
Expand All @@ -93,7 +84,7 @@ public function setDir($dir)
*
* @return string
*/
public function getExt()
public function getExt(): string
{
if ($this->useGzip()) {
return $this->config['ext'] . '.gz';
Expand All @@ -107,9 +98,9 @@ public function getExt()
*
* @param string $ext
*/
public function setExt($ext)
public function setExt(string $ext)
{
if ('.' != substr($ext, 0, 1)) {
if (substr($ext, 0, 1) !== '.') {
$ext = '.' . $ext;
}

Expand All @@ -121,7 +112,7 @@ public function setExt($ext)
*
* @return bool
*/
public function useGzip()
public function useGzip(): bool
{
return $this->config['gzip'];
}
Expand All @@ -131,9 +122,9 @@ public function useGzip()
*
* @param bool $gzip
*/
public function setGzip($gzip)
public function setGzip(bool $gzip)
{
$this->config['gzip'] = (bool)$gzip;
$this->config['gzip'] = $gzip;
}

/**
Expand Down Expand Up @@ -171,7 +162,7 @@ public function setCache($cache)
*
* @return FormatterInterface
*/
public function getFormatter()
public function getFormatter(): FormatterInterface
{
return $this->config['formatter'];
}
Expand Down Expand Up @@ -201,7 +192,7 @@ public function setFormatter($formatter)
*
* @return int
*/
public function getSwapMemoryLimit()
public function getSwapMemoryLimit(): int
{
return $this->config['swap_memory_limit'];
}
Expand All @@ -211,8 +202,8 @@ public function getSwapMemoryLimit()
*
* @param int $limit
*/
public function setSwapMemoryLimit($limit)
public function setSwapMemoryLimit(int $limit)
{
$this->config['swap_memory_limit'] = (int)$limit;
$this->config['swap_memory_limit'] = $limit;
}
}
Loading

0 comments on commit b507136

Please sign in to comment.