Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -12,71 +12,92 @@
|
||||
namespace IPS\nexus\Purchase;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Application;
|
||||
use IPS\DateTime;
|
||||
use IPS\Db;
|
||||
use IPS\IPS;
|
||||
use IPS\nexus\Purchase;
|
||||
use IPS\Patterns\ActiveRecord;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function get_class;
|
||||
use function strlen;
|
||||
use function substr;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* License Key Model
|
||||
*/
|
||||
abstract class _LicenseKey extends \IPS\Patterns\ActiveRecord
|
||||
abstract class LicenseKey extends ActiveRecord
|
||||
{
|
||||
/**
|
||||
* License Key Types
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function licenseKeyTypes()
|
||||
public static function licenseKeyTypes() : array
|
||||
{
|
||||
return array(
|
||||
$return = array(
|
||||
'Standard' => 'IPS\nexus\Purchase\LicenseKey\Standard',
|
||||
'Mdfive' => 'IPS\nexus\Purchase\LicenseKey\Mdfive',
|
||||
);
|
||||
|
||||
/* Extensions */
|
||||
foreach ( Application::allExtensions( 'nexus', 'LicenseKey', FALSE, 'core' ) as $key => $extension )
|
||||
{
|
||||
$return[$extension::$keyType] = $extension::class;
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
protected static array $multitons;
|
||||
|
||||
/**
|
||||
* @brief Database Table
|
||||
*/
|
||||
public static $databaseTable = 'nexus_licensekeys';
|
||||
public static ?string $databaseTable = 'nexus_licensekeys';
|
||||
|
||||
/**
|
||||
* @brief Database Prefix
|
||||
*/
|
||||
public static $databasePrefix = 'lkey_';
|
||||
public static string $databasePrefix = 'lkey_';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database ID Column
|
||||
*/
|
||||
public static $databaseColumnId = 'key';
|
||||
public static string $databaseColumnId = 'key';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database ID Fields
|
||||
*/
|
||||
protected static $databaseIdFields = array( 'lkey_purchase' );
|
||||
protected static array $databaseIdFields = array( 'lkey_purchase' );
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Map
|
||||
*/
|
||||
protected static $multitonMap = array();
|
||||
protected static array $multitonMap = array();
|
||||
|
||||
/**
|
||||
* Construct ActiveRecord from database row
|
||||
*
|
||||
* @param array $data Row from database table
|
||||
* @param bool $updateMultitonStoreIfExists Replace current object in multiton store if it already exists there?
|
||||
* @return static
|
||||
* @param array $data Row from database table
|
||||
* @param bool $updateMultitonStoreIfExists Replace current object in multiton store if it already exists there?
|
||||
* @return static
|
||||
*/
|
||||
public static function constructFromData( $data, $updateMultitonStoreIfExists = TRUE )
|
||||
public static function constructFromData( array $data, bool $updateMultitonStoreIfExists = TRUE ): static
|
||||
{
|
||||
$types = static::licenseKeyTypes();
|
||||
$classname = $types[ mb_ucfirst( $data['lkey_type'] ) ];
|
||||
$classname = $types[ IPS::mb_ucfirst( $data['lkey_type'] ) ];
|
||||
|
||||
/* Initiate an object */
|
||||
$obj = new $classname;
|
||||
@@ -87,7 +108,7 @@ abstract class _LicenseKey extends \IPS\Patterns\ActiveRecord
|
||||
{
|
||||
if( static::$databasePrefix AND mb_strpos( $k, static::$databasePrefix ) === 0 )
|
||||
{
|
||||
$k = \substr( $k, \strlen( static::$databasePrefix ) );
|
||||
$k = substr( $k, strlen( static::$databasePrefix ) );
|
||||
}
|
||||
|
||||
$obj->_data[ $k ] = $v;
|
||||
@@ -109,23 +130,23 @@ abstract class _LicenseKey extends \IPS\Patterns\ActiveRecord
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setDefaultValues()
|
||||
public function setDefaultValues() : void
|
||||
{
|
||||
$exploded = explode( '\\', \get_class( $this ) );
|
||||
$exploded = explode( '\\', get_class( $this ) );
|
||||
$this->type = mb_strtolower( array_pop( $exploded ) );
|
||||
$this->active = TRUE;
|
||||
$this->uses = 0;
|
||||
$this->activate_data = array();
|
||||
$this->generated = new \IPS\DateTime;
|
||||
$this->generated = new DateTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set purchase
|
||||
*
|
||||
* @param \IPS\nexus\Purchase $purchase The purchase
|
||||
* @param Purchase $purchase The purchase
|
||||
* @return void
|
||||
*/
|
||||
public function set_purchase( \IPS\nexus\Purchase $purchase )
|
||||
public function set_purchase( Purchase $purchase ) : void
|
||||
{
|
||||
$this->_data['purchase'] = $purchase->id;
|
||||
$this->_data['member'] = $purchase->member->member_id;
|
||||
@@ -134,11 +155,11 @@ abstract class _LicenseKey extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Set purchase
|
||||
*
|
||||
* @return \IPS\nexus\Purchase
|
||||
* @return Purchase
|
||||
*/
|
||||
public function get_purchase()
|
||||
public function get_purchase() : Purchase
|
||||
{
|
||||
return \IPS\nexus\Purchase::load( $this->_data['purchase'] );
|
||||
return Purchase::load( $this->_data['purchase'] );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -147,7 +168,7 @@ abstract class _LicenseKey extends \IPS\Patterns\ActiveRecord
|
||||
* @param array $data The data
|
||||
* @return void
|
||||
*/
|
||||
public function set_activate_data( array $data )
|
||||
public function set_activate_data( array $data ) : void
|
||||
{
|
||||
$this->_data['activate_data'] = json_encode( $data );
|
||||
}
|
||||
@@ -155,20 +176,20 @@ abstract class _LicenseKey extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Set activate data
|
||||
*
|
||||
* @return \IPS\DateTime
|
||||
* @return array
|
||||
*/
|
||||
public function get_activate_data()
|
||||
public function get_activate_data() : array
|
||||
{
|
||||
return json_decode( $this->_data['activate_data'], TRUE );
|
||||
return json_decode( $this->_data['activate_data'], TRUE ) ?: array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set generated time
|
||||
*
|
||||
* @param \IPS\DateTime $generated Generated time
|
||||
* @param DateTime $generated Generated time
|
||||
* @return void
|
||||
*/
|
||||
public function set_generated( \IPS\DateTime $generated )
|
||||
public function set_generated( DateTime $generated ) : void
|
||||
{
|
||||
$this->_data['generated'] = $generated->getTimestamp();
|
||||
}
|
||||
@@ -176,28 +197,28 @@ abstract class _LicenseKey extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Set generated time
|
||||
*
|
||||
* @return \IPS\DateTime
|
||||
* @return DateTime
|
||||
*/
|
||||
public function get_generated()
|
||||
public function get_generated() : DateTime
|
||||
{
|
||||
return \IPS\DateTime::ts( $this->_data['generated'] );
|
||||
return DateTime::ts( $this->_data['generated'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Save Changed Columns
|
||||
*
|
||||
* @return void
|
||||
* @return void
|
||||
*/
|
||||
public function save()
|
||||
public function save(): void
|
||||
{
|
||||
if ( !$this->key )
|
||||
{
|
||||
do
|
||||
{
|
||||
$this->key = $this->generate();
|
||||
$this->key = $this->generateKey();
|
||||
}
|
||||
while ( \count( \IPS\Db::i()->select( '*', 'nexus_licensekeys', array( 'lkey_key=?', $this->key ) ) ) );
|
||||
while ( count( Db::i()->select( '*', 'nexus_licensekeys', array( 'lkey_key=?', $this->key ) ) ) );
|
||||
}
|
||||
return parent::save();
|
||||
parent::save();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user