Download the PHP package hedronium/casus without Composer

On this page you can find all versions of the php package hedronium/casus. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package casus

Casus

Just another Randomizer Library but cooler! With many out of the box features and support for 'Cryptographically Secure Pseudo Random Number Generators' (CSPRNGs) provided by MCrypt and/or OpenSSL

Installation

The easiest way to install Casus for use in your own projects is through composer. You could manually download the files and use an alternative psr-4 compatible autoloader to autoload the file in the src directory but this is not recommended and highly discouraged.

Through composer.json File

Add this line in your composer.json file and run composer install on the command line

Through the command line

Just run in your project directory

Usage

Basically all you do is instantiate an object of the Casus Class and you're good to go!

The above example will out put a number between 0 and PHP_INT_MAX of your PHP installation.

The casus class actually forwards all method calls to the generator instance, thus you could, if you prefer to, get the generator instance and call methods directly on it. Like:

Methods

Method List

The $secure parameter on each method is used to temporarily override the secure generator for an insecure one, in a secure instance. (This can be done by setting it to false). By default it is set to true.

integer ($min, $max [, $secure])

Returns a Number between $min & $max

Parameters

float ($min, $max, $precision [, $secure])

Returns a Floating point number between $min & $max

Parameters

boolean ([$secure])

Returns a boolean value (true or false)

alpha ($length, _$caserandomization [, $secure])

Returns a string consisting of alphabets

Parameters

alphanum ($length, _$caserandomization [, $secure])

Returns a string consisting of alphabets & numbers

Parameters

asciiRange ($length, $ranges [, $secure])

Returns a string consisting of ASCII characters with the the range defined by $ranges

Parameters

string ($length, $charset [, $secure])

Returns a string consisting of the characters specified in $charset

Parameters

integerArray ($min, $max, $length [, $secure])

Returns an array of random integers

Parameters

uniqueIntegerArray ($min, $max, $length [, $secure])

Returns an array of unique random integers

Parameters

floatArray ($min, $max, $precision, $length [, $secure])

Returns an array of random floating point numbers

Parameters

randomize ($input [, $secure])

Takes a Array or String and returns a randomized version of it.

Parameters

selectRandom ($input, $length [, $secure])

Selects random elements from an array or string

Parameters

byte ([$secure])

Returns a Random Byte

byteString ($length [, $secure])

Returns a Random String of Bytes

Parameters

Initialization Options

$secure

type: boolean
default: true
To use a Cryptographically Secure Generator or not. By default, a CSPRNG like MCrypt or OpenSSL will be used

The Above example makes Casus use a Generator that is not cryptographically secure. (It just uses PHP's built in mt_rand function)

$generator

type: Generator
default: null
Injects the Generator Instance to use. (Must be an instance of a child of \hedronium\Casus\Generator)

The Above example specifies an instance of the default OpenSSL generator.
Note: If the provided generator is not secure and $secure is set to true, Casus will throw an \hedronium\Casus\errors\Insecure Exception.

Misc Methods

isSecure()

Returns: boolean
Returns if the current Generator in use is Secure or not.

hasMCrypt()

Returns: boolean
Returns if your PHP installation has the MCrypt extension enabled or not.

hasOpenSSL()

Returns: boolean
Returns if your PHP installation has the OpenSSL extension enabled or not.

getGenerator()

Returns: Generator
Returns the current Generator Instance in use.

setGenerator($secure, $generator)

Returns: boolean
Set a new generator based on arguments. (This is actually the method the constructor calls behind the scenes)

Returns true on success, and throws hedronium\Casus\errors\Insecure Exception if the first parameter is true but the generator parameter is not a secure generator, or if no secure generator extension was found.

Writing Custom Generators

Creating a Generator

To create a generator all you have to do is write a class that extends the abstract class \hedronium\Casus\Generator. It is absolutely required that you implement the integer ($min, $max) method. (It's already an Abstract Method, so you should get an error in the event that you forget to implement it)

Example Generator:

Using your Custom Generator

Just Pass it in as the second parameter of the Casus constructor

Or Just directly instantiate your Generator class (the Casus Main Class is useless anyway, it actually just forwards all the method calls to the generator instance)

Note: The Casus main class could be used to enforce secure Generators.

Cryptographically Secure?

If your Generator is Cryptographically Secure (uses an CSPRNG Algorithm) then you have to specify it so that Casus doesn't complain.

You can do that simply by setting the $secure property in your Generator class to true like:

Unit Testing Your Generator

The simplest way to Unit test your Custom Generator would be to extend the GeneratorTest class in Casus's Tests directory. The CeneratorTest class already extends the PHPUnit_Framework_TestCase class so you don't have to.

You do have to implement the setUp() though so that it sets the casus property of the TestClass Object to an instance of your Generator Class.

Example:

This will test all the standard methods that comes packaged with Casus. You could go ahead and add tests for your Special Methods.


All versions of casus with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.0
ext-mcrypt Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package hedronium/casus contains the following files

Loading the files please wait ....