Skip to content

karolisdailidonis/DORM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The DORM 0.1.3

A lightweight PHP ORM framework with API and no dependencies other than the native PHP extensions. In addition, it has a simple GUI for initializing models based on the tables in the database


Caution, the software is still in a very early stage. Is unstable and definitely has security vulnerabilities


Requirements:

  • Minimal PHP Version is PHP 8.0
  • MariaDB 10.5.0 or SQL Server 2012

Implemented:

  • PHP model class generator [ Dev ]
  • Custom Query Builder [ Dev ]
  • API [ Dev ]
    • default request methods like nodes
    • custom request methods
    • With "token" auth
  • Setup GUI
    • Generate models from selected DB tables [ Dev ]
    • Test API Requests [ Dev ]

Client helpers

npm https://www.npmjs.com/package/dorm-handler-js
dart https://pub.dev/packages/dorm_client
c++ cooming soon

Install

Simply download the DORM repo and paste it into your project or Webspace root folder. The project follows PSR-4 code style guide with namespaces and autoload, that means you only need to include the autoload.

include 'DORM/autoload.php';

Later the composer option will be added as well.

Next, rename DORM/Config/Config.sample.php to Config.php and set you database connection data.

For the db_type you can use:

db_type PDO
mysql php_pdo_mysql
mssql php_pdo_sqlsrv_[php version]_[ts|nts]_[x86|x64]

To call one of the main functions, you must also use use in one of the three folders.

use 'DORM\API';
use 'DORM\Database';
use 'DORM\Includes';

Like to call the DBHandler.php class

use DORM\Database\DBHandler;

$connection = new DBHandler();

Except for the generated classes, these are not in any namespace. There the normal class call is enough and the included autoload does the rest.

Setup

The DORM has a simple setup page, which can be found at DORM/Includes/Setup.php

use DORM\Database\DBHandler;
use DORM\Includes\Setup;

include_once 'DORM/autoload.php';

new Setup();

API Endpoint

You can use the DORM API anywhere, such as in your api.php file located in the root directory of the example.com/api.php website.

Just put this two line of Code

use DORM\API\API;
use DORM\Includes\Auth\Ignore;

include_once 'DORM/autoload.php';

new API(new Ignore(), '<my db config name from Config.php');

If you want to use token for authentification, give the api class a boolen true and set in the Config.php file you new token key.

#api.php
use DORM\API\API;
use DORM\Includes\Auth\SimpleToken;

include_once 'DORM/autoload.php';

new API(new SimpleToken(), '<my db config name from Config.php');


#DORM/Config/Config.php
...
class Config {

    public static $token = "<you-token-key>";
...

POST Request

The basic SQL CRUD commands are implemented, but only with simple WHERE and SET clauses. As in the example Shema respectively

{
  "schema": "DORM 0.0.6",
  "token": "123456",
  "jobs": [
    {
      "job": "read",
      "columns": [
        { "column": "<column_name>" },
        { "column": "<column_name>" }
      ],
      "from": "<table_name>",
      "join":[
        { 
          "<table_name>": "<column_name>",
          "<table_name>": "<column_name>"
        }
      ],
      "order": { "column": "<column_name>", "sort": "DESC" },
      "limit": 1000, 
      "embed": [
        { "table": "<table_name>" }
      ]
    },
  ]
}

Response

Here is an example response, more info in the docu

{ 
  "body": {
      "ovc": {
        "rows": [
            {
                "person_id": "22",
                "ovc_number": "23232132132",
                "ovc_status": null,
                "generate_income": "Yes",
                "lead_child": "0",
            },
        ]
      },
      "references": {
              "caregiver": {
                  "column": "caregiver_id",
                  "referenced_column": "person_id"
              }
          }
  },
  "errors" : []      
}

Exceptions and Logs

With the API calls all exceptions are intercepted, however these are not always meaningful on the client side, therefore activate logs and look in there. In the config you can activate the logging of errors and set the path to the file, see Config.sample.php

    /*
    * Default is false, if true, then it is important that a log path exists and write permissions are available 
    */
    static public $logErrors = false;
    
    /*
    * Path to the log incl. file name, example command for write permission: chown -R www-data Logs
    */
    static public $paths = [
        'logs' => __DIR__ . '/../Logs/errors.log'
    ];

Inspiration for the custom Query Builder by https://github.com/devcoder-xyz/php-query-builder

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published