Compare commits

...

3 commits

Author SHA1 Message Date
f4b8f8673e fix: set Database env credentials without returning a new instance (#24)
This is a follow-up PR from #22. Instead of returning a new instance after setting the environment variables we simply do nothing. Most of the extending classes will not take advantage of the new instance anyways, and will just call `new Database()` as before. Of course, as mentioned in #22 this setup is not ideal, and another solution should be implemented to instance this class.

Reviewed-on: https://codeberg.org/vlw/scaffold/pulls/24
2026-02-11 17:39:01 +01:00
1536079fe3 feat: add static method to create new Database instance from credentials (#22)
In this PR we add a new static method for creating a `vlw\Scaffold\Database\Database` instance from a set of provided credentials. This is of course not ideal and a better way to instance this class should be added in the future.

Reviewed-on: https://codeberg.org/vlw/scaffold/pulls/22
2026-02-11 17:25:22 +01:00
c501201f11 doc: add text that this library is primarily for Vegvisir and Reflect scaffolding (#23)
Reviewed-on: https://codeberg.org/vlw/scaffold/pulls/23
2026-02-11 17:25:05 +01:00
3 changed files with 33 additions and 2 deletions

View file

@ -1,5 +1,5 @@
# Scaffold # Scaffold
This composer package contains my project boilerplate code for working with [Vegvisir](https://vegvisir.vlw.se) and [Reflect](https://reflect.vlw.se) projects. It contains my most commonly used classes and functions which I use to make development of new project in these frameworks easier. This composer package (primarily) contains my project boilerplate code for working with [Vegvisir](https://vegvisir.vlw.se) and [Reflect](https://reflect.vlw.se) projects. It contains my most commonly used classes and functions which I use to make development of new project in these frameworks easier.
Refer to the documentation in each source file for more information about its function. Refer to the documentation in each source file for more information about its function.

View file

@ -1,6 +1,6 @@
{ {
"name": "vlw/scaffold", "name": "vlw/scaffold",
"description": "Project scaffolding for Reflect and Vegvisir projects", "description": "Project scaffolding (primarily) for Reflect and Vegvisir projects",
"type": "library", "type": "library",
"license": "GPL-3.0-or-later", "license": "GPL-3.0-or-later",
"authors": [ "authors": [

View file

@ -15,6 +15,37 @@
public const DATE_FORMAT = "Y-m-d"; public const DATE_FORMAT = "Y-m-d";
public const DATETIME_FORMAT = "Y-m-d H:i:s"; public const DATETIME_FORMAT = "Y-m-d H:i:s";
private const DEFAULT_HOSTNAME = "localhost";
private const DEFAULT_USERNAME = "www-data";
private const DEFAULT_PASSWORD = "";
/**
* Create a new Database instance from credentials
*
* @param string $host
* @param string $username
* @param string $password
* @param string $database
* @return void
*/
public static function set_credentials(
?string $host = self::DEFAULT_HOSTNAME,
?string $username = self::DEFAULT_USERNAME,
?string $password = self::DEFAULT_PASSWORD,
string $database
) {
// Create key if it does not exist
if (!$_ENV["mariadb"]) {
$_ENV["mariadb"] = [];
}
// Set environment variables from credentials
$_ENV["mariadb"]["host"] = $host;
$_ENV["mariadb"]["user"] = $username;
$_ENV["mariadb"]["pass"] = $password;
$_ENV["mariadb"]["db"] = $database;
}
/** /**
* Wrap a new vlw/MySQL instance with credentials from project .env.ini * Wrap a new vlw/MySQL instance with credentials from project .env.ini
*/ */