Merged in feature/MAW-855-import-code-into-aws (pull request #2)

code import from pantheon

* code import from pantheon
This commit is contained in:
Tony Volpe
2023-12-04 23:08:14 +00:00
parent 8c9b1312bc
commit 8f4b5efda6
4766 changed files with 185592 additions and 239967 deletions

View File

@@ -3,6 +3,7 @@
namespace Yoast\WP\Lib;
use JsonSerializable;
use ReturnTypeWillChange;
/**
* Make Model compatible with WordPress.
@@ -87,6 +88,13 @@ class Model implements JsonSerializable {
*/
protected $int_columns = [];
/**
* Which columns contain float values.
*
* @var array
*/
protected $float_columns = [];
/**
* Hacks around the Model to provide WordPress prefix to tables.
*
@@ -154,20 +162,22 @@ class Model implements JsonSerializable {
* class or the property does not exist, returns the default
* value supplied as the third argument (which defaults to null).
*
* @param string $class_name The target class name.
* @param string $property The property to get the value for.
* @param string|null $default Default value when property does not exist.
* @param string $class_name The target class name.
* @param string $property The property to get the value for.
* @param mixed|null $default_value Default value when property does not exist.
*
* @return string The value of the property.
* @return mixed|null The value of the property.
*/
protected static function get_static_property( $class_name, $property, $default = null ) {
protected static function get_static_property( $class_name, $property, $default_value = null ) {
if ( ! \class_exists( $class_name ) || ! \property_exists( $class_name, $property ) ) {
return $default;
return $default_value;
}
$properties = \get_class_vars( $class_name );
if ( ! isset( $class_name::${$property} ) ) {
return $default_value;
}
return $properties[ $property ];
return $class_name::${$property};
}
/**
@@ -392,7 +402,7 @@ class Model implements JsonSerializable {
$associated_table_name = static::get_table_name_for_class( static::$auto_prefix_models . $associated_class_name );
$foreign_key_name = static::build_foreign_key_name( $foreign_key_name, $associated_table_name );
$associated_object_id = $this->{$foreign_key_name};
$desired_record = null;
if ( $foreign_key_name_in_associated_models_table === null ) {
/*
* Comparison: "{$associated_table_name}.primary_key = {$associated_object_id}".
@@ -505,6 +515,9 @@ class Model implements JsonSerializable {
if ( $value !== null && \in_array( $property, $this->int_columns, true ) ) {
return (int) $value;
}
if ( $value !== null && \in_array( $property, $this->float_columns, true ) ) {
return (float) $value;
}
return $value;
}
@@ -524,6 +537,9 @@ class Model implements JsonSerializable {
if ( $value !== null && \in_array( $property, $this->int_columns, true ) ) {
$value = (string) $value;
}
if ( $value !== null && \in_array( $property, $this->float_columns, true ) ) {
$value = (string) $value;
}
$this->orm->set( $property, $value );
}
@@ -544,6 +560,7 @@ class Model implements JsonSerializable {
*
* @return array The data of this object.
*/
#[ReturnTypeWillChange]
public function jsonSerialize() {
return $this->orm->as_array();
}
@@ -554,7 +571,11 @@ class Model implements JsonSerializable {
* @return array
*/
public function __debugInfo() {
return $this->orm->as_array();
if ( $this->orm ) {
return $this->orm->as_array();
}
return [];
}
/**
@@ -641,7 +662,7 @@ class Model implements JsonSerializable {
/**
* Save the data associated with this model instance to the database.
*
* @return null Nothing.
* @return bool True on success.
*/
public function save() {
if ( $this->uses_timestamps ) {
@@ -657,7 +678,7 @@ class Model implements JsonSerializable {
/**
* Delete the database row associated with this model instance.
*
* @return null Nothing.
* @return bool|int Response of wpdb::query.
*/
public function delete() {
return $this->orm->delete();