Changeset 95 for trunk/Application


Ignore:
Timestamp:
Dec 6, 2021, 11:33:48 AM (3 years ago)
Author:
chronos
Message:
  • Modified: Updated Common package.
  • Added: Explicit types for better type checking.
  • Fixed: Support for php 8.0.
Location:
trunk/Application
Files:
4 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/Application/BaseView.php

    r94 r95  
    33class BaseView extends View
    44{
    5   function ShowPage($Content)
     5  function ShowPage(string $Content): string
    66  {
    77    global $ReleaseTime, $Revision;
     
    2222      ' &nbsp; <a href="https://app.zdechov.net/estetistic/">Zdrojový kód</a></div>';
    2323    $Output .= '</body></html>';
    24     echo($Output);
     24    return $Output;
    2525  }
    2626
    27   function GetOutput($Page)
     27  function GetOutput(Page $Page): string
    2828  {
    2929    $Output = $this->ShowPage($Page->Show());
  • trunk/Application/Core.php

    r92 r95  
    66include_once(dirname(__FILE__).'/../Global.php');
    77include_once(dirname(__FILE__).'/Version.php');
    8 include_once(dirname(__FILE__).'/View.php');
     8include_once(dirname(__FILE__).'/BaseView.php');
    99include_once(dirname(__FILE__).'/UpdateTrace.php');
    1010include_once(dirname(__FILE__).'/DefaultConfig.php');
    1111
    12 class Core extends Application
     12class Core extends System
    1313{
    14   var $Pages;
    15   var $ShowPage;
    16   var $BaseURL;
    17   var $UseSession;
     14  public array $Pages;
     15  public bool $ShowPage;
     16  public string $BaseURL;
     17  public bool $UseSession;
    1818
    1919  function __construct()
     
    2828  }
    2929
    30   function RunCommon()
     30  function RunCommon(): void
    3131  {
    3232    global $Config, $DatabaseRevision, $WithoutSessionStart;
     
    3838    //$ErrorHandler->Start();
    3939
    40     try {
     40    try
     41    {
    4142      $this->Database = new Database();
    4243      $this->Database->Connect($Config['Database']['Host'], $Config['Database']['User'],
     
    5556    $this->Config = &$Config;
    5657
    57     // Register and start existing modules
    58     $this->Setup = new Setup($this);
    59     $this->Setup->Start();
    60     if ($this->Setup->CheckState())
     58    $this->StartModules();
     59  }
     60
     61  function StartModules(): void
     62  {
     63    $ModuleSetup = $this->ModuleManager->LoadModule(dirname(__FILE__).'/../Packages/Common/Modules/Setup.php');
     64    $ModuleSetup->Install();
     65    $ModuleSetup->Start();
     66    $this->ModuleManager->LoadModules();
     67    $this->ModuleManager->LoadModule(dirname(__FILE__).'/../Packages/Common/Modules/ModuleManager.php');
     68    if (file_exists($this->ModuleManager->FileName)) $this->ModuleManager->LoadState();
     69    if (ModuleSetup::Cast($ModuleSetup)->CheckState())
    6170    {
    62       $this->ModuleManager->Start();
     71      $this->ModuleManager->StartAll(array(ModuleCondition::Enabled));
    6372    }
    6473  }
    6574
    66   function Run()
     75  function Run(): void
    6776  {
    6877    $this->RunCommon();
     
    7483  }
    7584
    76   function ShowPage()
     85  static function Cast(System $System): Core
     86  {
     87    if ($System instanceof Core)
     88    {
     89      return $System;
     90    }
     91    throw new Exception('Expected Core type but '.gettype($System));
     92  }
     93
     94  function ShowPage(): void
    7795  {
    7896    $this->BaseView = new BaseView($this);
     
    89107  }
    90108
    91   function RegisterPage($Path, $Handler)
    92   {
    93     if (is_array($Path))
    94     {
    95       $Page = &$this->Pages;
    96       $LastKey = array_pop($Path);
    97       foreach ($Path as $PathItem)
    98       {
    99         $Page = &$Page[$PathItem];
    100       }
    101       if (!is_array($Page)) $Page = array('' => $Page);
    102       $Page[$LastKey] = $Handler;
    103     } else $this->Pages[$Path] = $Handler;
    104   }
    105 
    106   function UnregisterPage($Path)
    107   {
    108     unset($this->Pages[$Path]);
    109   }
    110 
    111   function SearchPage($PathItems, $Pages)
     109  function SearchPage(array $PathItems, array $Pages): string
    112110  {
    113111    if (count($PathItems) > 0) $PathItem = $PathItems[0];
     
    123121  }
    124122
    125   function Link($Target)
     123  function Link(string $Target): string
    126124  {
    127125    return $this->BaseURL.$Target;
     
    138136  }
    139137
    140   function Show()
     138  function Show(): string
    141139  {
    142140    Header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found');
  • trunk/Application/DefaultConfig.php

    r92 r95  
    33class DefaultConfig
    44{
    5   function Get()
     5  function Get(): array
    66  {
    77    $IsDeveloper = in_array($_SERVER['REMOTE_ADDR'], array('127.0.0.1'));
  • trunk/Application/UpdateTrace.php

    r92 r95  
    11<?php
    22
    3 function FullInstall($Manager)
     3function FullInstall($Manager): void
    44{
    55   $Manager->Execute('CREATE TABLE IF NOT EXISTS `SystemVersion` (
     
    2929}
    3030
    31 function UpdateTo67($Manager)
     31function UpdateTo67($Manager): void
    3232{
    3333  $Manager->Execute('RENAME TABLE `measure` TO `Measure`;');
     
    5858}
    5959
    60 function UpdateTo79($Manager)
     60function UpdateTo79($Manager): void
    6161{
    6262  $DbResult = $Manager->Execute('SELECT `DataTable`,`DataType` FROM `Measure`;');
     
    7878class Updates
    7979{
    80   function Get()
     80  function Get(): array
    8181  {
    8282    return array(
  • trunk/Application/Version.php

    r94 r95  
    66// and system will need database update.
    77
    8 $Revision = 94;
     8$Revision = 95;
    99$DatabaseRevision = 79;
    10 $ReleaseTime = strtotime('2020-05-25');
     10$ReleaseTime = strtotime('2021-12-06');
Note: See TracChangeset for help on using the changeset viewer.