first commit
This commit is contained in:
65
autoload/shop/class.ProductCustomField.php
Normal file
65
autoload/shop/class.ProductCustomField.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
namespace shop;
|
||||
|
||||
class ProductCustomField implements \ArrayAccess
|
||||
{
|
||||
public function __construct( int $custom_field_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$result = $mdb -> get( 'pp_shop_products_custom_fields', '*', [ 'id_additional_field' => $custom_field_id ] );
|
||||
if ( \S::is_array_fix( $result ) ) foreach ( $result as $key => $val )
|
||||
$this -> $key = $val;
|
||||
}
|
||||
|
||||
static public function getFromCache( int $custom_field_id )
|
||||
{
|
||||
// Check if Redis extension is loaded
|
||||
if ( class_exists( 'Redis' ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$redis = \RedisConnection::getInstance() -> getConnection();
|
||||
$objectData = $redis -> get( "shop\ProductCustomField:$custom_field_id" );
|
||||
|
||||
if ( !$objectData )
|
||||
{
|
||||
$object = new self( $custom_field_id );
|
||||
$redis -> setex( "shop\ProductCustomField:$custom_field_id", 60 * 60 * 24, serialize( $object ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$object = unserialize( $objectData );
|
||||
}
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
// Log the exception if needed
|
||||
$object = new self( $custom_field_id );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Redis extension not loaded, create a new instance
|
||||
$object = new self( $custom_field_id );
|
||||
}
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
public function offsetExists($offset) {
|
||||
return isset($this->$offset);
|
||||
}
|
||||
|
||||
public function offsetGet($offset) {
|
||||
return $this->$offset;
|
||||
}
|
||||
|
||||
public function offsetSet($offset , $value) {
|
||||
$this->$offset = $value;
|
||||
}
|
||||
|
||||
public function offsetUnset($offset) {
|
||||
unset($this->$offset);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user