Skip to content

Commit e4c316e

Browse files
Add files via upload
1 parent e6f6c8e commit e4c316e

File tree

3 files changed

+34
-24
lines changed

3 files changed

+34
-24
lines changed

src/Database.php

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
2-
2+
33
namespace jsonDB;
4-
4+
55
use jsonDB\dbException;
66
use jsonDB\Relation;
77
use jsonDB;
8-
8+
99
/**
1010
* Core class of jsonDB.
1111
*
@@ -15,37 +15,37 @@
1515
*
1616
*/
1717
class Database implements \IteratorAggregate, \Countable {
18-
18+
1919
/**
2020
* Contain returned data from file as object or array of objects
2121
* @var mixed Data from table
2222
*/
2323
protected $data;
24-
24+
2525
/**
2626
* Name of file (table)
2727
* @var string Name of table
2828
*/
2929
protected $name;
30-
30+
3131
/**
3232
* Object with setted data
3333
* @var object Setted data
3434
*/
3535
protected $set;
36-
36+
3737
/**
3838
* ID of current row if setted
3939
* @var integer Current ID
4040
*/
4141
protected $currentId;
42-
42+
4343
/**
4444
* Key if current row if setted
4545
* @var integer Current key
4646
*/
4747
protected $currentKey;
48-
48+
4949
/**
5050
* Pending functions with values
5151
* @see \jsonDB\Database::setPending()
@@ -130,7 +130,7 @@ protected function clearKeyInfo()
130130
protected function setFields()
131131
{
132132
$this->set = new \stdClass();
133-
$schema = $this->schema();
133+
$schema = $this->schema();
134134

135135
foreach ($schema as $field => $type)
136136
{
@@ -177,11 +177,22 @@ protected function clearQuery()
177177
*/
178178
public function __set($name, $value)
179179
{
180+
/*
180181
if (Validate::table($this->name)->field($name) && Validate::table($this->name)->type($name, $value))
181182
{
182183
$this->set->{$name} = $value;
184+
}
185+
*/
186+
try {
187+
Validate::table($this->name)->field($name);
188+
Validate::table($this->name)->type($name, $value);
189+
$this->set->{$name} = $value;
190+
} catch(dbException $error) {
191+
echo $error;
183192
}
193+
184194
}
195+
185196

186197
/**
187198
* Returning variable from Object
@@ -521,7 +532,7 @@ protected function wherePending()
521532
elseif (!is_array($value) && in_array($op, array('LIKE', 'like')))
522533
{
523534

524-
//$specials = '.\+*?[^]$(){}=!<>|:-';
535+
//$specials = '.\+*?[^]$(){}=!<>|:-';
525536
$regex = "/^" . str_replace('%', '(.*?)', preg_quote($value)) . "$/si";
526537
$value = preg_match($regex, $row->{$field});
527538
$op = '==';
@@ -794,13 +805,13 @@ public function save()
794805
}
795806
else
796807
{
797-
$this->set->id = $this->currentId;
808+
$this->set->id = $this->currentId;
798809
$data[$this->currentKey] = $this->set;
799810
}
800811

801812
Data::table($this->name)->put($data);
802813

803-
// $this->setFields();
814+
// $this->setFields();
804815
}
805816

806817
/**
@@ -856,8 +867,8 @@ public function find($id = NULL)
856867
{
857868
if ($id !== NULL)
858869
{
859-
$data = $this->getData();
860-
$this->currentId = $id;
870+
$data = $this->getData();
871+
$this->currentId = $id;
861872
$this->currentKey = $this->getRowKey($id);
862873
foreach ($data[$this->currentKey] as $field => $value)
863874
{
@@ -907,7 +918,7 @@ public function getIterator()
907918
*/
908919
public function debug()
909920
{
910-
$print = "jsonDB::table(" . $this->name . ")\n";
921+
$print = "jsonDB::table(".$this->name.")\n";
911922
foreach ($this->pending as $function => $values)
912923
{
913924
if (!empty($values))

src/File.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public final function get($assoc = false)
6161

6262
$getPath = file_get_contents($this->getPath());
6363

64-
// Если ключ шифрования установлен расшифровываем
64+
// Если ключ шифрования установлен расшифровываем
6565
if (defined('JSON_DB_KEY') && JSON_DB_CRYPT == true){
6666

6767
try {
@@ -96,7 +96,7 @@ public final function get($assoc = false)
9696

9797
public final function put($data)
9898
{
99-
// Если ключ шифрования установлен шифруем
99+
// Если ключ шифрования установлен шифруем
100100
if (defined('JSON_DB_KEY') && JSON_DB_CRYPT == true){
101101
try {
102102
$getPath = Crypto::encrypt(json_encode($data), Key::loadFromAsciiSafeString(JSON_DB_KEY));

src/Validate.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
2-
2+
33
namespace jsonDB;
4-
4+
55
use jsonDB\dbException;
66
use jsonDB\Relation;
7-
7+
88
/**
99
* Validation for tables
1010
*
@@ -37,7 +37,7 @@ public static function table($name)
3737
*/
3838
public static function isNumeric($type)
3939
{
40-
$defined = array('integer', 'double');
40+
$defined = array("integer", "double");
4141

4242
if (in_array($type, $defined))
4343
{
@@ -56,7 +56,7 @@ public static function isNumeric($type)
5656
public static function types(array $types)
5757
{
5858
$defined = array('boolean', 'integer', 'double', 'string', 'text', 'datetime');
59-
$diff = array_diff($types, $defined);
59+
$diff = array_diff($types, $defined);
6060

6161
if (empty($diff))
6262
{
@@ -162,7 +162,6 @@ public function type($name, $value)
162162
{
163163
return TRUE;
164164
}
165-
166165
throw new dbException('Wrong data type');
167166
}
168167

0 commit comments

Comments
 (0)