Skip to content

Commit

Permalink
Log için destek eklendi
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammetsafak committed Nov 18, 2022
1 parent aaca370 commit 0582bee
Show file tree
Hide file tree
Showing 21 changed files with 58 additions and 24 deletions.
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 <[email protected]>
* @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 <[email protected]>
* @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 <[email protected]>
* @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 <[email protected]>
* @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 <[email protected]>
* @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 <[email protected]>
* @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 <[email protected]>
* @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 <[email protected]>
* @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 <[email protected]>
* @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 <[email protected]>
* @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 <[email protected]>
* @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 <[email protected]>
* @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 <[email protected]>
* @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 <[email protected]>
* @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 <[email protected]>
* @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 <[email protected]>
* @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 <[email protected]>
* @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 <[email protected]>
* @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 <[email protected]>
* @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 <[email protected]>
* @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 <[email protected]>
* @copyright Copyright © 2022 Muhammet ŞAFAK
* @license ./LICENSE MIT
* @version 2.0
* @version 2.0.5
* @link https://www.muhammetsafak.com.tr
*/

Expand Down

0 comments on commit 0582bee

Please sign in to comment.