| @@ -1,9 +1,9 @@ | ||
| 1 | 1 | <?php | 
| 2 | 2 |    interface ConnectionAdapterInterface { | 
| 3 | - public function __construct( $_srv, $_db, $_usr, $_pass); | |
| 4 | - public function query( $_query ); | |
| 5 | - public function queryFetch( $_query ); | |
| 6 | - public function queryArray( $_query ); | |
| 7 | - public function queryInsert( $_query ); | |
| 3 | + public function __construct( $_srv, $_db, $_usr, $_pass); | |
| 4 | + public function query( $_query ); | |
| 5 | + public function queryFetch( $_query ); | |
| 6 | + public function queryArray( $_query ); | |
| 7 | + public function queryInsert( $_query ); | |
| 8 | 8 | } | 
| 9 | 9 | ?> | 
| @@ -1,45 +1,45 @@ | ||
| 1 | 1 | <?php | 
| 2 | 2 |    function subFolder( $_dir = "./" ) { | 
| 3 | -    $temp = fetchInSubFolder($_dir, function() { | |
| 4 | - return true; | |
| 5 | - }); | |
| 6 | - return $temp; | |
| 3 | +	$temp = fetchInSubFolder($_dir, function() { | |
| 4 | + return true; | |
| 5 | + }); | |
| 6 | + return $temp; | |
| 7 | 7 | } | 
| 8 | 8 |    function subFolderFile( $_dir = "./" ) { | 
| 9 | -    $temp = fetchInSubFolder($_dir, function( $_file ) { | |
| 10 | - return !is_dir($_file); | |
| 11 | - }); | |
| 12 | - return $temp; | |
| 9 | +	$temp = fetchInSubFolder($_dir, function( $_file ) { | |
| 10 | + return !is_dir($_file); | |
| 11 | + }); | |
| 12 | + return $temp; | |
| 13 | 13 | } | 
| 14 | 14 |    function subFolderDir( $_dir = "./" ) { | 
| 15 | -    $temp = fetchInSubFolder($_dir, function( $_file ) { | |
| 16 | - return !is_file($_file); | |
| 17 | - }); | |
| 18 | - return $temp; | |
| 15 | +	$temp = fetchInSubFolder($_dir, function( $_file ) { | |
| 16 | + return !is_file($_file); | |
| 17 | + }); | |
| 18 | + return $temp; | |
| 19 | 19 | } | 
| 20 | 20 |    function fetchInSubFolder( $_dir = "./", $_function) { | 
| 21 | - $temp = []; | |
| 22 | -    if (is_dir($_dir)) { | |
| 23 | -        if ($dirOpened = opendir($_dir)) { | |
| 24 | - while (($file = readdir($dirOpened)) !== false) | |
| 25 | - if( ($file !='.')&&($file !='..') ) | |
| 26 | - if($_function($file)) | |
| 27 | - array_push($temp,$file); | |
| 28 | - closedir($dirOpened); | |
| 29 | - } | |
| 30 | - } | |
| 31 | - return $temp; | |
| 21 | + $temp = []; | |
| 22 | +	if (is_dir($_dir)) { | |
| 23 | +		if ($dirOpened = opendir($_dir)) { | |
| 24 | + while (($file = readdir($dirOpened)) !== false) | |
| 25 | + if( ($file !='.')&&($file !='..') ) | |
| 26 | + if($_function($file)) | |
| 27 | + array_push($temp,$file); | |
| 28 | + closedir($dirOpened); | |
| 29 | + } | |
| 30 | + } | |
| 31 | + return $temp; | |
| 32 | 32 | } | 
| 33 | 33 |    function requireSubfolder( $_dir = "./" ) { | 
| 34 | - $temp = subFolderFile($_dir); | |
| 35 | - foreach ($temp as $i) | |
| 36 | - jRequire($_dir."/".$i); | |
| 34 | + $temp = subFolderFile($_dir); | |
| 35 | + foreach ($temp as $i) | |
| 36 | + jRequire($_dir."/".$i); | |
| 37 | 37 | } | 
| 38 | 38 |    function require_js( $_dir = "./" ) { | 
| 39 | - $tempArray = []; | |
| 40 | - $temp = subFolderFile($_dir); | |
| 41 | - foreach ($temp as $i) | |
| 42 | - array_push($tempArray, $_dir."/".$i); | |
| 43 | - return $tempArray; | |
| 39 | + $tempArray = []; | |
| 40 | + $temp = subFolderFile($_dir); | |
| 41 | + foreach ($temp as $i) | |
| 42 | + array_push($tempArray, $_dir."/".$i); | |
| 43 | + return $tempArray; | |
| 44 | 44 | } | 
| 45 | 45 | ?> | 
| @@ -1,21 +1,21 @@ | ||
| 1 | 1 | <?php | 
| 2 | 2 | if(!isset($GLOBALS["JATEPath"])) | 
| 3 | - $GLOBALS["JATEPath"] = []; | |
| 3 | + $GLOBALS["JATEPath"] = []; | |
| 4 | 4 | $commonLocations = [ | 
| 5 | - "bower_components/JATE/dist/" | |
| 6 | - , "vendor/xaberr/jate/dist/" | |
| 7 | - , "../../dist/" | |
| 8 | - , "../dist/" | |
| 9 | - , dirname(__FILE__)."/" | |
| 5 | + "bower_components/JATE/dist/" | |
| 6 | + , "vendor/xaberr/jate/dist/" | |
| 7 | + , "../../dist/" | |
| 8 | + , "../dist/" | |
| 9 | + , dirname(__FILE__)."/" | |
| 10 | 10 | ]; | 
| 11 | 11 | $jSuccess = false; | 
| 12 | 12 | foreach ($commonLocations as $path) | 
| 13 | -    if(file_exists("${path}jate/coreEngine.php")) { | |
| 14 | - array_push($GLOBALS["JATEPath"], $path); | |
| 15 | -      require_once("${path}jate/coreEngine.php"); | |
| 16 | - $jSuccess = true; | |
| 17 | - break; | |
| 18 | - } | |
| 13 | +	if(file_exists("${path}jate/coreEngine.php")) { | |
| 14 | + array_push($GLOBALS["JATEPath"], $path); | |
| 15 | +	  require_once("${path}jate/coreEngine.php"); | |
| 16 | + $jSuccess = true; | |
| 17 | + break; | |
| 18 | + } | |
| 19 | 19 | if( !$jSuccess ) | 
| 20 | -    throw new Exception("JATE can't find coreEngine.php."); | |
| 20 | +	throw new Exception("JATE can't find coreEngine.php."); | |
| 21 | 21 | ?> | 
| @@ -1,64 +1,64 @@ | ||
| 1 | 1 | <?php | 
| 2 | 2 |    function requireComponent( $_path, $_local = true ) { | 
| 3 | - $path = getJFolder($_path, $_local, debug_backtrace()); | |
| 4 | - if(file_exists($path) && isPhp($path)) | |
| 5 | - jRequire($path, false, 0); | |
| 6 | - else | |
| 7 | - requireError($_path); | |
| 3 | + $path = getJFolder($_path, $_local, debug_backtrace()); | |
| 4 | + if(file_exists($path) && isPhp($path)) | |
| 5 | + jRequire($path, false, 0); | |
| 6 | + else | |
| 7 | + requireError($_path); | |
| 8 | 8 | } | 
| 9 | 9 |    function requireComponents( $_path, $_local = true ) { | 
| 10 | - $path = getJFolder($_path, $_local, debug_backtrace()); | |
| 11 | -    if(file_exists($path)) { | |
| 12 | - $files = subFolderFile($path); | |
| 13 | - foreach ($files as $i) | |
| 14 | -        if(isPhp("$path/$i")) | |
| 15 | - requireComponent($path."/".$i, false); | |
| 16 | - } else | |
| 17 | - requireError($_path); | |
| 10 | + $path = getJFolder($_path, $_local, debug_backtrace()); | |
| 11 | +	if(file_exists($path)) { | |
| 12 | + $files = subFolderFile($path); | |
| 13 | + foreach ($files as $i) | |
| 14 | +		if(isPhp("$path/$i")) | |
| 15 | + requireComponent($path."/".$i, false); | |
| 16 | + } else | |
| 17 | + requireError($_path); | |
| 18 | 18 | } | 
| 19 | 19 |    function requireError( $_path ) { | 
| 20 | - global $DEBUG; | |
| 21 | - if( $DEBUG == 1 ) | |
| 22 | - echo "Error load ($_path)<br>"; | |
| 20 | + global $DEBUG; | |
| 21 | + if( $DEBUG == 1 ) | |
| 22 | + echo "Error load ($_path)<br>"; | |
| 23 | 23 | } | 
| 24 | 24 |    function isPhp ( $_file ) { | 
| 25 | - if(!is_file($_file)) return false; | |
| 26 | - $info = pathinfo($_file); | |
| 27 | - return ($info["extension"] == "php") || ($info["extension"] == "PHP"); | |
| 25 | + if(!is_file($_file)) return false; | |
| 26 | + $info = pathinfo($_file); | |
| 27 | + return ($info["extension"] == "php") || ($info["extension"] == "PHP"); | |
| 28 | 28 | } | 
| 29 | 29 |    function requireModules( $_path, $_local = true ) { | 
| 30 | - $path = getJFolder($_path, $_local, debug_backtrace()); | |
| 31 | - $subFolders = subFolderDir($path); | |
| 32 | - foreach ($subFolders as $i) | |
| 33 | -      requireComponents("$path/$i", false); | |
| 30 | + $path = getJFolder($_path, $_local, debug_backtrace()); | |
| 31 | + $subFolders = subFolderDir($path); | |
| 32 | + foreach ($subFolders as $i) | |
| 33 | +	  requireComponents("$path/$i", false); | |
| 34 | 34 | } | 
| 35 | 35 |    function jRequire( $_path, $_local = true ) { | 
| 36 | - $path = getJFolder($_path, $_local, debug_backtrace()); | |
| 37 | - require_once( $path ); | |
| 36 | + $path = getJFolder($_path, $_local, debug_backtrace()); | |
| 37 | + require_once( $path ); | |
| 38 | 38 | } | 
| 39 | 39 |    function getJFolder( $_path, $_local, $_stack ) { | 
| 40 | -    if($_local) { | |
| 41 | - $stackInfo = $_stack; | |
| 42 | - $folder = dirname($stackInfo[0]["file"]); | |
| 43 | - $file = "$folder/$_path"; | |
| 44 | - } else | |
| 45 | - $file = $_path; | |
| 46 | - return $file; | |
| 40 | +	if($_local) { | |
| 41 | + $stackInfo = $_stack; | |
| 42 | + $folder = dirname($stackInfo[0]["file"]); | |
| 43 | + $file = "$folder/$_path"; | |
| 44 | + } else | |
| 45 | + $file = $_path; | |
| 46 | + return $file; | |
| 47 | 47 | } | 
| 48 | 48 |    function requireModulesList( $_path ) { | 
| 49 | - if(!file_exists($_path)) | |
| 50 | - return; | |
| 51 | - $data = file_get_contents($_path); | |
| 52 | - $data = json_decode($data); | |
| 53 | - if($data === NULL) | |
| 54 | -      throw new Exception("Error in the file format [$_path]", 1); | |
| 55 | -    foreach ($data as $item) { | |
| 56 | - if(substr($item, -1) == "*") | |
| 57 | - requireModules(substr($item, 0, -2), false); | |
| 58 | -      else { | |
| 59 | - $path = getJFolder($item, false, debug_backtrace()); | |
| 60 | -        requireComponents("$path", false); | |
| 61 | - } | |
| 62 | - } | |
| 49 | + if(!file_exists($_path)) | |
| 50 | + return; | |
| 51 | + $data = file_get_contents($_path); | |
| 52 | + $data = json_decode($data); | |
| 53 | + if($data === NULL) | |
| 54 | +	  throw new Exception("Error in the file format [$_path]", 1); | |
| 55 | +	foreach ($data as $item) { | |
| 56 | + if(substr($item, -1) == "*") | |
| 57 | + requireModules(substr($item, 0, -2), false); | |
| 58 | +	  else { | |
| 59 | + $path = getJFolder($item, false, debug_backtrace()); | |
| 60 | +		requireComponents("$path", false); | |
| 61 | + } | |
| 62 | + } | |
| 63 | 63 | } | 
| 64 | 64 | ?> | 
| @@ -2,46 +2,46 @@ | ||
| 2 | 2 |    jRequire("../modules/Parser/Parser.php"); | 
| 3 | 3 |    jRequire("../modules/JException/JException.php"); | 
| 4 | 4 |    function jBlock() { | 
| 5 | - return ob_start(); | |
| 5 | + return ob_start(); | |
| 6 | 6 | } | 
| 7 | 7 | |
| 8 | 8 |    function jBlockClose( $_type = "html", $_parameters = [] ) { | 
| 9 | - return jBlockEnd($_type, $_parameters); | |
| 9 | + return jBlockEnd($_type, $_parameters); | |
| 10 | 10 | } | 
| 11 | 11 | |
| 12 | 12 |    function jBlockFile( $_path, $_parameters = [] ) { | 
| 13 | -    try { | |
| 14 | - $temp = Parser::parseFile($_path, $_parameters); | |
| 15 | -    } catch (Exception $e) { | |
| 16 | - throw new JException($e->getMessage()); | |
| 17 | - } | |
| 18 | - return $temp; | |
| 13 | +	try { | |
| 14 | + $temp = Parser::parseFile($_path, $_parameters); | |
| 15 | +	} catch (Exception $e) { | |
| 16 | + throw new JException($e->getMessage()); | |
| 17 | + } | |
| 18 | + return $temp; | |
| 19 | 19 | } | 
| 20 | 20 | |
| 21 | 21 |    function jBlockFileMan( $_path, $_type, $_parameters = [] ) { | 
| 22 | -    try { | |
| 23 | - $temp = Parser::parseFileMan($_path, $_parameters, $_type); | |
| 24 | -    } catch (Exception $e) { | |
| 25 | - throw new JException($e->getMessage()); | |
| 26 | - } | |
| 27 | - return $temp; | |
| 22 | +	try { | |
| 23 | + $temp = Parser::parseFileMan($_path, $_parameters, $_type); | |
| 24 | +	} catch (Exception $e) { | |
| 25 | + throw new JException($e->getMessage()); | |
| 26 | + } | |
| 27 | + return $temp; | |
| 28 | 28 | } | 
| 29 | 29 | |
| 30 | 30 |    function jBlockEnd( $_type = "html", $_parameters = [] ) { | 
| 31 | - $text = ob_get_clean(); | |
| 32 | -    try { | |
| 33 | - $temp = Parser::parseText($text, $_parameters, $_type); | |
| 34 | -    } catch (Exception $e) { | |
| 35 | - throw new JException($e->getMessage()); | |
| 36 | - } | |
| 37 | - return $temp; | |
| 31 | + $text = ob_get_clean(); | |
| 32 | +	try { | |
| 33 | + $temp = Parser::parseText($text, $_parameters, $_type); | |
| 34 | +	} catch (Exception $e) { | |
| 35 | + throw new JException($e->getMessage()); | |
| 36 | + } | |
| 37 | + return $temp; | |
| 38 | 38 | } | 
| 39 | 39 | |
| 40 | 40 |    function minifyOutput($_buffer) { | 
| 41 | - $search = array ( '/\>[^\S ]+/s', '/[^\S ]+\</s', '/(\s)+/s' ); | |
| 42 | - $replace = array ( '>', '<', '\\1' ); | |
| 43 | -    if (preg_match("/\<html/i",$_buffer) == 1 && preg_match("/\<\/html\>/i",$_buffer) == 1) | |
| 44 | - $_buffer = preg_replace($search, $replace, utf8_decode($_buffer)); | |
| 45 | - return utf8_encode($_buffer); | |
| 41 | + $search = array ( '/\>[^\S ]+/s', '/[^\S ]+\</s', '/(\s)+/s' ); | |
| 42 | + $replace = array ( '>', '<', '\\1' ); | |
| 43 | +	if (preg_match("/\<html/i",$_buffer) == 1 && preg_match("/\<\/html\>/i",$_buffer) == 1) | |
| 44 | + $_buffer = preg_replace($search, $replace, utf8_decode($_buffer)); | |
| 45 | + return utf8_encode($_buffer); | |
| 46 | 46 | } | 
| 47 | 47 | ?> | 
| @@ -1,51 +1,51 @@ | ||
| 1 | 1 | <?php | 
| 2 | 2 |    function utf8ize($_array) { | 
| 3 | - return travelStringArray($_array,"utf8_encode"); | |
| 3 | + return travelStringArray($_array,"utf8_encode"); | |
| 4 | 4 | } | 
| 5 | 5 |    function unutf8ize($_array) { | 
| 6 | - return travelStringArray($_array,"utf8_decode"); | |
| 6 | + return travelStringArray($_array,"utf8_decode"); | |
| 7 | 7 | } | 
| 8 | 8 |    function arraySlash($_array) { | 
| 9 | - return travelStringArray($_array,"addslashes"); | |
| 9 | + return travelStringArray($_array,"addslashes"); | |
| 10 | 10 | } | 
| 11 | 11 |    function arrayHtmlParser($_array) { | 
| 12 | - return travelStringArray($_array,"htmlParser"); | |
| 12 | + return travelStringArray($_array,"htmlParser"); | |
| 13 | 13 | } | 
| 14 | 14 |    function travelStringArray ( $_array, $_function ) { | 
| 15 | -    if (is_array($_array)) { | |
| 16 | -      foreach ($_array as $k => $v) { | |
| 17 | - $_array[$k] = travelStringArray($v, $_function); | |
| 18 | - } | |
| 19 | -    } else if (is_string ($_array)) { | |
| 20 | - return call_user_func($_function,$_array); | |
| 21 | - } | |
| 22 | - return $_array; | |
| 15 | +	if (is_array($_array)) { | |
| 16 | +	  foreach ($_array as $k => $v) { | |
| 17 | + $_array[$k] = travelStringArray($v, $_function); | |
| 18 | + } | |
| 19 | +	} else if (is_string ($_array)) { | |
| 20 | + return call_user_func($_function,$_array); | |
| 21 | + } | |
| 22 | + return $_array; | |
| 23 | 23 | } | 
| 24 | 24 |    function arrayDepth( $_array ) { | 
| 25 | - $maxDepth = 1; | |
| 26 | -    foreach ($_array as $value) { | |
| 27 | -      if (is_array($value)) { | |
| 28 | - $depth = arrayDepth($value) + 1; | |
| 29 | -        if ($depth > $maxDepth) { | |
| 30 | - $maxDepth = $depth; | |
| 31 | - } | |
| 32 | - } | |
| 33 | - } | |
| 34 | - return $maxDepth; | |
| 25 | + $maxDepth = 1; | |
| 26 | +	foreach ($_array as $value) { | |
| 27 | +	  if (is_array($value)) { | |
| 28 | + $depth = arrayDepth($value) + 1; | |
| 29 | +		if ($depth > $maxDepth) { | |
| 30 | + $maxDepth = $depth; | |
| 31 | + } | |
| 32 | + } | |
| 33 | + } | |
| 34 | + return $maxDepth; | |
| 35 | 35 | } | 
| 36 | 36 |    function arrayDump( $_array, $_name = "Array", $_tab = "  " ) { | 
| 37 | -    $position = preg_replace('/  /', '', $_tab, 1); | |
| 38 | - echo "$position<span style=\"color:rgb(230,0,0)\">$_name:</span><br>"; | |
| 39 | - foreach ($_array as $k => $i) | |
| 40 | - if(is_array($i)) | |
| 41 | - arrayDump( $i, $k, "  $_tab" ); | |
| 42 | - else if(is_object($i)) | |
| 43 | - echo "$_tab<b>object:</b> [Object]<br>"; | |
| 44 | - else | |
| 45 | - echo "$_tab<b>$k:</b> $i<br>"; | |
| 37 | +	$position = preg_replace('/  /', '', $_tab, 1); | |
| 38 | + echo "$position<span style=\"color:rgb(230,0,0)\">$_name:</span><br>"; | |
| 39 | + foreach ($_array as $k => $i) | |
| 40 | + if(is_array($i)) | |
| 41 | + arrayDump( $i, $k, "  $_tab" ); | |
| 42 | + else if(is_object($i)) | |
| 43 | + echo "$_tab<b>object:</b> [Object]<br>"; | |
| 44 | + else | |
| 45 | + echo "$_tab<b>$k:</b> $i<br>"; | |
| 46 | 46 | } | 
| 47 | 47 | |
| 48 | 48 |    function htmlParser( $_str) { | 
| 49 | - return htmlentities($_str, ENT_QUOTES | ENT_IGNORE, "UTF-8"); | |
| 49 | + return htmlentities($_str, ENT_QUOTES | ENT_IGNORE, "UTF-8"); | |
| 50 | 50 | } | 
| 51 | 51 | ?> | 
| @@ -1,11 +1,11 @@ discard block | ||
| 1 | 1 | <?php | 
| 2 | 2 |    function jateErrorHandler($number, $message, $file, $line) { | 
| 3 | -    if (!(error_reporting() & $number)) { | |
| 4 | - return false; | |
| 5 | - } | |
| 6 | - ob_end_clean(); | |
| 7 | - $message = JException::decode($message); | |
| 8 | - echo " | |
| 3 | +	if (!(error_reporting() & $number)) { | |
| 4 | + return false; | |
| 5 | + } | |
| 6 | + ob_end_clean(); | |
| 7 | + $message = JException::decode($message); | |
| 8 | + echo " | |
| 9 | 9 | <div id='error'> | 
| 10 | 10 | <header> | 
| 11 | 11 | JATE ERROR | 
| @@ -51,14 +51,14 @@ discard block | ||
| 51 | 51 | } | 
| 52 | 52 | </style> | 
| 53 | 53 | "; | 
| 54 | - exit(1); | |
| 55 | - return true; | |
| 54 | + exit(1); | |
| 55 | + return true; | |
| 56 | 56 | } | 
| 57 | 57 |    function fatalErrorShutdownHandler() { | 
| 58 | - $last_error = error_get_last(); | |
| 59 | -    if ($last_error['type'] === E_ERROR) { | |
| 60 | - jateErrorHandler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']); | |
| 61 | - } | |
| 58 | + $last_error = error_get_last(); | |
| 59 | +	if ($last_error['type'] === E_ERROR) { | |
| 60 | + jateErrorHandler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']); | |
| 61 | + } | |
| 62 | 62 | } | 
| 63 | 63 |    set_error_handler('jateErrorHandler'); | 
| 64 | 64 |    register_shutdown_function('fatalErrorShutdownHandler'); | 
| @@ -1,42 +1,42 @@ | ||
| 1 | 1 | <?php | 
| 2 | 2 |    requireComponents("Adapters"); | 
| 3 | 3 |    class Connection { | 
| 4 | - public $database; | |
| 5 | - public $info; | |
| 6 | -    public function __construct( $_object ) { | |
| 7 | - if(!is_object($_object)) | |
| 8 | -        throw new InvalidArgumentException("Parameter must be an object."); | |
| 9 | - $this->setConnection( | |
| 10 | - $_object->server, | |
| 11 | - $_object->database, | |
| 12 | - $_object->user, | |
| 13 | - $_object->password, | |
| 14 | - $this->getConnectionType($_object->engine) | |
| 15 | - ); | |
| 16 | - } | |
| 17 | -    protected function setConnection ( $_srv, $_db, $_usr, $_pass, $_type ) { | |
| 18 | -      switch ($_type) { | |
| 19 | - case "mysqli": | |
| 20 | - $this->database = new MysqliAdapter($_srv, $_db, $_usr, $_pass); | |
| 21 | - break; | |
| 22 | - case "postgresql": | |
| 23 | - $this->database = new PostgresqlAdapter($_srv, $_db, $_usr, $_pass); | |
| 24 | - break; | |
| 25 | - case "memory": | |
| 26 | - $this->database = new PdoMemoryAdapter($_srv, $_db, $_usr, $_pass); | |
| 27 | - break; | |
| 28 | - case "pdo": | |
| 29 | - default: | |
| 30 | - $this->database = new PdoAdapter($_srv, $_db, $_usr, $_pass); | |
| 31 | - break; | |
| 32 | - } | |
| 33 | - } | |
| 34 | -    protected function getConnectionType( $_type ) { | |
| 35 | - $array = (array)$_type; | |
| 36 | - foreach ($array as $key => $value) | |
| 37 | - if($value) | |
| 38 | - return $key; | |
| 39 | - return "pdo"; | |
| 40 | - } | |
| 4 | + public $database; | |
| 5 | + public $info; | |
| 6 | +	public function __construct( $_object ) { | |
| 7 | + if(!is_object($_object)) | |
| 8 | +		throw new InvalidArgumentException("Parameter must be an object."); | |
| 9 | + $this->setConnection( | |
| 10 | + $_object->server, | |
| 11 | + $_object->database, | |
| 12 | + $_object->user, | |
| 13 | + $_object->password, | |
| 14 | + $this->getConnectionType($_object->engine) | |
| 15 | + ); | |
| 16 | + } | |
| 17 | +	protected function setConnection ( $_srv, $_db, $_usr, $_pass, $_type ) { | |
| 18 | +	  switch ($_type) { | |
| 19 | + case "mysqli": | |
| 20 | + $this->database = new MysqliAdapter($_srv, $_db, $_usr, $_pass); | |
| 21 | + break; | |
| 22 | + case "postgresql": | |
| 23 | + $this->database = new PostgresqlAdapter($_srv, $_db, $_usr, $_pass); | |
| 24 | + break; | |
| 25 | + case "memory": | |
| 26 | + $this->database = new PdoMemoryAdapter($_srv, $_db, $_usr, $_pass); | |
| 27 | + break; | |
| 28 | + case "pdo": | |
| 29 | + default: | |
| 30 | + $this->database = new PdoAdapter($_srv, $_db, $_usr, $_pass); | |
| 31 | + break; | |
| 32 | + } | |
| 33 | + } | |
| 34 | +	protected function getConnectionType( $_type ) { | |
| 35 | + $array = (array)$_type; | |
| 36 | + foreach ($array as $key => $value) | |
| 37 | + if($value) | |
| 38 | + return $key; | |
| 39 | + return "pdo"; | |
| 40 | + } | |
| 41 | 41 | } | 
| 42 | 42 | ?> | 
| @@ -1,44 +1,44 @@ | ||
| 1 | 1 | <?php | 
| 2 | 2 |    jRequire("ConnectionInterface.php"); | 
| 3 | 3 |    class PdoAdapter implements ConnectionAdapterInterface { | 
| 4 | - public $connection; | |
| 5 | -      public function __construct( $_srv, $_db, $_usr, $_pass ) { | |
| 6 | -        try { | |
| 7 | - $connection = "mysql:host=$_srv;dbname=$_db"; | |
| 8 | - $this->connection = new PDO( $connection, $_usr, $_pass, [PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'"] ); | |
| 9 | -        } catch( Exception $e ) { | |
| 10 | - throw new JException($e->getMessage()); | |
| 11 | - } | |
| 12 | - } | |
| 13 | -      public function query( $_query ) { | |
| 14 | - $this->stdQuery($_query); | |
| 15 | - return true; | |
| 16 | - } | |
| 17 | -      public function queryInsert( $_query ) { | |
| 18 | - $this->stdQuery($_query); | |
| 19 | - return $this->connection->lastInsertId(); | |
| 20 | - } | |
| 21 | -      public function queryFetch( $_query ) { | |
| 22 | - $temp = $this->stdQuery($_query); | |
| 23 | - return $temp->fetchAll(PDO::FETCH_ASSOC); | |
| 24 | - } | |
| 25 | -      public function queryArray( $_query ) { | |
| 26 | - $temp = $this->stdQuery($_query); | |
| 27 | - return $temp->fetchAll(PDO::FETCH_COLUMN, 0); | |
| 28 | - } | |
| 29 | -      protected function stdQuery( $_query ) { | |
| 30 | - $database = $this->connection; | |
| 31 | - $query = $database->prepare($_query); | |
| 32 | - $result = $query->execute(); | |
| 33 | - if(!$result) | |
| 34 | - throw new JException(json_encode([ | |
| 35 | - "query" => $_query, | |
| 36 | - "error" => [ | |
| 37 | - $query->errorInfo(), | |
| 38 | - $database->errorInfo() | |
| 39 | - ] | |
| 40 | - ])); | |
| 41 | - return $query; | |
| 42 | - } | |
| 4 | + public $connection; | |
| 5 | +	  public function __construct( $_srv, $_db, $_usr, $_pass ) { | |
| 6 | +		try { | |
| 7 | + $connection = "mysql:host=$_srv;dbname=$_db"; | |
| 8 | + $this->connection = new PDO( $connection, $_usr, $_pass, [PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'"] ); | |
| 9 | +		} catch( Exception $e ) { | |
| 10 | + throw new JException($e->getMessage()); | |
| 11 | + } | |
| 12 | + } | |
| 13 | +	  public function query( $_query ) { | |
| 14 | + $this->stdQuery($_query); | |
| 15 | + return true; | |
| 16 | + } | |
| 17 | +	  public function queryInsert( $_query ) { | |
| 18 | + $this->stdQuery($_query); | |
| 19 | + return $this->connection->lastInsertId(); | |
| 20 | + } | |
| 21 | +	  public function queryFetch( $_query ) { | |
| 22 | + $temp = $this->stdQuery($_query); | |
| 23 | + return $temp->fetchAll(PDO::FETCH_ASSOC); | |
| 24 | + } | |
| 25 | +	  public function queryArray( $_query ) { | |
| 26 | + $temp = $this->stdQuery($_query); | |
| 27 | + return $temp->fetchAll(PDO::FETCH_COLUMN, 0); | |
| 28 | + } | |
| 29 | +	  protected function stdQuery( $_query ) { | |
| 30 | + $database = $this->connection; | |
| 31 | + $query = $database->prepare($_query); | |
| 32 | + $result = $query->execute(); | |
| 33 | + if(!$result) | |
| 34 | + throw new JException(json_encode([ | |
| 35 | + "query" => $_query, | |
| 36 | + "error" => [ | |
| 37 | + $query->errorInfo(), | |
| 38 | + $database->errorInfo() | |
| 39 | + ] | |
| 40 | + ])); | |
| 41 | + return $query; | |
| 42 | + } | |
| 43 | 43 | } | 
| 44 | 44 | ?> |