Compare commits
No commits in common. "stable" and "3.1.0" have entirely different histories.
|
@ -66,4 +66,4 @@ if ($database->write($record)) {
|
||||||
## Used by
|
## Used by
|
||||||
- My site-article about how i was kidnapped by PMC Wagner operatives [mirzaev/repression](https://git.svoboda.works/mirzaev/repression)
|
- My site-article about how i was kidnapped by PMC Wagner operatives [mirzaev/repression](https://git.svoboda.works/mirzaev/repression)
|
||||||
- My decentralized P2P blockchain chats project [mirzaev/notchat](https://git.svoboda.works/mirzaev/notchat)
|
- My decentralized P2P blockchain chats project [mirzaev/notchat](https://git.svoboda.works/mirzaev/notchat)
|
||||||
- Svoboda Telegram chat-robot negotiator [svoboda/negotiator](https://git.svoboda.works/svoboda/negotiator)
|
- Svoboda Telegram chat-robot [svoboda/negotiator](https://git.svoboda.works/svoboda/negotiator)
|
||||||
|
|
|
@ -368,13 +368,8 @@ class database
|
||||||
*
|
*
|
||||||
* @return array|null Readed records
|
* @return array|null Readed records
|
||||||
*/
|
*/
|
||||||
public function read(
|
public function read(?callable $filter = null, ?callable $update = null, bool $delete = false, int $amount = 1, int $offset = 0): ?array
|
||||||
?callable $filter = null,
|
{
|
||||||
?callable $update = null,
|
|
||||||
bool $delete = false,
|
|
||||||
int $amount = 1,
|
|
||||||
int $offset = 0
|
|
||||||
): ?array {
|
|
||||||
// Opening the database file
|
// Opening the database file
|
||||||
$file = fopen($this->database, 'c+b');
|
$file = fopen($this->database, 'c+b');
|
||||||
|
|
||||||
|
@ -465,14 +460,12 @@ class database
|
||||||
--$amount;
|
--$amount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// The record contains only empty values
|
// The record contains only empty values
|
||||||
}
|
}
|
||||||
} catch (exception_logic | exception_invalid_argument | exception_domain $exception) {
|
} catch (exception_logic | exception_invalid_argument $exception) {
|
||||||
// Writing into the buffer of failed to reading records
|
// Writing into the buffer of failed to reading records
|
||||||
|
/* $failed[] = $record; */
|
||||||
// Exit (fail)
|
|
||||||
throw new exception_runtime('Failed to processing the record', previous: $exception);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -490,25 +483,6 @@ class database
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Count
|
|
||||||
*
|
|
||||||
* @throws exception_runtime If the database is corrupted (counting result is float)
|
|
||||||
*
|
|
||||||
* @return int Amount of records
|
|
||||||
*/
|
|
||||||
public function count(): int
|
|
||||||
{
|
|
||||||
// Deleting the database file cache
|
|
||||||
clearstatcache(true, $this->database);
|
|
||||||
|
|
||||||
// Counting
|
|
||||||
$amount = $this->length > 0 && file_exists($this->database) ? filesize($this->database) / $this->length : 0;
|
|
||||||
|
|
||||||
// Exit (success/fail)
|
|
||||||
return is_int($amount) ? $amount : throw new exception_runtime('The database is corrupted');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Backups
|
* Backups
|
||||||
*
|
*
|
||||||
|
|
|
@ -4,9 +4,6 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace mirzaev\baza;
|
namespace mirzaev\baza;
|
||||||
|
|
||||||
// Built-in libraries
|
|
||||||
use DomainException as exception_domain;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Record
|
* Record
|
||||||
*
|
*
|
||||||
|
@ -66,23 +63,12 @@ class record
|
||||||
* @param string $name Name of the parameter
|
* @param string $name Name of the parameter
|
||||||
* @param mixed $value Content of the parameter
|
* @param mixed $value Content of the parameter
|
||||||
*
|
*
|
||||||
* @throws exception_domain if not found the parameter
|
|
||||||
*
|
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __set(string $name, mixed $value = null): void
|
public function __set(string $name, mixed $value = null): void
|
||||||
{
|
{
|
||||||
if (isset($this->values[$name])) {
|
|
||||||
// Initialized the parameter
|
|
||||||
|
|
||||||
// Writing the value and exit
|
// Writing the value and exit
|
||||||
$this->values[$name] = $value;
|
$this->values[$name] = $value;
|
||||||
} else {
|
|
||||||
// Not initialized the parameter
|
|
||||||
|
|
||||||
// Exit (fail)
|
|
||||||
throw new exception_domain("Not found the parameter: $name");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
use mirzaev\baza\database,
|
use mirzaev\baza\database,
|
||||||
mirzaev\baza\record,
|
mirzaev\baza\record,
|
||||||
mirzaev\baza\column,
|
mirzaev\baza\column,
|
||||||
|
@ -9,24 +7,11 @@ use mirzaev\baza\database,
|
||||||
mirzaev\baza\enumerations\type;
|
mirzaev\baza\enumerations\type;
|
||||||
|
|
||||||
// Initializing path to the composer loader file (main project)
|
// Initializing path to the composer loader file (main project)
|
||||||
$autoload =
|
$autoload = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
|
||||||
__DIR__ . DIRECTORY_SEPARATOR .
|
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
|
||||||
'vendor' . DIRECTORY_SEPARATOR .
|
|
||||||
'autoload.php';
|
|
||||||
|
|
||||||
// Reinitializing path to the composer loaded file (depencendy project)
|
// Reinitializing path to the composer loaded file (depencendy project)
|
||||||
if (!file_exists($autoload))
|
if (!file_exists($autoload))
|
||||||
$autoload =
|
$autoload = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'autoload.php';
|
||||||
__DIR__ . DIRECTORY_SEPARATOR .
|
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
|
||||||
'autoload.php';
|
|
||||||
|
|
||||||
// Importing files of thr project and dependencies
|
// Importing files of thr project and dependencies
|
||||||
require($autoload);
|
require($autoload);
|
||||||
|
|
Loading…
Reference in New Issue