Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 38 additions & 4 deletions src/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
* @copyright Copyright © 2022 Muhammet ŞAFAK
* @license ./LICENSE MIT
* @version 2.0
* @version 2.0.5
* @link https://www.muhammetsafak.com.tr
*/

Expand Down Expand Up @@ -59,6 +59,8 @@ class Database extends QueryBuilder
'deletable' => true,
'updatable' => true,
'return' => null,
'debug' => false,
'log' => null,
];

private Result $_last;
Expand Down Expand Up @@ -354,9 +356,13 @@ final public function query(string $sqlQuery, array $parameters = []): Result
}
} catch (\Exception $e) {
$message = $e->getMessage();
if(($this->_credentials['debug'] ?? false) === TRUE){
$message .= ' SQL : '
. (empty($parameters) ? $sqlQuery : \strtr($sqlQuery, $parameters));
$sqlMessage = 'SQL : '
. (empty($parameters) ? $sqlQuery : strtr($sqlQuery, $parameters));
if(!empty($this->_credentials['log'])){
$this->_logCreate($message . ' ' . $sqlMessage);
}
if($this->_credentials['debug'] === TRUE){
$message .= $message . ' ' . $sqlMessage;
}
throw new SQLQueryExecuteException($e->getMessage(), (int)$e->getCode());
}
Expand Down Expand Up @@ -801,6 +807,34 @@ public function _deleteQuery(): string
. $this->_limitQuery();
}

protected function _logCreate(string $message): void
{
if(empty($this->_credentials['log'])){
return;
}
if(\is_callable($this->_credentials['log'])){
\call_user_func_array($this->_credentials['log'], [$message]);
return;
}
if(\is_string($this->_credentials['log'])){
$path = \strtr($this->_credentials['log'], [
'{timestamp}' => \time(),
'{date}' => \date("Y-m-d"),
'{year}' => \date("Y"),
'{month}' => \date("m"),
'{day}' => \date("d"),
'{hour}' => \date("H"),
'{minute}' => \date("i"),
'{second}' => \date("s"),
]);
@\file_put_contents($path, $message, \FILE_APPEND);
return;
}
if(\is_object($this->_credentials['log']) && \method_exists($this->_credentials['log'], 'critical')){
$this->_credentials['log']->critical($message);
}
}

private function _whereQuery(): string
{
$isAndEmpty = empty($this->_STRUCTURE['where']['AND']);
Expand Down
2 changes: 1 addition & 1 deletion src/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
* @copyright Copyright © 2022 Muhammet ŞAFAK
* @license ./LICENSE MIT
* @version 2.0
* @version 2.0.5
* @link https://www.muhammetsafak.com.tr
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/ConnectionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
* @copyright Copyright © 2022 Muhammet ŞAFAK
* @license ./LICENSE MIT
* @version 2.0
* @version 2.0.5
* @link https://www.muhammetsafak.com.tr
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/DeletableException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
* @copyright Copyright © 2022 Muhammet ŞAFAK
* @license ./LICENSE MIT
* @version 2.0
* @version 2.0.5
* @link https://www.muhammetsafak.com.tr
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/ModelCallbacksException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
* @copyright Copyright © 2022 Muhammet ŞAFAK
* @license ./LICENSE MIT
* @version 2.0
* @version 2.0.5
* @link https://www.muhammetsafak.com.tr
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/ModelException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
* @copyright Copyright © 2022 Muhammet ŞAFAK
* @license ./LICENSE MIT
* @version 2.0
* @version 2.0.5
* @link https://www.muhammetsafak.com.tr
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/ModelRelationsException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
* @copyright Copyright © 2022 Muhammet ŞAFAK
* @license ./LICENSE MIT
* @version 2.0
* @version 2.0.5
* @link https://www.muhammetsafak.com.tr
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/ReadableException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
* @copyright Copyright © 2022 Muhammet ŞAFAK
* @license ./LICENSE MIT
* @version 2.0
* @version 2.0.5
* @link https://www.muhammetsafak.com.tr
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/SQLQueryExecuteException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
* @copyright Copyright © 2022 Muhammet ŞAFAK
* @license ./LICENSE MIT
* @version 2.0
* @version 2.0.5
* @link https://www.muhammetsafak.com.tr
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/UpdatableException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
* @copyright Copyright © 2022 Muhammet ŞAFAK
* @license ./LICENSE MIT
* @version 2.0
* @version 2.0.5
* @link https://www.muhammetsafak.com.tr
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/ValidationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
* @copyright Copyright © 2022 Muhammet ŞAFAK
* @license ./LICENSE MIT
* @version 2.0
* @version 2.0.5
* @link https://www.muhammetsafak.com.tr
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/WritableException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
* @copyright Copyright © 2022 Muhammet ŞAFAK
* @license ./LICENSE MIT
* @version 2.0
* @version 2.0.5
* @link https://www.muhammetsafak.com.tr
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Facade/DB.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
* @copyright Copyright © 2022 Muhammet ŞAFAK
* @license ./LICENSE MIT
* @version 2.0
* @version 2.0.5
* @link https://www.muhammetsafak.com.tr
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Helpers/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
* @copyright Copyright © 2022 Muhammet ŞAFAK
* @license ./LICENSE MIT
* @version 2.0
* @version 2.0.5
* @link https://www.muhammetsafak.com.tr
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Helpers/Parameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
* @copyright Copyright © 2022 Muhammet ŞAFAK
* @license ./LICENSE MIT
* @version 2.0
* @version 2.0.5
* @link https://www.muhammetsafak.com.tr
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Helpers/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
* @copyright Copyright © 2022 Muhammet ŞAFAK
* @license ./LICENSE MIT
* @version 2.0
* @version 2.0.5
* @link https://www.muhammetsafak.com.tr
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Init.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
* @copyright Copyright © 2022 Muhammet ŞAFAK
* @license ./LICENSE MIT
* @version 2.0
* @version 2.0.5
* @link https://www.muhammetsafak.com.tr
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
* @copyright Copyright © 2022 Muhammet ŞAFAK
* @license ./LICENSE MIT
* @version 2.0
* @version 2.0.5
* @link https://www.muhammetsafak.com.tr
*/

Expand Down
2 changes: 1 addition & 1 deletion src/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
* @copyright Copyright © 2022 Muhammet ŞAFAK
* @license ./LICENSE MIT
* @version 2.0
* @version 2.0.5
* @link https://www.muhammetsafak.com.tr
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Raw.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
* @copyright Copyright © 2022 Muhammet ŞAFAK
* @license ./LICENSE MIT
* @version 2.0
* @version 2.0.5
* @link https://www.muhammetsafak.com.tr
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
* @copyright Copyright © 2022 Muhammet ŞAFAK
* @license ./LICENSE MIT
* @version 2.0
* @version 2.0.5
* @link https://www.muhammetsafak.com.tr
*/

Expand Down