Skip to content

Commit 52f07e1

Browse files
JJJdanieliserashleyfae
authored
Release/2.0.0 (#57)
Merging this a little early so we can get Composer support in a stable version. I've been running this for a few months now and it seems to work fine. * Move classes to PSR-4 compliant src structure * Add composer, autoloader support & gitignore * Add use to fix missing class issue after file move * Date: Remove duplicate "use" statement. * Query: non-functional clean-up. This change normalizes a bunch of variable names, docs, punctuation, and aliased functions (like join vs implode) - consistency! * Query: add copy_item() method. (#89) This change introduces a way to allow for copying an existing item/Row in the database, with the option to override that data via the $data parameter. The goal of including this method as a low-level API is to reduce the amount of code necessary to support this action higher up in the application layer (global functions, etc...) * Table: fix format of query inside index_exists(). (#90) This change prevents quotes around the $column value by not preparing it, and also by making sure its value is only 1 of 2 intended columns: Key_name and Column_name. This fixes incorrectly generated SQL, allowing this method to function as intended instead of incorrectly returning no results. Props @ashleyfae. Fixes #87. * First pass autoloader for non-Composer setups. Props szepeviktor. * Check if 'where' is empty before using #101 (#102) * Check if 'where' is empty before using #101 * Added protection against empty "where" clauses #101 Co-authored-by: John James Jacoby <[email protected]> Co-authored-by: danieliser <[email protected]> Co-authored-by: Ashley Gibson <[email protected]>
1 parent 550ad19 commit 52f07e1

12 files changed

+63
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/vendor/

autoloader.php

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
* Autoloader.
4+
*
5+
* @package Database
6+
* @copyright Copyright (c) 2021
7+
* @license https://opensource.org/licenses/gpl-2.0.php GNU Public License
8+
* @since 2.0.0
9+
*/
10+
11+
// Exit if accessed directly.
12+
defined( 'ABSPATH' ) || exit;
13+
14+
// Register a closure to autoload BerlinDB.
15+
spl_autoload_register(
16+
17+
/**
18+
* Closure of the autoloader.
19+
*
20+
* @param string $class_name The fully-qualified class name.
21+
* @return void
22+
*/
23+
static function ( $class_name = '' ) {
24+
25+
// Project namespace & length.
26+
$project_namespace = 'BerlinDB\\Database\\';
27+
$length = strlen( $project_namespace );
28+
29+
// Bail if class is not in this namespace.
30+
if ( 0 !== strncmp( $project_namespace, $class_name, $length ) ) {
31+
return;
32+
}
33+
34+
// Setup file parts.
35+
$format = '%1$s/src/%2$s.php';
36+
$path = __DIR__;
37+
$name = str_replace( '\\', '/', substr( $class_name, $length ) );
38+
39+
// Parse class and namespace to file.
40+
$file = sprintf( $format, $path, $name );
41+
42+
// Bail if file does not exist.
43+
if ( ! is_file( $file ) ) {
44+
return;
45+
}
46+
47+
// Require the file.
48+
require_once $file;
49+
}
50+
);

composer.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "berlindb/core",
3+
"description": "A collection of PHP classes and functions that aims to provide an ORM-like experience and interface to WordPress database tables.",
4+
"type": "library",
5+
"license": "GPL-2.0-only",
6+
"require": {},
7+
"autoload": {
8+
"psr-4": {
9+
"BerlinDB\\": "src/"
10+
}
11+
}
12+
}

base.php src/Database/Base.php

File renamed without changes.

column.php src/Database/Column.php

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

query.php src/Database/Query.php

File renamed without changes.

row.php src/Database/Row.php

File renamed without changes.

schema.php src/Database/Schema.php

File renamed without changes.

table.php src/Database/Table.php

File renamed without changes.

0 commit comments

Comments
 (0)