Ignore:
Timestamp:
Jun 1, 2023, 12:18:18 AM (12 months ago)
Author:
chronos
Message:
  • Modified: Updated Common package.
  • Modified: Form types made as separate FormManager package.
  • Fixed: PHP 8.1 support.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Application/Core.php

    r7 r8  
    44if (file_exists($ConfigFileName)) include_once($ConfigFileName);
    55
    6 include_once(dirname(__FILE__).'/../Packages/Common/Common.php');
     6include_once(dirname(__FILE__).'/../Packages/Common/PackageCommon.php');
     7include_once(dirname(__FILE__).'/../Packages/FormManager/PackageFormManager.php');
    78include_once(dirname(__FILE__).'/Version.php');
    8 include_once(dirname(__FILE__).'/View.php');
     9include_once(dirname(__FILE__).'/BaseView.php');
     10include_once(dirname(__FILE__).'/PageMissing.php');
    911include_once(dirname(__FILE__).'/UpdateTrace.php');
    1012include_once(dirname(__FILE__).'/DefaultConfig.php');
    1113include_once(dirname(__FILE__).'/../Global.php');
    1214
    13 class Core extends Application
     15class Core extends System
    1416{
    15   var $Pages;
    16   var $ShowPage;
    17   var $BaseURL;
    18   var $Config;
    19   var $HeadItems;
    20   var $Bars;
    21   /** @var FormManager */
    22   var $FormManager;
     17  public bool $ShowPage;
     18  public string $BaseURL;
     19  public array $Config;
     20  public array $HeadItems;
     21  public array $Bars;
     22  public array $PathItems;
     23  public FormManager $FormManager;
     24  public BaseView $BaseView;
    2325
    2426  function __construct()
     
    6567    $this->RegisterPageBar('TopLeft');
    6668
    67     // Register and start existing modules
    68     $this->Setup = new Setup($this);
    69     $this->Setup->Start();
    70     if ($this->Setup->CheckState())
     69    $this->StartModules();
     70  }
     71
     72  function StartModules(): void
     73  {
     74    $ModuleSetup = $this->ModuleManager->LoadModule(dirname(__FILE__).'/../Packages/Common/Modules/ModuleSetup.php');
     75    $ModuleSetup->Install();
     76    $ModuleSetup->Start();
     77    $this->ModuleManager->LoadModules();
     78    $this->ModuleManager->LoadModule(dirname(__FILE__).'/../Packages/Common/Modules/ModuleAdmin.php');
     79    if (file_exists($this->ModuleManager->FileName)) $this->ModuleManager->LoadState();
     80    if (ModuleSetup::Cast($ModuleSetup)->CheckState())
    7181    {
    72       $this->ModuleManager->Start();
     82      $this->ModuleManager->StartAll(array(ModuleCondition::Enabled));
    7383    }
    7484  }
    7585
    76   function Run()
     86  function Run(): void
    7787  {
    7888    $this->RunCommon();
     
    98108    echo($this->BaseView->GetOutput($Page));
    99109  }
    100 
    101   function RegisterPage($Path, $Handler)
    102   {
    103     if (is_array($Path))
    104     {
    105       $Page = &$this->Pages;
    106       $LastKey = array_pop($Path);
    107       foreach ($Path as $PathItem)
    108       {
    109         $Page = &$Page[$PathItem];
    110       }
    111       if (!is_array($Page)) $Page = array('' => $Page);
    112       $Page[$LastKey] = $Handler;
    113     } else $this->Pages[$Path] = $Handler;
    114   }
    115 
    116   function UnregisterPage($Path)
    117   {
    118     unset($this->Pages[$Path]);
    119   }
    120 
     110 
    121111  function RegisterPageBar($Name)
    122112  {
     
    148138  }
    149139
    150   function Link($Target)
     140  function Link($Target): string
    151141  {
    152142    return $this->BaseURL.$Target;
    153143  }
    154 }
    155144
    156 class PageMissing extends Page
    157 {
    158   function __construct($System)
     145  static function Cast(System $System): Core
    159146  {
    160     parent::__construct($System);
    161     $this->ParentClass = '';
    162     $this->Title = T('Page not found');
    163   }
    164 
    165   function Show()
    166   {
    167     Header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found');
    168     return '<h3 align="center">'.T('Required page not found').'</h3>';
     147    if ($System instanceof Core)
     148    {
     149      return $System;
     150    }
     151    throw new Exception('Expected Core type but '.gettype($System));
    169152  }
    170153}
Note: See TracChangeset for help on using the changeset viewer.