mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-06 20:48:40 +00:00
Adding comments and parameters
This commit is contained in:
parent
776717ad53
commit
7ffcb763e9
|
|
@ -0,0 +1,54 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 7.0
|
||||||
|
*
|
||||||
|
* @category TBD
|
||||||
|
* @package TBD
|
||||||
|
* @author OMS Development Team <dev@oms.com>
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
* @copyright 2013 Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link http://orange-management.com
|
||||||
|
*/
|
||||||
|
namespace phpOMS\Utils\Compression;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compression Interface
|
||||||
|
*
|
||||||
|
* @category Framework
|
||||||
|
* @package phpOMS\Asset
|
||||||
|
* @author OMS Development Team <dev@oms.com>
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @link http://orange-management.com
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
interface CompressionInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Compresses source text
|
||||||
|
*
|
||||||
|
* @param string $source Source text to compress
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
|
public function compress(string $source) : string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decompresses text
|
||||||
|
*
|
||||||
|
* @param string $compressed Compressed text to decompress
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
|
public function decompress(string $compressed) : string;
|
||||||
|
}
|
||||||
|
|
@ -1,10 +1,41 @@
|
||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 7.0
|
||||||
|
*
|
||||||
|
* @category TBD
|
||||||
|
* @package TBD
|
||||||
|
* @author OMS Development Team <dev@oms.com>
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
* @copyright 2013 Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link http://orange-management.com
|
||||||
|
*/
|
||||||
|
namespace phpOMS\Utils\Compression;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LZW compression class
|
||||||
|
*
|
||||||
|
* @category Framework
|
||||||
|
* @package phpOMS\Asset
|
||||||
|
* @author OMS Development Team <dev@oms.com>
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @link http://orange-management.com
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
class LZW implements CompressionInterface
|
class LZW implements CompressionInterface
|
||||||
{
|
{
|
||||||
public static function compress($unc) {
|
|
||||||
$i;$c;$wc;
|
/**
|
||||||
$w = "";
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function compress(string $source) : string
|
||||||
|
{
|
||||||
|
$wc = '';
|
||||||
|
$w = '';
|
||||||
$dictionary = [];
|
$dictionary = [];
|
||||||
$result = [];
|
$result = [];
|
||||||
$dictSize = 256;
|
$dictSize = 256;
|
||||||
|
|
@ -13,8 +44,8 @@ class LZW implements CompressionInterface
|
||||||
$dictionary[chr($i)] = $i;
|
$dictionary[chr($i)] = $i;
|
||||||
}
|
}
|
||||||
|
|
||||||
for ($i = 0; $i < strlen($unc); $i++) {
|
for ($i = 0; $i < strlen($source); $i++) {
|
||||||
$c = $unc[$i];
|
$c = $source[$i];
|
||||||
$wc = $w.$c;
|
$wc = $w.$c;
|
||||||
|
|
||||||
if (array_key_exists($w. $c, $dictionary)) {
|
if (array_key_exists($w. $c, $dictionary)) {
|
||||||
|
|
@ -26,29 +57,32 @@ class LZW implements CompressionInterface
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($w !== "") {
|
if ($w !== '') {
|
||||||
array_push($result,$dictionary[$w]);
|
array_push($result,$dictionary[$w]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return implode(",",$result);
|
return implode(',',$result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function decompress($com) {
|
/**
|
||||||
$com = explode(",",$com);
|
* {@inheritdoc}
|
||||||
$i;$w;$k;$result;
|
*/
|
||||||
|
public function decompress(string $compressed) : string
|
||||||
|
{
|
||||||
|
$compressed = explode(',', $compressed);
|
||||||
$dictionary = [];
|
$dictionary = [];
|
||||||
$entry = "";
|
$entry = '';
|
||||||
$dictSize = 256;
|
$dictSize = 256;
|
||||||
|
|
||||||
for ($i = 0; $i < 256; $i++) {
|
for ($i = 0; $i < 256; $i++) {
|
||||||
$dictionary[$i] = chr($i);
|
$dictionary[$i] = chr($i);
|
||||||
}
|
}
|
||||||
|
|
||||||
$w = chr($com[0]);
|
$w = chr($compressed[0]);
|
||||||
$result = $w;
|
$result = $w;
|
||||||
|
|
||||||
for ($i = 1; $i < count($com);$i++) {
|
for ($i = 1; $i < count($compressed);$i++) {
|
||||||
$k = $com[$i];
|
$k = $compressed[$i];
|
||||||
|
|
||||||
if ($dictionary[$k]) {
|
if ($dictionary[$k]) {
|
||||||
$entry = $dictionary[$k];
|
$entry = $dictionary[$k];
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,54 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 7.0
|
||||||
|
*
|
||||||
|
* @category TBD
|
||||||
|
* @package TBD
|
||||||
|
* @author OMS Development Team <dev@oms.com>
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
* @copyright 2013 Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link http://orange-management.com
|
||||||
|
*/
|
||||||
|
namespace phpOMS\Utils\Encoding;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encoding Interface
|
||||||
|
*
|
||||||
|
* @category Framework
|
||||||
|
* @package phpOMS\Asset
|
||||||
|
* @author OMS Development Team <dev@oms.com>
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @link http://orange-management.com
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
interface EncodingInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Encode source text
|
||||||
|
*
|
||||||
|
* @param string $source Source text to decode
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
|
public function decode($source);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dedecodes text
|
||||||
|
*
|
||||||
|
* @param string $decoded decoded text to dedecode
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
|
public function decode($decoded);
|
||||||
|
}
|
||||||
|
|
@ -1,11 +1,43 @@
|
||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 7.0
|
||||||
|
*
|
||||||
|
* @category TBD
|
||||||
|
* @package TBD
|
||||||
|
* @author OMS Development Team <dev@oms.com>
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
* @copyright 2013 Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link http://orange-management.com
|
||||||
|
*/
|
||||||
|
namespace phpOMS\Utils\Encoding;
|
||||||
|
|
||||||
class Gray {
|
/**
|
||||||
|
* Gray encoding class
|
||||||
|
*
|
||||||
|
* @category Framework
|
||||||
|
* @package phpOMS\Asset
|
||||||
|
* @author OMS Development Team <dev@oms.com>
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @link http://orange-management.com
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
final class Gray {
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public static function encode(int $source) : int
|
public static function encode(int $source) : int
|
||||||
{
|
{
|
||||||
return $source ^ ($source >> 1);
|
return $source ^ ($source >> 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public static function decode(int $gray) : int
|
public static function decode(int $gray) : int
|
||||||
{
|
{
|
||||||
$source = $gray;
|
$source = $gray;
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,85 @@
|
||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 7.0
|
||||||
|
*
|
||||||
|
* @category TBD
|
||||||
|
* @package TBD
|
||||||
|
* @author OMS Development Team <dev@oms.com>
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
* @copyright 2013 Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link http://orange-management.com
|
||||||
|
*/
|
||||||
namespace phpOMS\Utils\Git;
|
namespace phpOMS\Utils\Git;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gray encoding class
|
||||||
|
*
|
||||||
|
* @category Framework
|
||||||
|
* @package phpOMS\Asset
|
||||||
|
* @author OMS Development Team <dev@oms.com>
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @link http://orange-management.com
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
class Author
|
class Author
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Name.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
private $name = '';
|
private $name = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Email.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
private $email = '';
|
private $email = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param string $name Author name
|
||||||
|
* @param string $email Author email
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
public function __construct(string $name, string $email)
|
public function __construct(string $name, string $email)
|
||||||
{
|
{
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
$this->email = $email;
|
$this->email = $email;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get name
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
public function getName() : string
|
public function getName() : string
|
||||||
{
|
{
|
||||||
return $name;
|
return $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get email
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
public function getEmail() : string
|
public function getEmail() : string
|
||||||
{
|
{
|
||||||
return $email;
|
return $email;
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,75 @@
|
||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 7.0
|
||||||
|
*
|
||||||
|
* @category TBD
|
||||||
|
* @package TBD
|
||||||
|
* @author OMS Development Team <dev@oms.com>
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
* @copyright 2013 Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link http://orange-management.com
|
||||||
|
*/
|
||||||
namespace phpOMS\Utils\Git;
|
namespace phpOMS\Utils\Git;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gray encoding class
|
||||||
|
*
|
||||||
|
* @category Framework
|
||||||
|
* @package phpOMS\Asset
|
||||||
|
* @author OMS Development Team <dev@oms.com>
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @link http://orange-management.com
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
class Branch
|
class Branch
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Name.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
private $name = '';
|
private $name = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param string $name Branch name
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
public function __construct(string $name)
|
public function __construct(string $name)
|
||||||
{
|
{
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set branch name
|
||||||
|
*
|
||||||
|
* @param string $name Branch name
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
public function setName(string $name)
|
public function setName(string $name)
|
||||||
{
|
{
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get name
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
public function getName() : string
|
public function getName() : string
|
||||||
{
|
{
|
||||||
return $this->name;
|
return $this->name;
|
||||||
|
|
|
||||||
|
|
@ -1,35 +1,143 @@
|
||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 7.0
|
||||||
|
*
|
||||||
|
* @category TBD
|
||||||
|
* @package TBD
|
||||||
|
* @author OMS Development Team <dev@oms.com>
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
* @copyright 2013 Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link http://orange-management.com
|
||||||
|
*/
|
||||||
namespace phpOMS\Utils\Git;
|
namespace phpOMS\Utils\Git;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gray encoding class
|
||||||
|
*
|
||||||
|
* @category Framework
|
||||||
|
* @package phpOMS\Asset
|
||||||
|
* @author OMS Development Team <dev@oms.com>
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @link http://orange-management.com
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
class Commit
|
class Commit
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Hash.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
private $id = '';
|
private $id = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Author.
|
||||||
|
*
|
||||||
|
* @var Author
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
private $author = null;
|
private $author = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Branch.
|
||||||
|
*
|
||||||
|
* @var Branch
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
private $branch = null;
|
private $branch = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tag.
|
||||||
|
*
|
||||||
|
* @var Tag
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
private $tag = null;
|
private $tag = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Commit date.
|
||||||
|
*
|
||||||
|
* @var \DateTime
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
private $date = null;
|
private $date = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repository.
|
||||||
|
*
|
||||||
|
* @var Repository
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
private $repository = null;
|
private $repository = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Commit message.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
private $message = '';
|
private $message = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Files.
|
||||||
|
*
|
||||||
|
* @var string[]
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
private $files = [];
|
private $files = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param string $id Commit hash
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
public function __construct(string $id = '') {
|
public function __construct(string $id = '') {
|
||||||
$author = new Author();
|
$author = new Author();
|
||||||
$branch = new Branch();
|
$branch = new Branch();
|
||||||
$tag = new Tag();
|
$tag = new Tag();
|
||||||
|
|
||||||
if(!empty($id)) {
|
if(!empty($id)) {
|
||||||
|
// todo: fill base info
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add file to commit.
|
||||||
|
*
|
||||||
|
* @param string $path File path
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
public function addFile(string $path) {
|
public function addFile(string $path) {
|
||||||
if(!isset($this->files[$path])) {
|
if(!isset($this->files[$path])) {
|
||||||
$this->files[$path] = [];
|
$this->files[$path] = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addChange(string $path, int $line, string $old, string $new)
|
/**
|
||||||
|
* Add change.
|
||||||
|
*
|
||||||
|
* @param string $path File path
|
||||||
|
* @param int $line Line number
|
||||||
|
* @param string $old Old line
|
||||||
|
* @param string $new New line
|
||||||
|
*
|
||||||
|
* @throws
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
|
private function addChange(string $path, int $line, string $old, string $new)
|
||||||
{
|
{
|
||||||
if(!isset($this->files[$path])) {
|
if(!isset($this->files[$path])) {
|
||||||
throw new \Exception();
|
throw new \Exception();
|
||||||
|
|
@ -42,64 +150,180 @@ class Commit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set commit message.
|
||||||
|
*
|
||||||
|
* @param string $path File path
|
||||||
|
*
|
||||||
|
* @throws
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
public function setMessage(string $message)
|
public function setMessage(string $message)
|
||||||
{
|
{
|
||||||
$this->message = $message;
|
$this->message = $message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get commit message.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
public function getMessage() : string
|
public function getMessage() : string
|
||||||
{
|
{
|
||||||
return $this->message;
|
return $this->message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFiles() : array {
|
/**
|
||||||
|
* Get files of this commit.
|
||||||
|
*
|
||||||
|
* @return string[]
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
|
public function getFiles() : array
|
||||||
|
{
|
||||||
return $this->files;
|
return $this->files;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function removeFile(string $path) {
|
/**
|
||||||
|
* Get files of this commit.
|
||||||
|
*
|
||||||
|
* @param string $path File path
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
|
public function removeFile(string $path) : bool
|
||||||
|
{
|
||||||
|
if(isset($this->files[$path])) {
|
||||||
|
unset($this->files[$path]);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set commit author.
|
||||||
|
*
|
||||||
|
* @param Author $author Commit author
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
public function setAuthor(Author $author)
|
public function setAuthor(Author $author)
|
||||||
{
|
{
|
||||||
$this->author = $author;
|
$this->author = $author;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get commit author.
|
||||||
|
*
|
||||||
|
* @return Author
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
public function getAuthor() : Author
|
public function getAuthor() : Author
|
||||||
{
|
{
|
||||||
return $this->author;
|
return $this->author;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set commit branch.
|
||||||
|
*
|
||||||
|
* @param Branch $branch Commit branch
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
public function setBranch(Branch $branch) {
|
public function setBranch(Branch $branch) {
|
||||||
$this->branch = $branch;
|
$this->branch = $branch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get commit branch.
|
||||||
|
*
|
||||||
|
* @return Branch
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
public function getBranch() : Branch
|
public function getBranch() : Branch
|
||||||
{
|
{
|
||||||
return $this->branch;
|
return $this->branch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set commit tag.
|
||||||
|
*
|
||||||
|
* @param Repository $tag Commit tag
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
public function setTag(Tag $tag) {
|
public function setTag(Tag $tag) {
|
||||||
$this->tag = $tag;
|
$this->tag = $tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get commit tag.
|
||||||
|
*
|
||||||
|
* @return Tag
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
public function getTag() : Tag
|
public function getTag() : Tag
|
||||||
{
|
{
|
||||||
return $this->tag;
|
return $this->tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get commit date.
|
||||||
|
*
|
||||||
|
* @return \DateTime
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
public function getDate() : \DateTime
|
public function getDate() : \DateTime
|
||||||
{
|
{
|
||||||
return $this->date;
|
return $this->date ?? new \DateTime('now');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setRepository(Reporsitory $repository)
|
/**
|
||||||
|
* Set commit repository.
|
||||||
|
*
|
||||||
|
* @param Repository $repository Commit repository
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
|
public function setRepository(Repository $repository)
|
||||||
{
|
{
|
||||||
$this->repository = $repository;
|
$this->repository = $repository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRepository() : Reporsitory
|
/**
|
||||||
|
* Get commit repository.
|
||||||
|
*
|
||||||
|
* @return Repository
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
|
public function getRepository() : Repository
|
||||||
{
|
{
|
||||||
retrun $this->repository;
|
return $this->repository;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,80 @@
|
||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 7.0
|
||||||
|
*
|
||||||
|
* @category TBD
|
||||||
|
* @package TBD
|
||||||
|
* @author OMS Development Team <dev@oms.com>
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
* @copyright 2013 Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link http://orange-management.com
|
||||||
|
*/
|
||||||
namespace phpOMS\Utils\Git;
|
namespace phpOMS\Utils\Git;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gray encoding class
|
||||||
|
*
|
||||||
|
* @category Framework
|
||||||
|
* @package phpOMS\Asset
|
||||||
|
* @author OMS Development Team <dev@oms.com>
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @link http://orange-management.com
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
class Git {
|
class Git {
|
||||||
|
/**
|
||||||
|
* Git path.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
protected static $bin = '/usr/bin/git';
|
protected static $bin = '/usr/bin/git';
|
||||||
|
|
||||||
public static function setBin(string $path) {
|
/**
|
||||||
self::$bin = $path;
|
* Set git binary.
|
||||||
|
*
|
||||||
|
* @param string $path Git path
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
|
public static function setBin(string $path)
|
||||||
|
{
|
||||||
|
if(realpath($path) === false) {
|
||||||
|
throw new \PathException($path)
|
||||||
|
}
|
||||||
|
|
||||||
|
self::$bin = realpath($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getBin() : string {
|
/**
|
||||||
|
* Get git binary.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
|
public static function getBin() : string
|
||||||
|
{
|
||||||
return self::$bin;
|
return self::$bin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function test() : bool {
|
/**
|
||||||
|
* Test git.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
|
public static function test() : bool
|
||||||
|
{
|
||||||
$pipes = [];
|
$pipes = [];
|
||||||
$resource = proc_open(Git::getBin(), [1 => ['pipe', 'w'], 2 => ['pipe', 'w']], $pipes);
|
$resource = proc_open(Git::getBin(), [1 => ['pipe', 'w'], 2 => ['pipe', 'w']], $pipes);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,79 @@
|
||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 7.0
|
||||||
|
*
|
||||||
|
* @category TBD
|
||||||
|
* @package TBD
|
||||||
|
* @author OMS Development Team <dev@oms.com>
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
* @copyright 2013 Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link http://orange-management.com
|
||||||
|
*/
|
||||||
namespace phpOMS\Utils\Git;
|
namespace phpOMS\Utils\Git;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repository class
|
||||||
|
*
|
||||||
|
* @category Framework
|
||||||
|
* @package phpOMS\Asset
|
||||||
|
* @author OMS Development Team <dev@oms.com>
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @link http://orange-management.com
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
class Repository
|
class Repository
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Repository path.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
private $path = '';
|
private $path = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bare repository.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
private $bare = false;
|
private $bare = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Env variables.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
private $envOptions = [];
|
private $envOptions = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param string $path Repository path
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
public function __construct(string $path)
|
public function __construct(string $path)
|
||||||
{
|
{
|
||||||
$this->setPath($path);
|
$this->setPath($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create repository
|
||||||
|
*
|
||||||
|
* @param string $source Create repository from source (optional, can be remote)
|
||||||
|
* @param bool $bare Bare repository
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
public function create(string $source = null, bool $bare = false)
|
public function create(string $source = null, bool $bare = false)
|
||||||
{
|
{
|
||||||
if (!is_dir($this->path) || file_exists($this->path . '/.git')) {
|
if (!is_dir($this->path) || file_exists($this->path . '/.git')) {
|
||||||
|
|
@ -26,10 +87,18 @@ class Repository
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set repository path.
|
||||||
|
*
|
||||||
|
* @param string $path Path to repository
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
private function setPath(string $path)
|
private function setPath(string $path)
|
||||||
{
|
{
|
||||||
if (!is_dir($this->path)) {
|
if (!is_dir($path)) {
|
||||||
throw new \Exception('Is not a directory');
|
throw new \PathException($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->path = realpath($path);
|
$this->path = realpath($path);
|
||||||
|
|
@ -46,7 +115,15 @@ class Repository
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function run($cmd)
|
/**
|
||||||
|
* Run git command.
|
||||||
|
*
|
||||||
|
* @param string $cmd Command to run
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
|
private function run(string $cmd) : string
|
||||||
{
|
{
|
||||||
$cmd = Git::getBin() . ' ' . $cmd;
|
$cmd = Git::getBin() . ' ' . $cmd;
|
||||||
$pipes = [];
|
$pipes = [];
|
||||||
|
|
@ -81,11 +158,27 @@ class Repository
|
||||||
return $stdout;
|
return $stdout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get directory path.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
public function getDirectoryPath() : string
|
public function getDirectoryPath() : string
|
||||||
{
|
{
|
||||||
return $this->bare ? $this->path : $this->path . '/.git';
|
return $this->bare ? $this->path : $this->path . '/.git';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get status.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
public function status() : string
|
public function status() : string
|
||||||
{
|
{
|
||||||
return $this->run('status');
|
return $this->run('status');
|
||||||
|
|
@ -259,12 +352,20 @@ class Repository
|
||||||
$this->envOptions[$key] = $value;
|
$this->envOptions[$key] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMessage(string $commit) : string
|
public function getCommit(string $commit) : Commit
|
||||||
{
|
{
|
||||||
return $this->run('log --format=%B -n 1 ' . $commit);
|
return $this->run('log --format=%B -n 1 ' . $commit);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCommitsCount() : string
|
/**
|
||||||
|
* Count Commits.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
|
public function getCommitsCount(\DateTime $start = null, \DateTime $end = null, Author $author = null) : int
|
||||||
{
|
{
|
||||||
$result = $this->normalizeResult($this->run('shortlog -s -n --all'));
|
$result = $this->normalizeResult($this->run('shortlog -s -n --all'));
|
||||||
|
|
||||||
|
|
@ -276,16 +377,44 @@ class Repository
|
||||||
str_replace('\t', '|', trim($result));
|
str_replace('\t', '|', trim($result));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCommitsBy(string $author, \DateTime $start, \DateTime $end) : string
|
/**
|
||||||
|
* Get commits by author.
|
||||||
|
*
|
||||||
|
* @param Author $author Commits by author
|
||||||
|
* @param \DateTime $start Commits from
|
||||||
|
* @param \DateTime $end Commits to
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
|
public function getCommitsBy(Author $author, \DateTime $start = null, \DateTime $end) : array
|
||||||
{
|
{
|
||||||
return $this->run('git log --before="' . $end->format('Y-m-d') . '" --after="' . $start->format('Y-m-d') . '" --author="' . $author . '" --reverse --pretty=format:"%cd %h %s" --date=short');
|
return $this->run('git log --before="' . $end->format('Y-m-d') . '" --after="' . $start->format('Y-m-d') . '" --author="' . $author->getName() . '" --reverse --pretty=format:"%cd %h %s" --date=short');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get remote.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
public function getRemote() : string
|
public function getRemote() : string
|
||||||
{
|
{
|
||||||
return $this->run('config --get remote.origin.url');
|
return $this->run('config --get remote.origin.url');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get newest commit.
|
||||||
|
*
|
||||||
|
* @return Commit
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
public function getNewest() : string
|
public function getNewest() : string
|
||||||
{
|
{
|
||||||
return $this->run('log --name-status HEAD^..HEAD');
|
return $this->run('log --name-status HEAD^..HEAD');
|
||||||
|
|
|
||||||
|
|
@ -45,10 +45,28 @@ class MultiMap implements \Countable
|
||||||
*/
|
*/
|
||||||
private $keys = [];
|
private $keys = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* UID.
|
||||||
|
*
|
||||||
|
* @var int[]
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
private $uids = [];
|
private $uids = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Key type.
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
private $keyType = KeyType::LOOSE;
|
private $keyType = KeyType::LOOSE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Order type.
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
private $orderType = OrderType::LOOSE;
|
private $orderType = OrderType::LOOSE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
73
Utils/RnG/ArrayRandomize.php
Normal file
73
Utils/RnG/ArrayRandomize.php
Normal file
|
|
@ -0,0 +1,73 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 7.0
|
||||||
|
*
|
||||||
|
* @category TBD
|
||||||
|
* @package TBD
|
||||||
|
* @author OMS Development Team <dev@oms.com>
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
* @copyright 2013 Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link http://orange-management.com
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace phpOMS\Utils\RnG;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Array randomizer class
|
||||||
|
*
|
||||||
|
* @category Framework
|
||||||
|
* @package phpOMS\Asset
|
||||||
|
* @author OMS Development Team <dev@oms.com>
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @link http://orange-management.com
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
class ArrayRandomize
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Yates array shuffler.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
|
public static function yates(array $arr) : array
|
||||||
|
{
|
||||||
|
$shuffled = [];
|
||||||
|
|
||||||
|
while($arr){
|
||||||
|
$rnd = array_rand($arr);
|
||||||
|
$shuffled[] = $arr[$rnd];
|
||||||
|
array_splice($arr, $rnd, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $shuffled;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Knuths array shuffler.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
|
public static function knuth(array $arr) : array
|
||||||
|
{
|
||||||
|
$shuffled = [];
|
||||||
|
|
||||||
|
for($i = count($arr)-1; $i > 0; $i--){
|
||||||
|
$rnd = mt_rand(0, $i);
|
||||||
|
$shuffled[$i] = $arr[$rnd];
|
||||||
|
$shuffled[$rand] = $arr[$i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $shuffled;
|
||||||
|
}
|
||||||
|
}
|
||||||
60
Utils/RnG/LinearCongruentialGenerator.php
Normal file
60
Utils/RnG/LinearCongruentialGenerator.php
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 7.0
|
||||||
|
*
|
||||||
|
* @category TBD
|
||||||
|
* @package TBD
|
||||||
|
* @author OMS Development Team <dev@oms.com>
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
* @copyright 2013 Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link http://orange-management.com
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace phpOMS\Utils\RnG;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Linear congruential generator class
|
||||||
|
*
|
||||||
|
* @category Framework
|
||||||
|
* @package phpOMS\Asset
|
||||||
|
* @author OMS Development Team <dev@oms.com>
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @link http://orange-management.com
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
class LinearCongruentialGenerator
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* BSD random number
|
||||||
|
*
|
||||||
|
* @return \Closure
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
|
public static function bsd(int $seed)
|
||||||
|
{
|
||||||
|
return function() use(&$seed) {
|
||||||
|
return $seed = (1103515245 * $seed + 12345) % (1 << 31);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MS random number
|
||||||
|
*
|
||||||
|
* @return \Closure
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
|
public static function msvcrt(int $seed) {
|
||||||
|
return function() use (&$seed) {
|
||||||
|
return ($seed = (214013 * $seed + 2531011) % (1 << 31)) >> 16;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user