Changeset 888 for trunk/Packages/Common


Ignore:
Timestamp:
Nov 24, 2020, 10:58:56 AM (4 years ago)
Author:
chronos
Message:
  • Modified: More static types added.
Location:
trunk/Packages/Common
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/Common/BigInt.php

    r870 r888  
    99// First byte is MSB and last byte is LSB
    1010
    11 function BigIntNew($BitWidth)
     11function BigIntNew($BitWidth): string
    1212{
    1313  return str_repeat(chr(0), $BitWidth >> 3);
    1414}
    1515
    16 function BigIntNewAs($A)
     16function BigIntNewAs($A): string
    1717{
    1818  return str_repeat(chr(0), strlen($A));
    1919}
    2020
    21 function BigIntCheck($A, $B)
     21function BigIntCheck(string $A, string $B): void
    2222{
    2323    if (strlen($A) != strlen($B))
     
    2525}
    2626
    27 function BigIntAdd($A, $B)
     27function BigIntAdd(string $A, string $B): string
    2828{
    2929  BigIntCheck($A, $B);
     
    4040}
    4141
    42 function BigIntSub($A, $B)
     42function BigIntSub(string $A, string $B): string
    4343{
    4444  BigIntCheck($A, $B);
     
    5555}
    5656
    57 function BigIntInc($A)
     57function BigIntInc(string $A): string
    5858{
    5959  $Result = BigIntNewAs($A);
     
    6969}
    7070
    71 function BigIntDec($A)
     71function BigIntDec(string $A): string
    7272{
    7373  $Result = BigIntNewAs($A);
     
    8383}
    8484
    85 function BigIntNeg($A)
     85function BigIntNeg(string $A): string
    8686{
    8787  return BigIntInc(BigIntNot($A));
    8888}
    8989
    90 function BigIntIsNeg($A)
     90function BigIntIsNeg(string $A): string
    9191{
    9292  return ord($A[0]) & 0x80;
    9393}
    9494
    95 function BigIntEqual($A, $B)
     95function BigIntEqual(string $A, string $B): bool
    9696{
    9797  return $A == $B; // Simple string comparison
    9898}
    9999
    100 function BigIntNotEqual($A, $B)
     100function BigIntNotEqual(string $A, string $B): bool
    101101{
    102102  return $A != $B; // Simple string comparison
    103103}
    104104
    105 function BigIntGreater($A, $B)
     105function BigIntGreater(string $A, string $B): bool
    106106{
    107107  return BigIntIsNeg(BigIntSub($B, $A));
    108108}
    109109
    110 function BigIntGreaterOrEqual($A, $B)
     110function BigIntGreaterOrEqual(string $A, string $B): bool
    111111{
    112112  return BigIntIsNeg(BigIntSub($B, $A)) or BigIntEqual($A, $B);
    113113}
    114114
    115 function BigIntLesser($A, $B)
     115function BigIntLesser(string $A, string $B): bool
    116116{
    117117  return BigIntIsNeg(BigIntSub($A, $B));
    118118}
    119119
    120 function BigIntLesserOrEqual($A, $B)
     120function BigIntLesserOrEqual(string $A, string $B): bool
    121121{
    122122  return BigIntIsNeg(BigIntSub($A, $B)) or BigIntEqual($A, $B);
    123123}
    124124
    125 function BigIntMul($A, $B)
    126 {
    127   BigIntCheck($A, $B);
    128   $Result = BigIntNewAs($A);
    129   while (BigIntGreater($B, BigIntNew()))
     125function BigIntMul(string $A, string $B): string
     126{
     127  BigIntCheck($A, $B);
     128  $Result = BigIntNewAs($A);
     129  while (BigIntGreater($B, BigIntNewAs($A)))
    130130  {
    131131    $Result = BigIntAdd($Result, $A);
     
    135135}
    136136
    137 function BigIntDiv($A, $B)
     137function BigIntDiv(string $A, string $B): string
    138138{
    139139  BigIntCheck($A, $B);
     
    147147}
    148148
    149 function BigIntMod($A, $B)
     149function BigIntMod(string $A, string $B): string
    150150{
    151151  BigIntCheck($A, $B);
     
    159159}
    160160
    161 function BigIntAnd($A, $B)
     161function BigIntAnd(string $A, string $B): string
    162162{
    163163  BigIntCheck($A, $B);
     
    170170}
    171171
    172 function BigIntOr($A, $B)
     172function BigIntOr(string $A, string $B): string
    173173{
    174174  BigIntCheck($A, $B);
     
    181181}
    182182
    183 function BigIntXor($A, $B)
     183function BigIntXor(string $A, string $B): string
    184184{
    185185  BigIntCheck($A, $B);
     
    192192}
    193193
    194 function BigIntNot($A)
     194function BigIntNot(string $A): string
    195195{
    196196  $Result = BigIntNewAs($A);
     
    202202}
    203203
    204 function BigIntShl1($A)
     204function BigIntShl1(string $A): string
    205205{
    206206  $Result = BigIntNewAs($A);
     
    213213}
    214214
    215 function BigIntShl($A, $B)
     215function BigIntShl(string $A, string $B): string
    216216{
    217217  BigIntCheck($A, $B);
     
    224224}
    225225
    226 function BigIntShr1($A)
     226function BigIntShr1(string $A): string
    227227{
    228228  $Result = BigIntNewAs($A);
     
    235235}
    236236
    237 function BigIntShr($A, $B)
     237function BigIntShr(string $A, string $B): string
    238238{
    239239  BigIntCheck($A, $B);
     
    246246}
    247247
    248 function BigIntToHex($A)
     248function BigIntToHex(string $A): string
    249249{
    250250  $Result = '';
     
    256256}
    257257
    258 function HexToBigInt($A, $BitWidth)
     258function HexToBigInt(string $A, int $BitWidth): string
    259259{
    260260  $Result = BigIntNew($BitWidth);
     
    275275}
    276276
    277 function BigIntToBin($A)
     277function BigIntToBin(string $A): string
    278278{
    279279  $Result = '';
     
    285285}
    286286
    287 function BinToBigInt($A, $BitWidth)
     287function BinToBigInt(string $A, int $BitWidth): string
    288288{
    289289  $Result = BigIntNew($BitWidth);
     
    305305}
    306306
    307 function BigIntToInt($A)
     307function BigIntToInt(string $A): int
    308308{
    309309  // 32-bit int support
     
    311311}
    312312
    313 function IntToBigInt($A, $BitWidth)
     313function IntToBigInt(int $A, int $BitWidth): string
    314314{
    315315  $Result = BigIntNew($BitWidth);
     
    322322}
    323323
    324 function BigIntToDec($A)
     324function BigIntToDec(string $A): string
    325325{
    326326  $BitWidth = strlen($A) << 3;
     
    335335}
    336336
    337 function DecToBigInt($A, $BitWidth)
     337function DecToBigInt(string $A, int $BitWidth): string
    338338{
    339339  $Result = BigIntNew($BitWidth);
     
    342342  {
    343343    $Result = BigIntMul($Result, IntToBigInt(10, $BitWidth));
    344     $Result = BigIntAdd($Result, IntToBigInt(intval($A[$I], $BitWidth)));
     344    $Result = BigIntAdd($Result, IntToBigInt(intval($A[$I]), $BitWidth));
    345345    $I++;
    346346  }
  • trunk/Packages/Common/Config.php

    r874 r888  
    33class Config
    44{
    5   var $Data;
     5  public array $Data;
    66
    77  function __construct()
     
    1010  }
    1111
    12   function ReadValue($Name)
     12  function ReadValue(string $Name)
    1313  {
    1414    if (!is_array($Name)) $Name = explode('/', $Name);
     
    2222  }
    2323
    24   function WriteValue($Name, $Value)
     24  function WriteValue(string $Name, $Value)
    2525  {
    2626    if (!is_array($Name)) $Name = explode('/', $Name);
     
    3434  }
    3535
    36   function LoadFromFile($FileName)
     36  function LoadFromFile(string $FileName): void
    3737  {
    3838    $ConfigData = array();
     
    4040    foreach ($this->Data as $Index => $Item)
    4141    {
    42       if (array_key_exits($Index, $ConfigData))
     42      if (array_key_exists($Index, $ConfigData))
    4343        $this->Data[$Index] = $ConfigData[$Index];
    4444    }
    4545  }
    4646
    47   function SaveToFile($FileName)
     47  function SaveToFile(string $FileName): void
    4848  {
    4949    file_put_contents($FileName, "<?php \n\n\$ConfigData = ".var_export($this->Data, true).";\n");
    5050  }
    5151
    52   function GetAsArray()
     52  function GetAsArray(): array
    5353  {
    5454    return $this->Data;
  • trunk/Packages/Common/Database.php

    r887 r888  
    1212class DatabaseResult
    1313{
    14   var $PDOStatement;
     14  public PDOStatement $PDOStatement;
    1515  public int $num_rows = 0;
    1616
  • trunk/Packages/Common/Generics.php

    r887 r888  
    33class GenericList
    44{
    5   var $Items = array();
     5  public array $Items = array();
    66
    77  function Add($Item): void
  • trunk/Packages/Common/NetworkAddress.php

    r874 r888  
    55class NetworkAddressIPv4
    66{
    7   var $Address;
    8   var $Prefix;
     7  public int $Address;
     8  public int $Prefix;
    99
    1010  function __construct()
     
    1414  }
    1515
    16   function GetNetMask()
     16  function GetNetMask(): int
    1717  {
    1818    return ((1 << IPV4_BIT_WIDTH) - 1) ^ ((1 << (IPV4_BIT_WIDTH - $this->Prefix)) - 1);
    1919  }
    2020
    21   function AddressToString()
     21  function AddressToString(): string
    2222  {
    2323    return implode('.', array(($this->Address >> 24) & 255, ($this->Address >> 16) & 255, ($this->Address >> 8) & 255, ($this->Address & 255)));
    2424  }
    2525
    26   function AddressFromString($Value)
     26  function AddressFromString(string $Value): void
    2727  {
    2828    $Parts = explode('.', $Value);
     
    3030  }
    3131
    32   function GetRange()
     32  function GetRange(): array
    3333  {
    3434    $From = new NetworkAddressIPv4();
     
    4242  }
    4343
    44   function ChangePrefix($NewPrefix)
     44  function ChangePrefix(int $NewPrefix): void
    4545  {
    4646    $this->Prefix = $NewPrefix;
     
    5050  }
    5151
    52   function Contain($Address)
     52  function Contain(NetworkAddressIPv4 $Address): bool
    5353  {
    5454    $UpperNetmask = $this->GetNetMask();
     
    6363class NetworkAddressIPv6
    6464{
    65   var $Address;
    66   var $Prefix;
     65  public string $Address;
     66  public int $Prefix;
    6767
    6868  function __construct()
     
    7272  }
    7373
    74   function GetNetMask()
     74  function GetNetMask(): string
    7575  {
    7676    return Int128Xor(Int128Sub(Int128Shl(IntToInt128(1), IntToInt128(IPV6_BIT_WIDTH)), IntToInt128(1)),
     
    7878  }
    7979
    80   function AddressToString()
     80  function AddressToString(): string
    8181  {
    8282    return inet_ntop($this->Address);
    8383  }
    8484
    85   function AddressFromString($Value)
     85  function AddressFromString(string $Value)
    8686  {
    8787    $this->Address = inet_pton($Value);
    8888  }
    8989
    90   function ChangePrefix($NewPrefix)
     90  function ChangePrefix(int $NewPrefix): void
    9191  {
    9292    $this->Prefix = $NewPrefix;
     
    9696  }
    9797
    98   function GetOctets()
     98  function GetOctets(): array
    9999  {
    100100    $Result = array();
     
    109109  }
    110110
    111   function EncodeMAC($MAC)
     111  function EncodeMAC(string $MAC): void
    112112  {
    113113    $MAC = explode(':', $MAC);
     
    124124  }
    125125
    126   function Contain($Address)
     126  function Contain(NetworkAddressIPv6 $Address): bool
    127127  {
    128128    $UpperNetmask = $this->GetNetMask();
  • trunk/Packages/Common/Page.php

    r887 r888  
    77  public string $ParentClass;
    88  public bool $ClearPage;
    9   var $OnSystemMessage;
     9  public $OnSystemMessage;
    1010  public string $Load;
    1111  public string $Unload;
  • trunk/Packages/Common/Process.php

    r874 r888  
    33class Process
    44{
    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
    1111  function __construct()
    1212  {
     
    1717    $this->WorkingDir = null;
    1818  }
    19  
    20   function Start()
     19
     20  function Start(): void
    2121  {
    2222    if (!$this->IsRunning())
     
    2828      );
    2929
    30       $this->Handle = proc_open($this->Command, $DescriptorSpec, $this->Pipes, 
     30      $this->Handle = proc_open($this->Command, $DescriptorSpec, $this->Pipes,
    3131        $this->WorkingDir, $this->Environment);
    3232      stream_set_blocking($this->Pipes[0], FALSE);
     
    3535    }
    3636  }
    37  
    38   function Stop()
     37
     38  function Stop(): void
    3939  {
    40     if ($this->IsRunning()) 
     40    if ($this->IsRunning())
    4141    {
    4242      proc_close($this->Handle);
     
    4444    }
    4545  }
    46  
    47   function IsRunning()
     46
     47  function IsRunning(): bool
    4848  {
    4949    return is_resource($this->Handle);
  • trunk/Packages/Common/Table.php

    r887 r888  
    33class Control
    44{
    5   var $Name;
     5  public string $Name;
    66
    77  function Show(): string
  • trunk/Packages/Common/UTF8.php

    r887 r888  
    526526  }
    527527
    528   function ToUTF8string ($String, string $Charset = 'iso2'): string
     528  function ToUTF8string(string $String, string $Charset = 'iso2'): string
    529529  {
    530530    $Result = '';
  • trunk/Packages/Common/Update.php

    r887 r888  
    1818  }
    1919
    20   function GetDbVersion()
     20  function GetDbVersion(): string
    2121  {
    2222    $DbResult = $this->Database->select($this->VersionTable, '*', 'Id=1');
     
    2525  }
    2626
    27   function IsInstalled()
     27  function IsInstalled(): bool
    2828  {
    2929    $DbResult = $this->Database->query('SHOW TABLES LIKE "'.$this->VersionTable.'"');
     
    3131  }
    3232
    33   function IsUpToDate()
     33  function IsUpToDate(): bool
    3434  {
    3535    return $this->Revision <= $this->GetDbVersion();
    3636  }
    3737
    38   function Upgrade()
     38  function Upgrade(): string
    3939  {
    4040    $DbRevision = $this->GetDbVersion();
     
    5858  }
    5959
    60   function Install()
     60  function Install(): void
    6161  {
    6262    $InstallMethod = $this->InstallMethod;
     
    6464  }
    6565
    66   function Uninstall()
     66  function Uninstall(): void
    6767  {
    68 
    6968  }
    7069
    71   function InsertSampleData()
     70  function InsertSampleData(): void
    7271  {
    7372    $InstallMethod = $this->InsertSampleDataMethod;
Note: See TracChangeset for help on using the changeset viewer.