Changeset 888 for trunk/Packages/Common
- Timestamp:
- Nov 24, 2020, 10:58:56 AM (4 years ago)
- Location:
- trunk/Packages/Common
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/BigInt.php
r870 r888 9 9 // First byte is MSB and last byte is LSB 10 10 11 function BigIntNew($BitWidth) 11 function BigIntNew($BitWidth): string 12 12 { 13 13 return str_repeat(chr(0), $BitWidth >> 3); 14 14 } 15 15 16 function BigIntNewAs($A) 16 function BigIntNewAs($A): string 17 17 { 18 18 return str_repeat(chr(0), strlen($A)); 19 19 } 20 20 21 function BigIntCheck( $A, $B)21 function BigIntCheck(string $A, string $B): void 22 22 { 23 23 if (strlen($A) != strlen($B)) … … 25 25 } 26 26 27 function BigIntAdd( $A, $B)27 function BigIntAdd(string $A, string $B): string 28 28 { 29 29 BigIntCheck($A, $B); … … 40 40 } 41 41 42 function BigIntSub( $A, $B)42 function BigIntSub(string $A, string $B): string 43 43 { 44 44 BigIntCheck($A, $B); … … 55 55 } 56 56 57 function BigIntInc( $A)57 function BigIntInc(string $A): string 58 58 { 59 59 $Result = BigIntNewAs($A); … … 69 69 } 70 70 71 function BigIntDec( $A)71 function BigIntDec(string $A): string 72 72 { 73 73 $Result = BigIntNewAs($A); … … 83 83 } 84 84 85 function BigIntNeg( $A)85 function BigIntNeg(string $A): string 86 86 { 87 87 return BigIntInc(BigIntNot($A)); 88 88 } 89 89 90 function BigIntIsNeg( $A)90 function BigIntIsNeg(string $A): string 91 91 { 92 92 return ord($A[0]) & 0x80; 93 93 } 94 94 95 function BigIntEqual( $A, $B)95 function BigIntEqual(string $A, string $B): bool 96 96 { 97 97 return $A == $B; // Simple string comparison 98 98 } 99 99 100 function BigIntNotEqual( $A, $B)100 function BigIntNotEqual(string $A, string $B): bool 101 101 { 102 102 return $A != $B; // Simple string comparison 103 103 } 104 104 105 function BigIntGreater( $A, $B)105 function BigIntGreater(string $A, string $B): bool 106 106 { 107 107 return BigIntIsNeg(BigIntSub($B, $A)); 108 108 } 109 109 110 function BigIntGreaterOrEqual( $A, $B)110 function BigIntGreaterOrEqual(string $A, string $B): bool 111 111 { 112 112 return BigIntIsNeg(BigIntSub($B, $A)) or BigIntEqual($A, $B); 113 113 } 114 114 115 function BigIntLesser( $A, $B)115 function BigIntLesser(string $A, string $B): bool 116 116 { 117 117 return BigIntIsNeg(BigIntSub($A, $B)); 118 118 } 119 119 120 function BigIntLesserOrEqual( $A, $B)120 function BigIntLesserOrEqual(string $A, string $B): bool 121 121 { 122 122 return BigIntIsNeg(BigIntSub($A, $B)) or BigIntEqual($A, $B); 123 123 } 124 124 125 function BigIntMul( $A, $B)126 { 127 BigIntCheck($A, $B); 128 $Result = BigIntNewAs($A); 129 while (BigIntGreater($B, BigIntNew ()))125 function BigIntMul(string $A, string $B): string 126 { 127 BigIntCheck($A, $B); 128 $Result = BigIntNewAs($A); 129 while (BigIntGreater($B, BigIntNewAs($A))) 130 130 { 131 131 $Result = BigIntAdd($Result, $A); … … 135 135 } 136 136 137 function BigIntDiv( $A, $B)137 function BigIntDiv(string $A, string $B): string 138 138 { 139 139 BigIntCheck($A, $B); … … 147 147 } 148 148 149 function BigIntMod( $A, $B)149 function BigIntMod(string $A, string $B): string 150 150 { 151 151 BigIntCheck($A, $B); … … 159 159 } 160 160 161 function BigIntAnd( $A, $B)161 function BigIntAnd(string $A, string $B): string 162 162 { 163 163 BigIntCheck($A, $B); … … 170 170 } 171 171 172 function BigIntOr( $A, $B)172 function BigIntOr(string $A, string $B): string 173 173 { 174 174 BigIntCheck($A, $B); … … 181 181 } 182 182 183 function BigIntXor( $A, $B)183 function BigIntXor(string $A, string $B): string 184 184 { 185 185 BigIntCheck($A, $B); … … 192 192 } 193 193 194 function BigIntNot( $A)194 function BigIntNot(string $A): string 195 195 { 196 196 $Result = BigIntNewAs($A); … … 202 202 } 203 203 204 function BigIntShl1( $A)204 function BigIntShl1(string $A): string 205 205 { 206 206 $Result = BigIntNewAs($A); … … 213 213 } 214 214 215 function BigIntShl( $A, $B)215 function BigIntShl(string $A, string $B): string 216 216 { 217 217 BigIntCheck($A, $B); … … 224 224 } 225 225 226 function BigIntShr1( $A)226 function BigIntShr1(string $A): string 227 227 { 228 228 $Result = BigIntNewAs($A); … … 235 235 } 236 236 237 function BigIntShr( $A, $B)237 function BigIntShr(string $A, string $B): string 238 238 { 239 239 BigIntCheck($A, $B); … … 246 246 } 247 247 248 function BigIntToHex( $A)248 function BigIntToHex(string $A): string 249 249 { 250 250 $Result = ''; … … 256 256 } 257 257 258 function HexToBigInt( $A, $BitWidth)258 function HexToBigInt(string $A, int $BitWidth): string 259 259 { 260 260 $Result = BigIntNew($BitWidth); … … 275 275 } 276 276 277 function BigIntToBin( $A)277 function BigIntToBin(string $A): string 278 278 { 279 279 $Result = ''; … … 285 285 } 286 286 287 function BinToBigInt( $A, $BitWidth)287 function BinToBigInt(string $A, int $BitWidth): string 288 288 { 289 289 $Result = BigIntNew($BitWidth); … … 305 305 } 306 306 307 function BigIntToInt( $A)307 function BigIntToInt(string $A): int 308 308 { 309 309 // 32-bit int support … … 311 311 } 312 312 313 function IntToBigInt( $A, $BitWidth)313 function IntToBigInt(int $A, int $BitWidth): string 314 314 { 315 315 $Result = BigIntNew($BitWidth); … … 322 322 } 323 323 324 function BigIntToDec( $A)324 function BigIntToDec(string $A): string 325 325 { 326 326 $BitWidth = strlen($A) << 3; … … 335 335 } 336 336 337 function DecToBigInt( $A, $BitWidth)337 function DecToBigInt(string $A, int $BitWidth): string 338 338 { 339 339 $Result = BigIntNew($BitWidth); … … 342 342 { 343 343 $Result = BigIntMul($Result, IntToBigInt(10, $BitWidth)); 344 $Result = BigIntAdd($Result, IntToBigInt(intval($A[$I] , $BitWidth)));344 $Result = BigIntAdd($Result, IntToBigInt(intval($A[$I]), $BitWidth)); 345 345 $I++; 346 346 } -
trunk/Packages/Common/Config.php
r874 r888 3 3 class Config 4 4 { 5 var$Data;5 public array $Data; 6 6 7 7 function __construct() … … 10 10 } 11 11 12 function ReadValue( $Name)12 function ReadValue(string $Name) 13 13 { 14 14 if (!is_array($Name)) $Name = explode('/', $Name); … … 22 22 } 23 23 24 function WriteValue( $Name, $Value)24 function WriteValue(string $Name, $Value) 25 25 { 26 26 if (!is_array($Name)) $Name = explode('/', $Name); … … 34 34 } 35 35 36 function LoadFromFile( $FileName)36 function LoadFromFile(string $FileName): void 37 37 { 38 38 $ConfigData = array(); … … 40 40 foreach ($this->Data as $Index => $Item) 41 41 { 42 if (array_key_exi ts($Index, $ConfigData))42 if (array_key_exists($Index, $ConfigData)) 43 43 $this->Data[$Index] = $ConfigData[$Index]; 44 44 } 45 45 } 46 46 47 function SaveToFile( $FileName)47 function SaveToFile(string $FileName): void 48 48 { 49 49 file_put_contents($FileName, "<?php \n\n\$ConfigData = ".var_export($this->Data, true).";\n"); 50 50 } 51 51 52 function GetAsArray() 52 function GetAsArray(): array 53 53 { 54 54 return $this->Data; -
trunk/Packages/Common/Database.php
r887 r888 12 12 class DatabaseResult 13 13 { 14 var$PDOStatement;14 public PDOStatement $PDOStatement; 15 15 public int $num_rows = 0; 16 16 -
trunk/Packages/Common/Generics.php
r887 r888 3 3 class GenericList 4 4 { 5 var$Items = array();5 public array $Items = array(); 6 6 7 7 function Add($Item): void -
trunk/Packages/Common/NetworkAddress.php
r874 r888 5 5 class NetworkAddressIPv4 6 6 { 7 var$Address;8 var$Prefix;7 public int $Address; 8 public int $Prefix; 9 9 10 10 function __construct() … … 14 14 } 15 15 16 function GetNetMask() 16 function GetNetMask(): int 17 17 { 18 18 return ((1 << IPV4_BIT_WIDTH) - 1) ^ ((1 << (IPV4_BIT_WIDTH - $this->Prefix)) - 1); 19 19 } 20 20 21 function AddressToString() 21 function AddressToString(): string 22 22 { 23 23 return implode('.', array(($this->Address >> 24) & 255, ($this->Address >> 16) & 255, ($this->Address >> 8) & 255, ($this->Address & 255))); 24 24 } 25 25 26 function AddressFromString( $Value)26 function AddressFromString(string $Value): void 27 27 { 28 28 $Parts = explode('.', $Value); … … 30 30 } 31 31 32 function GetRange() 32 function GetRange(): array 33 33 { 34 34 $From = new NetworkAddressIPv4(); … … 42 42 } 43 43 44 function ChangePrefix( $NewPrefix)44 function ChangePrefix(int $NewPrefix): void 45 45 { 46 46 $this->Prefix = $NewPrefix; … … 50 50 } 51 51 52 function Contain( $Address)52 function Contain(NetworkAddressIPv4 $Address): bool 53 53 { 54 54 $UpperNetmask = $this->GetNetMask(); … … 63 63 class NetworkAddressIPv6 64 64 { 65 var$Address;66 var$Prefix;65 public string $Address; 66 public int $Prefix; 67 67 68 68 function __construct() … … 72 72 } 73 73 74 function GetNetMask() 74 function GetNetMask(): string 75 75 { 76 76 return Int128Xor(Int128Sub(Int128Shl(IntToInt128(1), IntToInt128(IPV6_BIT_WIDTH)), IntToInt128(1)), … … 78 78 } 79 79 80 function AddressToString() 80 function AddressToString(): string 81 81 { 82 82 return inet_ntop($this->Address); 83 83 } 84 84 85 function AddressFromString( $Value)85 function AddressFromString(string $Value) 86 86 { 87 87 $this->Address = inet_pton($Value); 88 88 } 89 89 90 function ChangePrefix( $NewPrefix)90 function ChangePrefix(int $NewPrefix): void 91 91 { 92 92 $this->Prefix = $NewPrefix; … … 96 96 } 97 97 98 function GetOctets() 98 function GetOctets(): array 99 99 { 100 100 $Result = array(); … … 109 109 } 110 110 111 function EncodeMAC( $MAC)111 function EncodeMAC(string $MAC): void 112 112 { 113 113 $MAC = explode(':', $MAC); … … 124 124 } 125 125 126 function Contain( $Address)126 function Contain(NetworkAddressIPv6 $Address): bool 127 127 { 128 128 $UpperNetmask = $this->GetNetMask(); -
trunk/Packages/Common/Page.php
r887 r888 7 7 public string $ParentClass; 8 8 public bool $ClearPage; 9 var$OnSystemMessage;9 public $OnSystemMessage; 10 10 public string $Load; 11 11 public string $Unload; -
trunk/Packages/Common/Process.php
r874 r888 3 3 class Process 4 4 { 5 var$Command;6 var$Handle;7 var$Pipes;8 var$Environment;9 var$WorkingDir;10 5 public string $Command; 6 public $Handle; 7 public array $Pipes; 8 public array $Environment; 9 public ?string $WorkingDir; 10 11 11 function __construct() 12 12 { … … 17 17 $this->WorkingDir = null; 18 18 } 19 20 function Start() 19 20 function Start(): void 21 21 { 22 22 if (!$this->IsRunning()) … … 28 28 ); 29 29 30 $this->Handle = proc_open($this->Command, $DescriptorSpec, $this->Pipes, 30 $this->Handle = proc_open($this->Command, $DescriptorSpec, $this->Pipes, 31 31 $this->WorkingDir, $this->Environment); 32 32 stream_set_blocking($this->Pipes[0], FALSE); … … 35 35 } 36 36 } 37 38 function Stop() 37 38 function Stop(): void 39 39 { 40 if ($this->IsRunning()) 40 if ($this->IsRunning()) 41 41 { 42 42 proc_close($this->Handle); … … 44 44 } 45 45 } 46 47 function IsRunning() 46 47 function IsRunning(): bool 48 48 { 49 49 return is_resource($this->Handle); -
trunk/Packages/Common/Table.php
r887 r888 3 3 class Control 4 4 { 5 var$Name;5 public string $Name; 6 6 7 7 function Show(): string -
trunk/Packages/Common/UTF8.php
r887 r888 526 526 } 527 527 528 function ToUTF8string ($String, string $Charset = 'iso2'): string528 function ToUTF8string(string $String, string $Charset = 'iso2'): string 529 529 { 530 530 $Result = ''; -
trunk/Packages/Common/Update.php
r887 r888 18 18 } 19 19 20 function GetDbVersion() 20 function GetDbVersion(): string 21 21 { 22 22 $DbResult = $this->Database->select($this->VersionTable, '*', 'Id=1'); … … 25 25 } 26 26 27 function IsInstalled() 27 function IsInstalled(): bool 28 28 { 29 29 $DbResult = $this->Database->query('SHOW TABLES LIKE "'.$this->VersionTable.'"'); … … 31 31 } 32 32 33 function IsUpToDate() 33 function IsUpToDate(): bool 34 34 { 35 35 return $this->Revision <= $this->GetDbVersion(); 36 36 } 37 37 38 function Upgrade() 38 function Upgrade(): string 39 39 { 40 40 $DbRevision = $this->GetDbVersion(); … … 58 58 } 59 59 60 function Install() 60 function Install(): void 61 61 { 62 62 $InstallMethod = $this->InstallMethod; … … 64 64 } 65 65 66 function Uninstall() 66 function Uninstall(): void 67 67 { 68 69 68 } 70 69 71 function InsertSampleData() 70 function InsertSampleData(): void 72 71 { 73 72 $InstallMethod = $this->InsertSampleDataMethod;
Note:
See TracChangeset
for help on using the changeset viewer.