Ignore:
Timestamp:
Nov 20, 2020, 12:08:12 AM (3 years ago)
Author:
chronos
Message:
  • Added: Static types added to almost all classes, methods and function. Supported by PHP 7.4.
  • Fixed: Various found code issues.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Common/Form/Types/File.php

    r874 r887  
    33class DbFile
    44{
    5   var $Id;
    6   var $FileName;
    7   var $Size;
    8   var $Directory;
    9   var $DirectoryId;
    10   var $TempName;
     5  public string $Id;
     6  public string $FileName;
     7  public int $Size;
     8  public string $Directory;
     9  public string $DirectoryId;
     10  public string $TempName;
    1111
    12   function DetectMimeType()
     12  function DetectMimeType(): string
    1313  {
    1414    // For proper mime-type detection php-pecl-Fileinfo package should be installed on *nix systems
     
    1919  }
    2020
    21   function GetSize($Item)
     21  function GetSize($Item): int
    2222  {
    2323    $FileName = $this->GetFullName($Item);
     
    2727  }
    2828
    29   function GetFullName()
     29  function GetFullName(): string
    3030  {
     31    $Path = '';
    3132    $ParentId = $this->Directory;
    3233    while ($ParentId != null)
     
    3738      $ParentId = $DbRow['Parent'];
    3839    }
    39     $Result = $this->UploadFileFolder.'/'.$Path.$File->Name;
     40    $Result = $this->UploadFileFolder.'/'.$Path.$this->FileName;
    4041    return $Result;
    4142  }
    4243
    43   function GetExt()
     44  function GetExt(): string
    4445  {
    4546    return substr($this->Name, 0, strpos($this->Name, '.') - 1);
    4647  }
    4748
    48   function Delete()
     49  function Delete(): void
    4950  {
    5051    if (file_exists($this->GetFullName())) unlink($this->GetFullName());
    5152  }
    5253
    53   function GetContent()
     54  function GetContent(): string
    5455  {
    5556    if ($this->TempName != '') $Content = file_get_contents($this->TempName);
     
    6162class TypeFile extends TypeBase
    6263{
    63   var $UploadFileFolder;
    64   var $FileDownloadURL;
    65   var $DirectoryId;
     64  public string $UploadFileFolder;
     65  public string $FileDownloadURL;
     66  public string $DirectoryId;
    6667
    67   function __construct($FormManager)
     68  function __construct(FormManager $FormManager)
    6869  {
    6970    parent::__construct($FormManager);
     
    7273  }
    7374
    74   function OnView($Item)
     75  function OnView(array $Item): ?string
    7576  {
    7677    $File = &$Item['Value'];
     
    7980  }
    8081
    81   function OnEdit($Item)
     82  function OnEdit(array $Item): string
    8283  {
    8384    // Check max value of upload_max_filesize
     
    8990  }
    9091
    91   function OnLoad($Item)
     92  function OnLoad(array $Item): ?string
    9293  {
    9394    if (!is_object($Item['Value'])) $Item['Value'] = new DbFile();
     
    106107  }
    107108
    108   function OnLoadDb($Item)
     109  function OnLoadDb(array $Item): ?string
    109110  {
    110111    if (!is_object($Item['Value'])) $Item['Value'] = new DbFile();
    111112    $File = &$Item['Value'];
    112113    $DbResult = $this->Database->select('File', '*', 'Id='.$File->Id);
    113     if ($DbResult->num_rows() > 0)
     114    if ($DbResult->num_rows > 0)
    114115    {
    115116      $DbRow = $DbResult->fetch_assoc();
     
    121122  }
    122123
    123   function OnSaveDb($Item)
     124  function OnSaveDb(array $Item): ?string
    124125  {
    125126    if (!is_object($Item['Value'])) $Item['Value'] = new DbFile();
     
    128129      'Size' => $File->GetSize(), 'Directory' => $File->Directory);
    129130    $DbResult = $this->Database->select('File', '*', 'Id='.$File->Id);
    130     if ($DbResult->num_rows() > 0)
     131    if ($DbResult->num_rows > 0)
    131132    {
    132133      $DbRow = $DbResult->fetch_assoc();
     
    143144    }
    144145    if (!move_uploaded_file($File->TempName, $FileName))
    145       SystemMessage('Nahrání souboru', 'Cílová složka není dostupná!');
     146      $this->System->SystemMessage('Nahrání souboru', 'Cílová složka není dostupná!');
     147    return '';
    146148  }
    147149
Note: See TracChangeset for help on using the changeset viewer.