Siberia PHP Framework

Status
Not open for further replies.

Weasel

👄 I'd intercept me
Nov 25, 2011
4,135
2,461
Let's say we got a class that extends another class, which has a static property with the same name, it uses the one from the current class and not the extended one.
Well, it has just become a habit to me to use static over self, hehe, and it looks a lot cleaner if you ask me.

Never seen it before, you learn something new every day! The reason I asked is because I personally find self look cleaner, but that's just personal preference (as is a lot in coding). Thanks for explaining and including a source with more in-depth information!
 

MayoMayn

BestDev
Oct 18, 2016
1,423
683
#UPDATES
Couldn't really find an appropriate ORM that fulfilled my wishes, so I figured why not just learn a bit more and code one myself.
Only been coding on the container right now, so here's a little preview.
Basic usage of insert into a table:
PHP:
use Siberia\Database\DB;
// Select the table
$user = DB::allocate('users');
$user->username = "Sentinel";
$user->password = Auth::hash('Sentinel');
// Upon finish this will return a boolean
$user->store();
Currently outputs how the SQL syntax would look like:
Code:
INSERT INTO `users` (`username`,`password`) VALUES (:username,:password)

Siberia\Database\DB
PHP:
namespace Siberia\Database;
use Siberia\Database\ORM;

class DB
{

    protected static $orm;

    public static function allocate($table)
    {
        return static::$orm = new ORM($table);
    }

}

Siberia\Database\ORM
PHP:
namespace Siberia\Database;
use Siberia\Database\PDO;

class ORM extends PDO
{

    protected $tableName, $capsule;

    public function __construct($table)
    {
        $this->tableName = $table;
        return $this->capsule = new \stdClass;
    }

    public function __get($key)
    {
        return $this->capsule->{$key};
    }

    public function __set($key, $value)
    {
        $this->capsule->{$key} = $value;
    }

    public function splitCapsule()
    {
        foreach($this->capsule as $key => $value) {
            $params[$key] = $value;
            $rows[] = "`" . $key . "`";
            $ids[] = ":" . $key;
        }

        return (object) [
            'params' => $params,
            'name' => $this->tableName,
            'rows' => implode(",", $rows),
            'ids' => implode(",", $ids)
        ];
    }

    /**
     *  Insert information into the chosen database table
     */
    public function store()
    {
        $capsule = $this->splitCapsule();

        $sql = "INSERT INTO `{$capsule->name}` ({$capsule->rows}) VALUES ({$capsule->ids})";

        return $this->query($sql)->bind($capsule->params)->run();
    }

}

Did a little cleanup.
 
Last edited:

Weasel

👄 I'd intercept me
Nov 25, 2011
4,135
2,461
If I may ask, what was wrong with Eloquent ORM? Awesome you're making one yourself tough.
 

MayoMayn

BestDev
Oct 18, 2016
1,423
683
If I may ask, what was wrong with Eloquent ORM? Awesome you're making one yourself tough.
Nothing hehe, I just liked the usage more, and wanted to code one alike but with some twists and less coding.
 
#UPDATES
I've managed to find an easy way to receive columns/rows/values from a table based off the same structure as the insert method above.
PHP:
$user = DB::allocate('users');
$user->username = "Sentinel";

die(var_dump($user->get(['password', 'id'])));
It's the same method, basically here, instead of assigning the username as an insert value, it selects columns from a table based off that value.
This means, that I'll receive the password and id column in a fetch assoc mode converted to an object.
If I leave the get method empty, it just fetches all columns.
Code:
object(stdClass)#16 (2) { ["password"]=> string(60) "$2y$10$6RlXpgFg3wr5DWprAeCZRuCmEKGD2pm728LjbjoQjrPgoGpSp57Ti" ["id"]=> int(2) }
The method:
PHP:
public function get(array $val = [])
    {
        if(empty($val)) {
            $val = '*';
        } else {
            foreach($val as $key) {
                $keys[] = "`" . $key . "`";
            }
            $val = implode(",", $keys);
        }
   
        $capsule = $this->splitCapsule();

        $sql = "SELECT {$val} FROM `{$capsule->name}`";

        if(count($capsule->rows) > 0) {
            $sql .= " WHERE " . current($capsule->rows) . " = " . current($capsule->values);
            // Unset the first row as it has been used
            $this->array_unset($capsule->rows);
            // Unset the first value as it has been used
            $this->array_unset($capsule->values);
        }

        if(count($capsule->rows) >= 1) {
            for($i = 0; $i < count($capsule->rows); $i++) {
                $sql .= " AND " . current($capsule->rows) . " = " . current($capsule->values);

                $this->array_unset($capsule->rows);
                $this->array_unset($capsule->values);
            }
        }

        return $this->query($sql)->bind($capsule->params)->run()->fetchAll();

    }

    public function array_unset(array &$array)
    {
        unset($array[key($array)]);
    }
Next step would be to add limits etc.
 
#UPDATES
I feel like I am on fire today, might even finish off the ORM module before tomorrow!
Managed to code the update module.
Usage:
PHP:
$user = DB::allocate('users');
$user->id = 2;

// Creates a duplicate of the instance
$set = DB::duplicate();
$set->username = "Delight";

// Updates the table
$set->update($user);
Basically, it updates the username with an id of 2 to Delight.
Code:
UPDATE `users` SET `username` = "Delight" WHERE `id` = 2

