mirror of
https://codeberg.org/vlw/scaffold.git
synced 2025-11-05 06:02:42 +01:00
Compare commits
No commits in common. "00337cd3aac28d7be13abbab98079bccf40b7fac" and "e1d3a09966810b75a0bc0f35847d4ccee52341c8" have entirely different histories.
00337cd3aa
...
e1d3a09966
7 changed files with 47 additions and 44 deletions
|
|
@ -9,9 +9,3 @@ Run the install scripts for [Vegvisir](https://vegvisir.vlw.se/install) and/or [
|
|||
```
|
||||
composer require vlw/scaffold
|
||||
```
|
||||
|
||||
Refer to the code comments in each file for documentation about its function. The base namespace is `vlw\Scaffold` and each class and function can be `use`d that way. For example:
|
||||
|
||||
```php
|
||||
use vlw\Scaffold\Database\Model;
|
||||
```
|
||||
|
|
@ -1,12 +1,14 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Read the documentation at:
|
||||
* https://codeberg.org/vlw/scaffold/docs/API/API.md
|
||||
*/
|
||||
|
||||
namespace vlw\Scaffold\API;
|
||||
|
||||
use Reflect\Rules\Ruleset;
|
||||
|
||||
/**
|
||||
* Wrapper for Reflect API endpoints
|
||||
*/
|
||||
class API {
|
||||
/**
|
||||
* Create a new API request with automatic request validation
|
||||
|
|
|
|||
|
|
@ -1,5 +1,10 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Read the documentation at:
|
||||
* https://codeberg.org/vlw/scaffold/docs/Database/Database.md
|
||||
*/
|
||||
|
||||
namespace vlw\Scaffold\Database;
|
||||
|
||||
use vlw\MySQL\MySQL;
|
||||
|
|
@ -8,9 +13,6 @@
|
|||
|
||||
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";
|
||||
|
|
|
|||
|
|
@ -1,14 +1,16 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Read the documentation at:
|
||||
* https://codeberg.org/vlw/scaffold/docs/Database/Model.md
|
||||
*/
|
||||
|
||||
namespace vlw\Scaffold\Database;
|
||||
|
||||
use vlw\Scaffold\Database\Database;
|
||||
|
||||
require_once "Database.php";
|
||||
|
||||
/**
|
||||
* Abstract reading, creating, and updating of database entities.
|
||||
*/
|
||||
abstract class Model {
|
||||
const DATE_FORMAT = Database::DATE_FORMAT;
|
||||
|
||||
|
|
@ -55,7 +57,7 @@
|
|||
|
||||
$this->_resolved = true;
|
||||
$this->_row = $this->db
|
||||
->from($this->table)
|
||||
->for($this->table)
|
||||
->where($this->where)
|
||||
->limit(1)
|
||||
->select($this->columns)
|
||||
|
|
@ -72,9 +74,10 @@
|
|||
*
|
||||
* @return bool Entity exists
|
||||
*/
|
||||
public function isset(): bool {
|
||||
return $this->_isset ??= new Database()
|
||||
->from($this->table)
|
||||
public bool $isset {
|
||||
// Returns bool if row is set or attempts to resolve and set if null
|
||||
get => $this->_isset ??= new Database()
|
||||
->for($this->table)
|
||||
->where($this->where)
|
||||
->limit(1)
|
||||
->select()
|
||||
|
|
@ -102,7 +105,7 @@
|
|||
$this->_row[$key] = $value;
|
||||
|
||||
return $this->db
|
||||
->from($this->table)
|
||||
->for($this->table)
|
||||
->where($this->where)
|
||||
->update([$key => $value]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Read the documentation at:
|
||||
* https://codeberg.org/vlw/scaffold/docs/Database/Paginate.md
|
||||
*/
|
||||
|
||||
namespace vlw\Scaffold\Helpers;
|
||||
|
||||
/**
|
||||
* Paginate items of any kind. This class is deisgned to work well with
|
||||
* vlw\MySQL and the Scaffold\Database\Database class.
|
||||
*/
|
||||
class Paginate {
|
||||
public const KEY = "p";
|
||||
public const DEFAULT_RANGE = 3;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace vlw\Scaffold\Helpers;
|
||||
/**
|
||||
* Read the documentation at:
|
||||
* https://codeberg.org/vlw/scaffold/docs/Helpers/UUID.md
|
||||
*/
|
||||
|
||||
const UUID_LENGTH = 36;
|
||||
namespace vlw\Scaffold\Helpers;
|
||||
|
||||
/**
|
||||
* Generate an all binary 0:s UUID
|
||||
|
|
|
|||
|
|
@ -5,14 +5,13 @@
|
|||
use VV;
|
||||
use Reflect\Path;
|
||||
|
||||
class Scaffold {
|
||||
/**
|
||||
* Include a source file
|
||||
* Include a source file from either Vegvisir or Reflect
|
||||
*
|
||||
* @param string $pathname Relative path from project root to a source file
|
||||
*/
|
||||
public static function load(string $pathname): void {
|
||||
// Load the Vegvisir VV class from Reflect
|
||||
function load(string $pathname): void {
|
||||
// Load the Vegvisir VV clas from Reflect
|
||||
if (!class_exists("VV")) {
|
||||
require_once Path::root("vegvisir/src/kernel/Init.php");
|
||||
require_once Path::root("vegvisir/src/request/VV.php");
|
||||
|
|
@ -20,4 +19,3 @@
|
|||
|
||||
require_once VV::root($pathname);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue