Initial Commit

This commit is contained in:
David Stone
2024-11-30 18:24:12 -07:00
commit e8f7955c1c
5432 changed files with 1397750 additions and 0 deletions

View File

@ -0,0 +1,24 @@
<?php
/**
* BerlinDB Base Class Wrapper
*/
namespace WP_Ultimo\Database\Engine;
// Exit if accessed directly
defined('ABSPATH') || exit;
/**
* The base class that all other database base classes extend.
*
* This class attempts to provide some universal immutability to all other
* classes that extend it, starting with a magic getter, but likely expanding
* into a magic call handler and others.
*
* @since 1.0.0
*/
class Base extends \WP_Ultimo\Dependencies\BerlinDB\Database\Base {
protected $prefix = 'wu';
} // end class Base;

View File

@ -0,0 +1,24 @@
<?php
/**
* Base Custom Database Column Class.
*/
namespace WP_Ultimo\Database\Engine;
// Exit if accessed directly
defined('ABSPATH') || exit;
/**
* The base class that all other database base classes extend.
*
* This class attempts to provide some universal immutability to all other
* classes that extend it, starting with a magic getter, but likely expanding
* into a magic call handler and others.
*
* @since 1.0.0
*/
class Column extends \WP_Ultimo\Dependencies\BerlinDB\Database\Column {
protected $prefix = 'wu';
} // end class Column;

View File

@ -0,0 +1,20 @@
<?php
/**
* Base Custom Database Compare Class.
*/
namespace WP_Ultimo\Database\Engine;
// Exit if accessed directly
defined('ABSPATH') || exit;
/**
* The base class that all other database base classes extend.
*
* This class attempts to provide some universal immutability to all other
* classes that extend it, starting with a magic getter, but likely expanding
* into a magic call handler and others.
*
* @since 1.0.0
*/
class Compare extends \WP_Ultimo\Dependencies\BerlinDB\Database\Compare {} // end class Compare;

View File

@ -0,0 +1,20 @@
<?php
/**
* Base Custom Database Date Class.
*/
namespace WP_Ultimo\Database\Engine;
// Exit if accessed directly
defined('ABSPATH') || exit;
/**
* The base class that all other database base classes extend.
*
* This class attempts to provide some universal immutability to all other
* classes that extend it, starting with a magic getter, but likely expanding
* into a magic call handler and others.
*
* @since 1.0.0
*/
class Date extends \WP_Ultimo\Dependencies\BerlinDB\Database\Date {} // end class Date;

View File

@ -0,0 +1,281 @@
<?php
/**
* WP Ultimo ENUM base class.
*
* @package WP_Ultimo
* @subpackage WP_Ultimo\Database\Engine
* @since 2.0.0
*/
namespace WP_Ultimo\Database\Engine;
// Exit if accessed directly
defined('ABSPATH') || exit;
/**
* WP Ultimo ENUM base class.
*
* @since 2.0.0
*/
abstract class Enum
{
/**
* The default value.
*/
const __default = false;
// phpcs:ignore
/**
* The options available.
*
* @since 2.0.0
* @var array
*/
static $options = array();
/**
* @var string
*/
private $value = '';
/**
* Constructor method. Takes the value you want to set.
*
* @since 2.0.0
*
* @param string $value The value to be set.
*/
public function __construct($value = '')
{
$this->value = $value;
}
// end __construct;
// Needs to be Implemented
/**
* Returns an array with values => CSS Classes.
*
* @since 2.0.0
* @return array
*/
abstract protected function classes();
/**
* Returns an array with values => labels.
*
* @since 2.0.0
* @return void
*/
abstract protected function labels();
/**
* Returns an array with values => labels.
*
* @since 2.0.0
* @return void
*/
protected function icon_classes() {
return array();
}
// end icon_classes;
/**
* Returns the options available as constants.
*
* @since 2.0.0
* @return array
*/
public static function get_options() {
$hook = static::get_hook_name();
if (!isset(static::$options[$hook])) {
$reflector = new \ReflectionClass(static::class);
static::$options[$hook] = apply_filters("wu_available_{$hook}_options", $reflector->getConstants());
} // end if;
return static::$options[$hook];
}
// end get_options;
public static function get_allowed_list($string = false) {
$options = array_unique(self::get_options());
return $string ? implode(',', $options) : $options;
}
// end get_allowed_list;
/**
* Returns the value loaded here.
*
* This runs through is_valid and returns the
* default value if a invalid value is passed on.
*
* @since 2.0.0
* @return string
*/
public function get_value() {
if ($this->is_valid($this->value)) {
return $this->value;
} // end if;
return static::__default;
}
// end get_value;
/**
* Check for the the validity of the value passed.
*
* @since 2.0.0
*
* @param string $value The string.
* @return boolean
*/
public function is_valid($value) {
$options = static::get_options();
return in_array($value, $options, true);
}
// end is_valid;
/**
* Returns the label of a given value.
*
* @since 2.0.0
* @return string
*/
public function get_label() {
$hook = static::get_hook_name();
$labels = apply_filters("wu_available_{$hook}_labels", $this->labels());
return $this->exists_or_default($labels, $this->get_value());
}
// end get_label;
/**
* Returns the classes of a given value.
*
* @since 2.0.0
* @return string
*/
public function get_classes() {
$hook = static::get_hook_name();
$classes = apply_filters("wu_available_{$hook}_classes", $this->classes());
return $this->exists_or_default($classes, $this->get_value());
}
// end get_classes;
/**
* Returns the classes of a given value.
*
* @since 2.0.0
* @return string
*/
public function get_icon_classes() {
$hook = static::get_hook_name();
$classes = apply_filters("wu_available_{$hook}_icon_classes", $this->icon_classes());
return $this->exists_or_default($classes, $this->get_value());
}
// end get_icon_classes;
/**
* Returns an array of options.
*
* @since 2.0.0
* @return void
*/
public static function to_array() {
static $instance;
if ($instance === null) {
$instance = new static;
} // end if;
$hook = $instance::get_hook_name();
$labels = apply_filters("wu_{$hook}_to_array", $instance->labels());
return $labels;
}
// end to_array;
/**
* Get the hook name for this class, so we can add filters.
*
* @since 2.0.0
* @return string
*/
public static function get_hook_name() {
$class_name = (new \ReflectionClass(static::class))->getShortName();
return strtolower($class_name);
}
// end get_hook_name;
/**
* Checks if a key exists on an array, otherwise returns a default value.
*
* @since 2.0.0
*
* @param array $array The array to check.
* @param string $key The key to check.
* @param string $default The default value.
* @return string
*/
public function exists_or_default($array, $key, $default = '') {
if (empty($default)) {
$default = isset($array[static::__default]) ? $array[static::__default] : '';
} // end if;
return isset($array[$key]) ? $array[$key] : $default;
}
// end exists_or_default;
/**
* Converts this to string.
*
* @since 2.0.0
* @return string
*/
public function __toString(): string {
return $this->get_value();
}
// end __toString;
/**
* Magic method to allow for constants to be called.
*
* @since 2.0.0
*
* @param string $name The name of the constants.
* @param array $arguments The list of arguments. Not really needed here.
* @return string
*/
public static function __callStatic($name, $arguments) {
$class_name = static::class;
return constant("$class_name::$name");
}
// end __callStatic;
} // end class Enum;

View File

@ -0,0 +1,20 @@
<?php
/**
* Base Custom Database Meta Class.
*/
namespace WP_Ultimo\Database\Engine;
// Exit if accessed directly
defined('ABSPATH') || exit;
/**
* The base class that all other database base classes extend.
*
* This class attempts to provide some universal immutability to all other
* classes that extend it, starting with a magic getter, but likely expanding
* into a magic call handler and others.
*
* @since 1.0.0
*/
class Meta extends \WP_Ultimo\Dependencies\BerlinDB\Database\Meta {} // end class Meta;

View File

