mirror of
https://github.com/itflow-org/itflow
synced 2026-12-02 09:09:01 +00:00
Documents in Markdown: a document can be written in Markdown with Write and Preview or in the rich text editor and switched either way, pictures pasted or dropped into the Markdown are kept as files, New Document starts in the way last used, Import Markdown Files beside Upload makes a document from each .md file, a Markdown button beside PDF downloads a document as a .md file, and Markdown pasted into a document's rich text editor goes in as formatting; versions, restore, copy and the API carry the Markdown, and the API's document create and update no longer escape values twice; database 4.2.3 adds documents.document_markdown and document_versions.document_version_markdown, and league/commonmark 2.10 and league/html-to-markdown 5.2 are added to libs/vendor through composer; 26.12.3 changelog entries
This commit is contained in:
52
libs/vendor/nette/utils/src/Utils/Random.php
vendored
Normal file
52
libs/vendor/nette/utils/src/Utils/Random.php
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of the Nette Framework (https://nette.org)
|
||||
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
|
||||
*/
|
||||
|
||||
namespace Nette\Utils;
|
||||
|
||||
use Nette;
|
||||
use Random\Randomizer;
|
||||
use function strlen;
|
||||
use const PHP_VERSION_ID;
|
||||
|
||||
|
||||
/**
|
||||
* Secure random string generator.
|
||||
*/
|
||||
final class Random
|
||||
{
|
||||
use Nette\StaticClass;
|
||||
|
||||
/**
|
||||
* Generates a random string of given length from characters specified in second argument.
|
||||
* Supports intervals, such as `0-9` or `A-Z`.
|
||||
*/
|
||||
public static function generate(int $length = 10, string $charlist = '0-9a-z'): string
|
||||
{
|
||||
$charlist = preg_replace_callback(
|
||||
'#.-.#',
|
||||
fn(array $m): string => implode('', range($m[0][0], $m[0][2])),
|
||||
$charlist,
|
||||
);
|
||||
$charlist = count_chars($charlist, mode: 3);
|
||||
$chLen = strlen($charlist);
|
||||
|
||||
if ($length < 1) {
|
||||
throw new Nette\InvalidArgumentException('Length must be greater than zero.');
|
||||
} elseif ($chLen < 2) {
|
||||
throw new Nette\InvalidArgumentException('Character list must contain at least two chars.');
|
||||
} elseif (PHP_VERSION_ID >= 80300) {
|
||||
return (new Randomizer)->getBytesFromString($charlist, $length);
|
||||
}
|
||||
|
||||
$res = '';
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$res .= $charlist[random_int(0, $chLen - 1)];
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user