mirror of
https://codeberg.org/vlw/scaffold.git
synced 2026-01-11 22:16:00 +01:00
Remove all trailing whitespaces from source files. Looks like it was only docblocks tho, that's nice! Reviewed-on: https://codeberg.org/vlw/scaffold/pulls/12
39 lines
1 KiB
PHP
39 lines
1 KiB
PHP
<?php
|
|
|
|
namespace vlw\Scaffold\Database;
|
|
|
|
use vlw\MySQL\MySQL;
|
|
|
|
use vlw\Scaffold\Database\Paginate;
|
|
|
|
require_once dirname(__DIR__, 1) . "/Helpers/Paginate.php";
|
|
|
|
/**
|
|
* Wrapper for vlw\MySQL which reads credentials from .env.ini in the project root.
|
|
*/
|
|
class Database extends MySQL {
|
|
public const DATE_FORMAT = "Y-m-d";
|
|
public const DATETIME_FORMAT = "Y-m-d H:i:s";
|
|
|
|
/**
|
|
* Wrap a new vlw/MySQL instance with credentials from project .env.ini
|
|
*/
|
|
public function __construct() {
|
|
parent::__construct(
|
|
$_ENV["mariadb"]["host"],
|
|
$_ENV["mariadb"]["user"],
|
|
$_ENV["mariadb"]["pass"],
|
|
$_ENV["mariadb"]["db"],
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Paginate request by chaining this after vlw/MySQL->from() and before vlw/MySQL->select()
|
|
*
|
|
* @param ?Paginate $paginate a vlw\Scaffold\Helper\Paginate instance
|
|
* @return self Instance chainable with vlw\MySQL
|
|
*/
|
|
public function paginate(?Paginate &$paginate = null): self {
|
|
return $paginate ? $this->limit($paginate->size, $paginate->offset) : $this;
|
|
}
|
|
}
|