Skip to content

Commit

Permalink
Feature composer (#7)
Browse files Browse the repository at this point in the history
* Create composer.json

* add basic configuration composer

* Update slsql.php

* Remove src files

* Add src files

* Update Slsql.php

* Update composer.json

* Update Model

* Change config concept

* Fix : namespace problems
  • Loading branch information
Bastien Crettenand authored Jun 6, 2019
1 parent 0d5c335 commit 918937e
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 21 deletions.
10 changes: 10 additions & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php namespace slsql;

class Config
{
const dbType = 'mysql',
dbName = 'Default',
host = '127.0.0.1:3306',
user = 'root',
password = '';
}
2 changes: 2 additions & 0 deletions src/model/model.php → src/Model/Model.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php namespace slsql\Model;

use slsql\Slsql\Slsql;

/*
* WTFPL License (http://www.wtfpl.net/) - https: //github.com/CrBast/PHP-SQL_SimpleLife/blob/master/LICENSE
*
Expand Down
File renamed without changes.
File renamed without changes.
24 changes: 13 additions & 11 deletions src/slsql/slsql.php → src/Slsql/Slsql.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<?php namespace slqsl\slqsl;
<?php namespace slsql\Slsql;

use slsql\Config;
use \Error;
use \PDO;

/**
* WTFPL License (http://www.wtfpl.net/) - https: //github.com/CrBast/PHP-SQL_SimpleLife/blob/master/LICENSE
Expand Down Expand Up @@ -114,7 +118,7 @@ public function createDB()

/**
* Send Request.
* the parameters are in the .env file
* the parameters are in the Config class file (slsql\Config)
*
* Return :
* [value] = result,
Expand All @@ -124,7 +128,7 @@ public function createDB()
public static function go($request, $array = array())
{
try {
$db = slsql::getPDO();
$db = Slsql::getPDO();
$stmt = $db->prepare($request);
$stmt->execute($array);
//var_dump($stmt);
Expand All @@ -137,7 +141,7 @@ public static function go($request, $array = array())

/**
* Send Transaction.
* the parameters are in the .env file
* the parameters are in the Config class file (slsql\Config)
*
* Return :
* [value] = result,
Expand All @@ -146,7 +150,7 @@ public static function go($request, $array = array())
*/
public static function goT(SLTransaction $trans)
{
$db = slsql::getPDO();
$db = Slsql::getPDO();
try {
$db->beginTransaction();
foreach ($trans->get() as $transaction) {
Expand All @@ -164,13 +168,11 @@ public static function goT(SLTransaction $trans)

private static function getPDO()
{
try {
require '../.env';
} catch (Exception $e) {
throw new Error("Error Processing Request");
if (!class_exists("\slsql\Config")) {
throw new Error("Cannot find <\slsql\Config>");
}
try {
$db = new PDO($env['DBType'] . ':dbname=' . $env['DBName'] . ';host=' . $env['Host'], $env['User'], $env['Password']);
$db = new PDO(Config::dbType . ':dbname=' . Config::dbName . ';host=' . Config::host, Config::user, Config::password);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $db;
} catch (PDOException $e) {
Expand All @@ -195,7 +197,7 @@ public function get()

public function go()
{
return slsql::goT($this);
return Slsql::goT($this);
}
}

Expand Down
File renamed without changes.
10 changes: 0 additions & 10 deletions src/example.env

This file was deleted.

0 comments on commit 918937e

Please sign in to comment.