PHP Classes

PHP License System: Manage PHP applications license keys

Recommend this page to a friend!
  Info   View files Documentation   View files View files (54)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 232 This week: 4All time: 8,128 This week: 29Up
Version License PHP version Categories
license-handler 1.0.0MIT/X Consortium ...5PHP 5, Tools
Description 

Author

This package can manage PHP applications license keys.

It provides means to keep track of applications and licenses given to their users.

The package can generate authorization keys which can be associated to a given site that the application to be licensed will be running.

Picture of Josantonius
  Performance   Level  
Name: Josantonius is available for providing paid consulting. Contact Josantonius .
Classes: 31 packages by
Country: Spain Spain
Age: ???
All time rank: 132526 in Spain Spain
Week rank: 27 Up3 in Spain Spain Up
Innovation award
Innovation award
Nominee: 11x

Recommendations

What is the best PHP licence key system class?
I need a license key system to lock out users upon expiring date

Documentation

License Handler · Eliasis PHP Framework plugin

Packagist Downloads License Codacy Badge Build Status PSR2 PSR4 codecov

Versión en español

Licensing and applications manager.

Requirements

This plugin is supported by PHP versions 5.6 or higher and is compatible with HHVM versions 3.0 or higher.

Installation

The preferred way to install this extension is through Composer.

To install License Handler, simply:

$ composer require eliasis-framework/license-handler

The previous command will only install the necessary files, if you prefer to download the entire source code you can use:

$ composer require eliasis-framework/license-handler --prefer-source

You can also clone the complete repository with Git:

$ git clone https://github.com/eliasis-framework/license-handler.git

Available Methods

Available methods in this plugin:

Applications

- Add application:

$application->add($name, $type, $category, $active);

| Atttribute | Description | Type | Required | --- | --- | --- | --- | | $name | Application name. | string | Yes | | $type | Application type. | string | Yes | | $category | Application category. | string | Yes | | $active | Application state. | boolean| Yes |

@return (int) ? Application inserted ID.

- Update application:

$application->update($id, $name, $type, $category, $active);

| Atttribute | Description | Type | Required | --- | --- | --- | --- | | $id | Application ID. | string | Yes | | $name | Application name. | string | Yes | | $type | Application type. | string | Yes | | $category | Application category. | string | Yes | | $active | Application state. | boolean| Yes |

@return (int) ? Rows affected.

Sites

- Add site:

$site->add($domain, $host, $ip, $authorized);

| Atttribute | Description | Type | Required | --- | --- | --- | --- | | $domain | Site domain. | string | Yes | | $host | Site host. | string | Yes | | $ip | Site ip. | string | Yes | | $authorized | Authorized?. | boolean| Yes |

@return (int) ? Site inserted ID.

- Update site:

$site->update($id, $domain, $host, $ip, $authorized);

| Atttribute | Description | Type | Required | --- | --- | --- | --- | | $id | Site ID. | string | Yes | | $domain | Site domain. | string | Yes | | $host | Site host. | string | Yes | | $ip | Site ip. | string | Yes | | $authorized | Authorized?. | boolean| Yes |

@return (int) ? Rows affected.

License

- Generate license key:

$license->generateKey($characters, $segments);

| Atttribute | Description | Type | Required | Default | --- | --- | --- | --- | --- | | $characters | Characters number by segments. | int | No | 5 | | $segments | Segments number. | int | No | 5 |

@return (string) ? License key.

- Add license:

$license->add($appID, $siteID, $key, $state, $expire);

| Atttribute | Description | Type | Required | --- | --- | --- | --- | | $appID | Application table id. | int | Yes | | $siteID | Site table id. | int | Yes | | $key | License key. | string | Yes | | $state | License state. | bool | Yes | | $expire | License expiration date. | string| Yes |

@return (int) ? License inserted ID.

- Update license:

$license->update($id, $appID, $siteID, $key, $state, $expire);

| Atttribute | Description | Type | Required | --- | --- | --- | --- | | $id | License ID. | string | Yes | | $appID | Application table id. | int | Yes | | $siteID | Site table id. | int | Yes | | $key | License key. | string | Yes | | $state | License state. | bool | Yes | | $expire | License expiration date. | string| Yes |

@return (int) ? Rows affected.

- Check if license exists:

$license->keyExists($license);

| Atttribute | Description | Type | Required | --- | --- | --- | --- | | $license | License key. | string | Yes |

@return (boolean)

Options

- Add option:

$option->add($licenseID, $name, $value);

| Atttribute | Description | Type | Required | --- | --- | --- | --- | | $licenseID | License table id. | string | Yes | | $name | Option name. | string | Yes | | $value | Option value. | string | Yes |

@return (int) ? Option inserted ID.

- Update option:

$option->update($id, $licenseID, $name, $value);

| Atttribute | Description | Type | Required | --- | --- | --- | --- | | $id | Option ID. | string | Yes | | $licenseID | License table id. | string | Yes | | $name | Option name. | string | Yes | | $value | Option value. | string | Yes |