PHP:
    public function update(ORM $instance)
    {
        $instance = $this->splitInstance($instance->capsule);

        $capsule = $this->splitCapsule();

        $sql = "UPDATE `{$capsule->name->table}`";

        $sql .= " SET " . current($capsule->rows) . " = " . current($capsule->values);
        // Unset the first row as it has been used
        $this->array_unset($capsule->rows);
        // Unset the first value as it has been used
        $this->array_unset($capsule->values);

        if(count($capsule->rows) >= 1) {
            for($i = 0; $i < count($capsule->rows); $i++) {
                $sql .= ", " . current($capsule->rows) . " = " . current($capsule->values);

                $this->array_unset($capsule->rows);
                $this->array_unset($capsule->values);
            }
        }

        $sql .= $this->mergeWhereSQL($instance);

        $params = array_merge($instance->params, $capsule->params);

        return $this->query($sql)->bind($params)->run();
    }

    public function mergeWhereSQL($object)
    {
        $sql = "";

        if(count($object->rows) > 0) {
            $sql .= " WHERE " . current($object->rows) . " = " . current($object->values);
            // Unset the first row as it has been used
            $this->array_unset($object->rows);
            // Unset the first value as it has been used
            $this->array_unset($object->values);
        }

        if(count($object->rows) >= 1) {
            for($i = 0; $i < count($object->rows); $i++) {
                $sql .= " AND " . current($object->rows) . " = " . current($object->values);

                $this->array_unset($object->rows);
                $this->array_unset($object->values);
            }
        }

        return $sql;
    }

    public function splitInstance($instance)
    {
        foreach($instance as $key => $value) {
            $params[":i_{$key}"] = $value;
            $rows[] = "`{$key}`";
            $vals[] = ":i_" . $key;
        }

        return (object) [
            'params' => $params,
            'rows'   => $rows,
            'values' => $vals
        ];
    }
 

Nicholas

Just another user:)
Mar 18, 2015
58
9
Your composer is not working as it says error installing the framework, your git respitory leads to a 404 error, and the github page for it contains barley any files. I do not know if i can give you feedback.
 
Oh and you might want to patch that timing attack vulnerability on your CSRF page, use the built in hash_equals() function it is timing attack safe. More info at
 

MayoMayn

BestDev
Oct 18, 2016
1,423
683
Your composer is not working as it says error installing the framework, your git respitory leads to a 404 error, and the github page for it contains barley any files. I do not know if i can give you feedback.
 
Oh and you might want to patch that timing attack vulnerability on your CSRF page, use the built in hash_equals() function it is timing attack safe. More info at
Good luck installing a framework whereas the dist haven't been added.
This is a framework that is not even close to being finished, aswell as the git repository leads to a 404, is because I've changed the username of my account. This project was purely to expand my knowledge about PHP.
Since I've quit PHP it's not going to be finished, maybe sometime when I get tired of JS and want some nostalgia
 

Nicholas

Just another user:)
Mar 18, 2015
58
9
Good luck installing a framework whereas the dist haven't been added.
This is a framework that is not even close to being finished, aswell as the git repository leads to a 404, is because I've changed the username of my account. This project was purely to expand my knowledge about PHP.
Since I've quit PHP it's not going to be finished, maybe sometime when I get tired of JS and want some nostalgia
Alright if this project is not supported this thread should be closed. Man quiting PHP what made you do that.
 

MayoMayn

BestDev
Oct 18, 2016
1,423
683
If you really like javascript check out Angular Javascript or you can use the new Angular 2 . Most people do prefer the old one.
I prefer React for its simplicity.
 

Nicholas

Just another user:)
Mar 18, 2015
58
9
I prefer React for its simplicity.
Nice REACT JS is good for its speed,
 
Nice REACT JS is good for its speed,
I am sticking with Angular, I plan on making an admin panel with the new angular js with a number of features suck as a lock screen, login, remember me, forgot password, two factor authentication, message system between other users logged in, unlimited roles, and much more, but that is far from completion i am constructing the main components such as the php session, i am using every security action their is, by enabling strict mode that is recommended by , and by regenerating a new session id every time the user logs in, changes their password, and other other sensitive actions, and also by locking the session to the user using their ip and user agent. I am currently constructing the DB connection file witch all i have to do is create the config vars and create the interface for the class. But anyways GoodLuck with REACT JS.
 

ViZoK

New Member
Aug 12, 2013
15
0
Looking good, man. I know it's cliche to say but I love seeing active development for projects that actually have a point (like this one) Keep it up. I haven't been on DB since 2013 and I was slightly surprised to see so many people still here.
 

MayoMayn

BestDev
Oct 18, 2016
1,423
683
Looking good, man. I know it's cliche to say but I love seeing active development for projects that actually have a point (like this one) Keep it up. I haven't been on DB since 2013 and I was slightly surprised to see so many people still here.
If you read the earlier posts being commented, it's no longer under development :)
Thanks for the feedback though.

Waiting on a moderator to close the thread.
 

Weasel

👄 I'd intercept me
Nov 25, 2011
4,135
2,461
Too bad you've stopped developing this. It looked promosing. Thread closed, PM me if you start development once again.
 
Status
Not open for further replies.

Users who are viewing this thread

Top