Algoritore Documentation

LbZJ-IIcy-0QKE-p3bb-R6U

A simple key generator tool by DaGardner

A simple and flexible package with great and top-notch API design.

Thank you for purchasing my package. If you have any questions or suggestions that are beyond the scope of this help file, please do not hesitate to email via my user page contact form here (lower right).
Thanks so much!


Author: DaGardner / Christian Gärtner
Contact: Contact Form lower right!
Author URL: DaGardner
Item URL: On CodeCanyon
Current Version: 1.0.0
Documentation Version 1.0.0
Created: 2013-10-28
Modified: 2013-10-28

You can use this package to generate random and custom strings or numbers. You can use this in lots of applications. For email verifaction, API keys, etc. Your imagination is the limit here. Thanks to awesome hook points in the package you have maximum control of the generated code.


Quick Start

This way you can easily generate a random code.

/**
 * Christian Gärtner (DaGardner)
 * Example usage of the Algoritore package.
 * (c) 2013 Christian Gärtner (DaGardner)
 */
 
require './vendor/autoload.php';
 
use DaGardner\Algoritore\Algoritore;
 
$algoritore = new Algoritore;
 
$algoritore->setLength(19);
 
$algoritore->useSpecialChars(false);
 
$algoritore->hyphenate(4);
 
echo $algoritore->get(); // results in: LbZJ-IIcy-0QKE-p3bb-R6U

Customize Character Pool

You have full control of the character pool used by the class:

// Default character pool
$this->pool['letters']  = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
$this->pool['numbers']  = '0123456789';
$this->pool['extra']    = '-_.:,;!"ยง$%&/()=?';
$this->pool['user']     = $extraChars; // Constructor Argument
///--------------
$algoritore->useLetters(false);
$algoritore->useNumbers(false);
$algoritore->useSpecialChars(false);
$algoritore->useUserChars(true);

Customize

You can easily customize the code, by changing the length, case of the letters or hyphenate the string. Note that these things are handled by shiped String Processors.

$algoritore->setLength(20);
$algoritore->upperCase();
$algoritore->lowerCase();
$algoritore->hyphenate(4, '='); // With custom symbol!

// This methods are all chainable!
$algoritore
    ->setLength(20)
    ->unique()
    ->lowerCase()
    ->hyphenate()
    ->prefix('API_CODE==')
    ->suffix('==END')
    ->get();

// Awesome isn't it :D
// This will result in: "API_CODE==mjpo-!q&m-&.x0-(p%d-henx==END"


Heads up! These feature will get extended in the near future! This is just the start of it! (I won't break BC!)

Basics

String Processors are an easiy way of changing the produced code/string. The will get called after a basic code generation and allow to change the string in any way! I' ve already created a few and they are shiped with in this package.

Name How? What? Why?
CaseShifter Shits the case to lower- or upper-case.
$algoritore->upperCase() or $algoritore->lowerCase()
Hyphenator Hypenates the string (guess what?!
$algoritore->hyphenate()
Prefixer This will prefix and/or suffix the code.
$algoritore->prefix('PREFIX') or $algoritore->suffix('SUFFIX')
UniqueMaker This will discard the previous code and generate a much more secure one (this is way slower).
$algoritore->unique()

Create your own!

You can easily create your own one.

/*
 * First: Create your class. It has to implement the
 * \DaGardner\Algoritore\StringProcessor\StringProcessorInterface
 */
class MyProcessor implements DaGardner\Algoritore\StringProcessor\StringProcessorInterface {
    
    public function process($string) {
        // This one will just replaces all 'a's with 'b's
        return str_replace('a', 'b', $string);
    }

}
// Now you need to add it Algoritore:

$algoritore = new DaGardner\Algoritore\Algoritore;

$algoritore->addProcessor(new MyProcessor);

// But you can do it even more quickly
// by using anonymous functions or called closures

$algoritore->addProcessor(function($string)
{
    return str_replace('a', 'b', $string);
});


Priority System

You can imagine that if we have a few (2 are enough) processors they will interfere. I' ve added a priority system for that.

// If you add a shiped processor
$algoritore->unique(0);

// or with a custom:
$algoritore->addProcessor(new MyProcessor, 1);

/*
 * Now the 'unique' processor will get called FIRST.
 * NOTE! LOWER or NEGATIVE priorities will get called FIRST
 */

1. Include the class files

There are a few ways of including all files (I'll show you two). I recommend to use composers autoloader!

This one is the easiest and most reliable approach. In this package the autoload files are already generated for you. Otherwise you could run a composer install in the main directory. You can include all classes of this package by adding this line to your php-file (somewhat on the top).
require 'vendor/autoload.php'

You can also manually include each file like this:
require 'src/DaGardner/Algoritore/StringProcessor/StringProcessorInterface.php';
require 'src/DaGardner/Algoritore/Algoritore.php';
and so on!
Note! Make sure to include/require the StringProcessorInterface first!


2. Namespacing

This package is in the DaGardner\Algoritore namespace. This means you cannot simply instantiate the class like this:
new Algoritore;

// Full-name access:

new DaGardner\Algoritore\Algoritore;

//==========
// a use statement:
use DaGardner\Algoritore\Algoritore

new Algoritore;

//=========
// go into the same namespace
// Not recommended
namespace DaGardner\Algoritore;