Files
crm.clientright.ru/modules/Workflow2/lib/Workflow/BPMN/Flow.php

51 lines
1.1 KiB
PHP
Executable File

<?php
/**
* Created by PhpStorm.
* User: StefanWarnat
* Date: 26.03.2019
* Time: 18:23
*/
namespace Workflow\BPMN;
class Flow
{
private static $cache = array();
private static $ids = array();
public static function getId($from, $to) {
if(!isset(self::$cache[$from])) {
self::$cache[$from] = array();
}
if(!isset(self::$cache[$from][$to])) {
self::$cache[$from][$to] = 'SequenceFlow_'.self::getFreeId();
}
return self::$cache[$from][$to];
}
private static function random_strings($length_of_string)
{
// String of all alphanumeric character
$str_result = '0123456789abcdefghijklmnopqrstuvwxyz';
// Shufle the $str_result and returns substring
// of specified length
return substr(str_shuffle($str_result),
0, $length_of_string);
}
public static function getFreeId() {
do {
$id = self::random_strings(8);
} while(isset(self::$ids[$id]));
return $id;
}
public static function getAll() {
return self::$cache;
}
}