Skip to content

Commit

Permalink
FIX] Забыл добавить файлы класса и обновлённый файл функций. Хотел ка…
Browse files Browse the repository at this point in the history
…к лучше, через композер, но получилось как всегда
  • Loading branch information
Gokujo committed Mar 17, 2023
1 parent e0d3d7d commit ae1caf6
Show file tree
Hide file tree
Showing 6 changed files with 518 additions and 3 deletions.
40 changes: 40 additions & 0 deletions upload/api/includes/PDO.Iterator.class.php
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;
}
}
35 changes: 35 additions & 0 deletions upload/api/includes/PDO.Log.class.php
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);
}
}
Loading

0 comments on commit ae1caf6

Please sign in to comment.