-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX] Забыл добавить файлы класса и обновлённый файл функций. Хотел ка…
…к лучше, через композер, но получилось как всегда
- Loading branch information
Showing
6 changed files
with
518 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
class PDOIterator implements Iterator { | ||
private $position = 0; | ||
private $pdo; | ||
private $fetchMode; | ||
private $nextResult; | ||
|
||
public function __construct(PDOStatement $pdo, $fetchMode = PDO::FETCH_ASSOC) { | ||
$this->position = 0; | ||
$this->pdo = $pdo; | ||
$this->fetchMode = $fetchMode; | ||
} | ||
|
||
function rewind() { | ||
$this->position = 0; | ||
$this->pdo->execute(); | ||
$this->nextResult = $this->pdo->fetch($this->fetchMode, PDO::FETCH_ORI_NEXT); | ||
} | ||
|
||
function current() { | ||
return $this->nextResult; | ||
} | ||
|
||
function key() { | ||
return $this->position; | ||
} | ||
|
||
function next() { | ||
++$this->position; | ||
$this->nextResult = $this->pdo->fetch($this->fetchMode, PDO::FETCH_ORI_NEXT); | ||
} | ||
|
||
function valid() { | ||
$invalid = $this->nextResult === false; | ||
if ($invalid) { | ||
$this->pdo->closeCursor(); | ||
} | ||
return !$invalid; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
class PDOLog | ||
{ | ||
private $path = '/logs/'; | ||
public function __construct() | ||
{ | ||
$this->path = __DIR__ . $this->path; | ||
} | ||
|
||
public function write($message, $fileSalt) | ||
{ | ||
$date = new DateTime(); | ||
$log = $this->path . $date->format('Y-m-d') . "-" . md5($date->format('Y-m-d') . $fileSalt) . ".txt"; | ||
if (is_dir($this->path)) { | ||
if (!file_exists($log)) { | ||
$fh = fopen($log, 'a+') or die("Fatal Error !"); | ||
$logcontent = "Time : " . $date->format('H:i:s') . "\r\n" . $message . "\r\n"; | ||
fwrite($fh, $logcontent); | ||
fclose($fh); | ||
} else { | ||
$this->edit($log, $date, $message); | ||
} | ||
} else { | ||
if (mkdir($this->path, 0777) === true) { | ||
$this->write($message, $fileSalt); | ||
} | ||
} | ||
} | ||
private function edit($log, DateTime $date, $message) | ||
{ | ||
$logcontent = "Time : " . $date->format('H:i:s') . "\r\n" . $message . "\r\n\r\n"; | ||
$logcontent = $logcontent . file_get_contents($log); | ||
file_put_contents($log, $logcontent); | ||
} | ||
} |
Oops, something went wrong.