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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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');
Note: See TracChangeset for help on using the changeset viewer.