@ -0,0 +1,100 @@
<?php
/**
* Base Custom Database Table Query Class.
*/
namespace WP_Ultimo\Database\Engine;
// Exit if accessed directly
defined('ABSPATH') || exit;
/**
* The base class that all other database base classes extend.
*
* This class attempts to provide some universal immutability to all other
* classes that extend it, starting with a magic getter, but likely expanding
* into a magic call handler and others.
*
* @since 1.0.0
*/
class Query extends \WP_Ultimo\Dependencies\BerlinDB\Database\Query {
/**
* The prefix for the custom table.
*
* @since 2.0.0
* @var string
*/
protected $prefix = 'wu';
/**
* If we should use a global cache group.
*
* @since 2.1.2
* @var bool
*/
protected $global_cache = false;
/**
* Keep track of the global cache groups we've added.
* This is to prevent adding the same group multiple times.
*
* @since 2.1.2
* @var array
*/
protected static $added_globals = array();
/**
* Plural version for a group of items.
*
* @since 2.0.0
* @access public
* @var string
*/
protected $item_name_plural;
/**
* Group to cache queries and queried items in.
*
* @since 2.0.0
* @access public
* @var string
*/
protected $cache_group = 'sites';
/**
* The class constructor
*
* @since 2.1.2
* @param string|array $query Optional. An array or string of Query parameters.
* @return void
*/
public function __construct($query = array()) {
$cache_group = $this->apply_prefix($this->cache_group, '-');
if ($this->global_cache && !in_array($cache_group, self::$added_globals, true)) {
wp_cache_add_global_groups(array($cache_group));
self::$added_globals[] = $cache_group;
} // end if;
parent::__construct($query);
} // end __construct;
/**
* Get the plural name.
*
* @since 2.0.0
* @return string
*/
public function get_plural_name() {
return $this->item_name_plural;
} // end get_plural_name;
} // end class Query;

View File

@ -0,0 +1,24 @@
<?php
/**
* Base Custom Database Row Class.
*/
namespace WP_Ultimo\Database\Engine;
// Exit if accessed directly
defined('ABSPATH') || exit;
/**
* The base class that all other database base classes extend.
*
* This class attempts to provide some universal immutability to all other
* classes that extend it, starting with a magic getter, but likely expanding
* into a magic call handler and others.
*
* @since 1.0.0
*/
class Row extends \WP_Ultimo\Dependencies\BerlinDB\Database\Row {
protected $prefix = 'wu';
} // end class Row;

View File

@ -0,0 +1,24 @@
<?php
/**
* Base Custom Database Table Schema Class.
*/
namespace WP_Ultimo\Database\Engine;
// Exit if accessed directly
defined('ABSPATH') || exit;
/**
* The base class that all other database base classes extend.
*
* This class attempts to provide some universal immutability to all other
* classes that extend it, starting with a magic getter, but likely expanding
* into a magic call handler and others.
*
* @since 1.0.0
*/
class Schema extends \WP_Ultimo\Dependencies\BerlinDB\Database\Schema {
protected $prefix = 'wu';
} // end class Schema;

View File

@ -0,0 +1,84 @@
<?php
/**
* Base Custom Database Table Class.
*/
namespace WP_Ultimo\Database\Engine;
// Exit if accessed directly
defined('ABSPATH') || exit;
/**
* The base class that all other database base classes extend.
*
* This class attempts to provide some universal immutability to all other
* classes that extend it, starting with a magic getter, but likely expanding
* into a magic call handler and others.
*
* @since 1.0.0
*/
abstract class Table extends \WP_Ultimo\Dependencies\BerlinDB\Database\Table {
/**
* Table prefix.
*
* @since 2.0.0
* @var string
*/
protected $prefix = 'wu';
/**
* Caches the SHOW TABLES result.
*
* @since 2.0.0
* @var bool
*/
protected $_exists;
/**
* Overrides the is_upgradeable method.
*
* We need to do this because we are using the table object
* early in the lifecycle, which means that upgrade.php is not
* available.
*
* @since 2.0.0
* @return boolean
*/
public function is_upgradeable() {
if (!is_main_network()) {
return false;
} // end if;
if (!is_main_site()) {
return false;
} // end if;
return true;
} // end is_upgradeable;
/**
* Adds a caching layer to the parent exists method.
*
* @since 2.0.0
* @return boolean
*/
public function exists() {
if ($this->_exists === null) {
$this->_exists = parent::exists();
} // end if;
return $this->_exists;
} // end exists;
} // end class Table;