Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added versioning #2

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions src/Loader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?php
namespace SureCart\Licensing;

/**
* SureCart Loader
*
* This class is necessary to set project data
*/
class Loader {

/**
* Product data.
*
* @access private
* @var array Entities array.
*/
private $entities = array();

/**
* Client version.
*
* @access private
* @var string client version.
*/
private $client_version = '';

/**
* Client path.
*
* @access private
* @var string client path.
*/
private $client_path = '';

/**
* Instance
*
* @access private
* @var object Class object.
*/
private static $instance = null;

/**
* Get instance of class.
*
* @return object
*/
public static function instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}

return self::$instance;
}
/**
* Initialize the class
*
* @param string $name Readable name of the plugin.
* @param string $file Main plugin file path.
*/
public function __construct() {

add_action( 'plugins_loaded', array( $this, 'load_license_client' ), 1 );
}

/**
* Set entity for analytics.
*
* @param string $data Entity attributes data.
* @return void
*/
public function set_entity( $data ) {
array_push( $this->entities, $data );
}

/**
* Load license client.
*
* @return void
*/
public function load_license_client() {

if ( ! empty( $this->entities ) ) {
foreach ( $this->entities as $data ) {
if ( isset( $data['path'] ) ) {
if ( file_exists( $data['path'] . 'src//version.json' ) ) {
$file_contents = file_get_contents( $data['path'] . 'src//version.json' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
$client_version = json_decode( $file_contents, 1 );
$client_version = $client_version['version'];

if ( version_compare( $client_version, $this->client_version, '>' ) ) {
$this->client_version = $client_version;
$this->client_path = $data['path'];
}
}
}
}
}
}

/**
* Set entity for analytics.
*
* @param string $data Entity attributes data.
* @return void
*/
public function get_client( $name, $file ) {

if ( ! class_exists( 'SureCart\Licensing\Client' ) ) {

if ( file_exists( $this->client_path ) ) {
require_once $this->client_path . 'src/Client.php';
} else {
require_once 'Client.php';
}
}

// initialize client with your plugin name.
return new \SureCart\Licensing\Client( $name, $file );
}
}
7 changes: 7 additions & 0 deletions src/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ class Updater {
*/
protected $client;

/**
* SureCart\Licensing\Client
*
* @var string
*/
protected $cache_key;

/**
* Initialize the class
*
Expand Down
3 changes: 3 additions & 0 deletions src/version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"version": "1.0.0"
}