@return (int) ? Rows affected.

Quick Start

To use this plugin, your Eliasis application must use the PHP-Database library and add the following to the application configuration files:

/
 * eliasis-app/config/complements.php
 */
return [

    'plugin' => [

        'license-handler' => [

            'db-id' => 'app',
            'db-prefix' => 'test_',
            'db-charset' => 'utf8',
            'db-engine' => 'innodb'
        ],
    ],
];

And get the instances from each table:

use Eliasis\Complement\Type\Plugin;

$site = Plugin::WP_Plugin_Info()->getControllerInstance('Site');
$option = Plugin::WP_Plugin_Info()->getControllerInstance('Option');
$license = Plugin::WP_Plugin_Info()->getControllerInstance('License);
$application = Plugin::WP_Plugin_Info()->getControllerInstance('Application');

Usage

Applications

- Add application:

$appID = $application->add('app-name', 'plugin', 'WordPress', 1);

- Update application:

$application->update($appID, 'new-app-name', 'module', 'Prestashop', 1);

Sites

- Add site:

$siteID = $site->add(
	'domain.com', 
	'host.domain.com',
	'87.142.85.70', 1
);

- Update site:

$site->update(
	$siteID, 
	'new-domain.com', 
	'host.new-domain.com', 
	'87.142.85.70', 1
);

License

- Generate license key:

$license = $license->generateKey(); // 3FGSV-BZ49N-U79EA-S96ZY-MFQ63

$license = $license->generateKey(5, 5); // 3FGSV-BZ49N-U79EA-S96ZY-MFQ63

$license = $license->generateKey(4, 4); // 3FGS-BZ4N-U7EA-S9ZY

$license = $license->generateKey(6, 5); // SF4W2H-FEJKZ5-PU7KAD-N77486-BKMJSW

$license = $license->generateKey(4, 2); // FT3Q-EBT5

- Add license:

$licenseID = $license->add(1, 1, $key, $license, '+1day');

$licenseID = $license->add(1, 1, $key, $license, '+10days');

$licenseID = $license->add(1, 1, $key, $license, '+1week');

$licenseID = $license->add(1, 1, $key, $license, '+1month');

$licenseID = $license->add(1, 1, $key, $license, '+2months');

$licenseID = $license->add(1, 1, $key, $license, '+1year');

$licenseID = $license->add(1, 1, $key, $license, '+2years');

- Update license:

$license->update(1, 1, $key, $license, '+3weeks');

- Check if license exists:

$license->keyExists('SF4W2H-FEJKZ5-PU7KAD-N77486-BKMJSW');

Options

- Add option:

$option->add($licenseID, 'lang', 'es-ES');

- Update option:

$option->update($id, $licenseID, 'lang', 'en-EN');

Database

This plugin will create the following tables.

- test_applications:

The table structure created is as follows:

| Columns | Data type | | --- | --- | | app_id | INT(9) | | app_name | VARCHAR(80) | | app_type | VARCHAR(80) | | app_category | VARCHAR(80) | | app_state | INT(1) | | updated | TIMESTAMP | | created | TIMESTAMP |

- test_sites:

The table structure created is as follows:

| Columns | Data type | | --- | --- | | site_id | INT(9) | | site_domain | VARCHAR(255) | | site_host | VARCHAR(255) | | site_ip | VARCHAR(1) | | site_authorized | INT(1) | | updated | TIMESTAMP | | created | TIMESTAMP |

- test_licenses:

The table structure created is as follows:

| Columns | Data type | | --- | --- | | lic_id | INT(9) | | app_id | INT(9) | | site_id | INT(9) | | lic_key | VARCHAR(29) | | lic_state | INT(1) | | lic_expire | DATETIME | | site_authorized | INT(1) | | updated | TIMESTAMP | | created | TIMESTAMP |

- test_options:

The table structure created is as follows:

| Columns | Data type | | --- | --- | | option_id | INT(9) | | lic_id | INT(9) | | option_name | VARCHAR(180) | | option_value | LONGTEXT |

Tests

To run tests you just need composer and to execute the following:

$ git clone https://github.com/eliasis-framework/license-handler.git

$ cd license-handler

$ composer install

Run unit tests with PHPUnit:

$ composer phpunit

Run PSR2 code standard tests with PHPCS:

$ composer phpcs

Run PHP Mess Detector tests to detect inconsistencies in code style:

$ composer phpmd

Run all previous tests:

$ composer tests

? TODO

  • [ ] Run PHPUnit on Travis CI.
  • [ ] Add more methods.
  • [ ] Improve tests.
  • [ ] Improve documentation.
  • [ ] Refactor code for disabled code style rules. See phpmd.xml and .php_cs.dist.

Contribute

If you would like to help, please take a look at the list of issues or the To Do checklist.

Pull requests

  • Fork and clone.
  • Run the command `composer install` to install the dependencies. This will also install the dev dependencies.
  • Run the command `composer fix` to excute code standard fixers.
  • Run the tests.
  • Create a branch, commit, push and send me a pull request.

License

This project is licensed under MIT license. See the LICENSE file for more info.

Copyright

2017 - 2018 Josantonius, josantonius.com

If you find it useful, let me know :wink:

You can contact me on Twitter or through my email.


  Files folder image Files  
File Role Description
Files folder imageconfig (6 files)
Files folder imagesrc (2 directories)
Files folder imagetests (5 files, 1 directory)
Accessible without login Plain text file .editorconfig Data Auxiliary data
Accessible without login Plain text file .php_cs.dist Example Example script
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file CHANGELOG.md Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file CONDUCT.md Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file license-handler.json Lic. License text
Accessible without login Plain text file phpcs.xml Data Auxiliary data
Accessible without login Plain text file phpmd.xml Data Auxiliary data
Accessible without login Plain text file README-ES.md Doc. Documentation
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file _config.yml Data Auxiliary data

  Files folder image Files  /  config  
File Role Description
  Accessible without login Plain text file database.php Aux. Auxiliary script
  Accessible without login Plain text file datetime.php Aux. Auxiliary script
  Accessible without login Plain text file namespaces.php Aux. Auxiliary script
  Accessible without login Plain text file rows.php Aux. Auxiliary script
  Accessible without login Plain text file set-hooks.php Example Example script
  Accessible without login Plain text file tables.php Aux. Auxiliary script

  Files folder image Files  /  src  
File Role Description
Files folder imageController (5 files, 1 directory)
Files folder imageModel (4 files)

  Files folder image Files  /  src  /  Controller  
File Role Description
Files folder imageException (1 file)
  Plain text file Application.php Class Class source
  Plain text file Launcher.php Class Class source
  Plain text file License.php Class Class source
  Plain text file Option.php Class Class source
  Plain text file Site.php Class Class source

  Files folder image Files  /  src  /  Controller  /  Exception  
File Role Description
  Plain text file LHException.php Class Class source

  Files folder image Files  /  src  /  Model  
File Role Description
  Plain text file Application.php Class Class source
  Plain text file License.php Class Class source
  Plain text file Option.php Class Class source
  Plain text file Site.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imagesample-app (2 directories)
  Plain text file ApplicationTest.php Class Class source
  Accessible without login Plain text file bootstrap.php Aux. Auxiliary script
  Plain text file LicenseTest.php Class Class source
  Plain text file OptionTest.php Class Class source
  Plain text file SiteTest.php Class Class source

  Files folder image Files  /  tests  /  sample-app  
File Role Description
Files folder imageconfig (2 files)
Files folder imageplugins (1 file, 1 directory)

  Files folder image Files  /  tests  /  sample-app  /  config  
File Role Description
  Accessible without login Plain text file complements.php Aux. Auxiliary script
  Accessible without login Plain text file database.php Aux. Auxiliary script

  Files folder image Files  /  tests  /  sample-app  /  plugins  
File Role Description
Files folder imagelicense-handler (1 file, 2 directories)
  Accessible without login Plain text file .plugins-states.json Data Auxiliary data

  Files folder image Files  /  tests  /  sample-app  /  plugins  /  license-handler  
File Role Description
Files folder imageconfig (6 files)
Files folder imagesrc (2 directories)
  Accessible without login Plain text file license-handler.json Lic. License text

  Files folder image Files  /  tests  /  sample-app  /  plugins  /  license-handler  /  config  
File Role Description
  Accessible without login Plain text file database.php Aux. Auxiliary script
  Accessible without login Plain text file datetime.php Aux. Auxiliary script
  Accessible without login Plain text file namespaces.php Aux. Auxiliary script
  Accessible without login Plain text file rows.php Aux. Auxiliary script
  Accessible without login Plain text file set-hooks.php Example Example script
  Accessible without login Plain text file tables.php Aux. Auxiliary script

  Files folder image Files  /  tests  /  sample-app  /  plugins  /  license-handler  /  src  
File Role Description
Files folder imageController (5 files, 1 directory)
Files folder imageModel (4 files)

  Files folder image Files  /  tests  /  sample-app  /  plugins  /  license-handler  /  src  /  Controller  
File Role Description
Files folder imageException (1 file)
  Plain text file Application.php Class Class source
  Plain text file Launcher.php Class Class source
  Plain text file License.php Class Class source
  Plain text file Option.php Class Class source
  Plain text file Site.php Class Class source

  Files folder image Files  /  tests  /  sample-app  /  plugins  /  license-handler  /  src  /  Controller  /  Exception  
File Role Description
  Plain text file LHException.php Class Class source

  Files folder image Files  /  tests  /  sample-app  /  plugins  /  license-handler  /  src  /  Model  
File Role Description
  Plain text file Application.php Class Class source
  Plain text file License.php Class Class source
  Plain text file Option.php Class Class source
  Plain text file Site.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:232
This week:4
All time:8,128
This week:29Up