Skip to content

Commit

Permalink
bugs fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg0 committed Feb 16, 2013
0 parents commit 1b6e10c
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 0 deletions.
Empty file added data/users.config.json
Empty file.
1 change: 1 addition & 0 deletions data/users.data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"value":"New","onclick":"CreateNewDoc()"},{"value":"Open","onclick":"OpenDoc()"},{"value":"Close","onclick":"CloseDoc()"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"},{"pozdro":"asd","pa":"345"}]
13 changes: 13 additions & 0 deletions includes/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

define('JSONDB', 1);

function __autoload($class)
{
if (file_exists('includes/'.$class.'.class.php'))
{
require_once 'includes/'.$class.'.class.php';
}
}

?>
36 changes: 36 additions & 0 deletions includes/core.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

defined('JSONDB') or die('Permission denied!');

/**
* Core class of JSONDB project
*
* @author Grzegorz Kuźnik
* @copyright (c) 2013, Grzegorz Kuźnik
*/
abstract class Core {

public $data;
public $name;
protected $set;

public function __set($name, $value)
{
$this->set->{$name} = $value;

}

public function save()
{
array_push($this->data, $this->set);
File::put($this->name, json_encode($this->data));
}

public function find_all()
{
return $this->data;
}

}

?>
25 changes: 25 additions & 0 deletions includes/file.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

defined('JSONDB') or die('Permission denied!');

/**
* File managing class of JSONDB project
*
* @author Grzegorz Kuźnik
* @copyright (c) 2013, Grzegorz Kuźnik
*/
class File {

public static function get($name, $type='data')
{
return file_get_contents(JSONDB_DATA_PATH.$name.'.'.$type.'.json');
}

public static function put($name, $data, $type='data')
{
return file_put_contents(JSONDB_DATA_PATH.$name.'.'.$type.'.json', $data);
}

}

?>
16 changes: 16 additions & 0 deletions includes/jdbexception.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php


class JDBException extends Exception {
public function __construct($message, $code=0)
{
parent::__construct($message,$code);
}

public function __toString()
{
return $this->message;
}
}

?>
33 changes: 33 additions & 0 deletions includes/jsondb.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

defined('JSONDB') or die('Permission denied!');

/**
* Core class of JSONDB project
*
* @author Grzegorz Kuźnik
* @copyright (c) 2013, Grzegorz Kuźnik
*/
class Jsondb extends Core {

public static function factory($name)
{
$self = new Jsondb;
$self->name = $name;

try {
if (!file_exists(JSONDB_DATA_PATH.$self->name.'.data.json'))
throw new JDBException('Failed to load data file');

$self->data = json_decode(File::get($self->name));
}
catch (JDBException $exc) {
echo $exc;
}

return $self;
}

}

?>
15 changes: 15 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

require_once 'includes/config.php';
define('JSONDB_DATA_PATH', realpath(dirname(__FILE__)).'/data/');

$users = Jsondb::factory('users');

$users->pozdro = 'asd';
$users->pa = '345';

$users->save();

var_dump($users);

?>
7 changes: 7 additions & 0 deletions nbproject/project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
include.path=${php.global.include.path}
php.version=PHP_54
source.encoding=UTF-8
src.dir=.
tags.asp=false
tags.short=true
web.root=.
9 changes: 9 additions & 0 deletions nbproject/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.php.project</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/php-project/1">
<name>JSONDB</name>
</data>
</configuration>
</project>

0 comments on commit 1b6e10c

Please sign in to comment.