PHP code example of mistralys / errorcode-incrementor

1. Go to this page and download the library: Download mistralys/errorcode-incrementor library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mistralys / errorcode-incrementor example snippets



$counters = array(
    'Mistral' => 0,
    'Tramontane' => 520 // start at #520
);


// The list of counters
$counters = array(
    'Test' => 0
);

// Create the collection with the path to the folder
// where the files can be stored - must be writable.
$collection = new \Mistralys\Counters\Counters('./storage', $counters);

// To avoid an exception, always check first
if($collection->counterExists('Test'))
{
    $number = $collection->getByName('Test')->getNumber();
}  


// The list of counters
$counters = array(
    'Test' => 0
);

// Create the collection with the path to the folder
// where the files can be stored - must be writable.
$collection = new \Mistralys\Counters\Counters('./storage', $counters);

// To avoid an exception, always check first
if($collection->counterExists('Test'))
{
    // Incrementing returns the new counter value
    $newNumber = $collection->getByName('Test')->increment();
}  


// The list of counters
$counters = array(
    'Test' => 0
);

// Create the collection with the path to the folder
// where the files can be stored - must be writable.
$collection = new \Mistralys\Counters\Counters('./storage', $counters);

$counters = $collection->getCounters();

// Display a list of counters and their values
foreach($counters as $counter)
{
    echo $counter->getName().' = '.$counter->getNumber().PHP_EOL;
}