source: trunk/Packages/FormManager/Types/Type.php

Last change on this file was 8, checked in by chronos, 18 months ago
  • Modified: Updated Common package.
  • Modified: Form types made as separate FormManager package.
  • Fixed: PHP 8.1 support.
File size: 5.6 KB
Line 
1<?php
2
3include(dirname(__FILE__).'/Base.php');
4include(dirname(__FILE__).'/Enumeration.php');
5include(dirname(__FILE__).'/Boolean.php');
6include(dirname(__FILE__).'/Integer.php');
7include(dirname(__FILE__).'/String.php');
8include(dirname(__FILE__).'/Text.php');
9include(dirname(__FILE__).'/OneToMany.php');
10include(dirname(__FILE__).'/OneToMany2.php');
11include(dirname(__FILE__).'/Date.php');
12include(dirname(__FILE__).'/Time.php');
13include(dirname(__FILE__).'/DateTime.php');
14include(dirname(__FILE__).'/Password.php');
15include(dirname(__FILE__).'/Float.php');
16include(dirname(__FILE__).'/Hyperlink.php');
17include(dirname(__FILE__).'/Hidden.php');
18include(dirname(__FILE__).'/File.php');
19include(dirname(__FILE__).'/GPS.php');
20include(dirname(__FILE__).'/IPv4Address.php');
21include(dirname(__FILE__).'/IPv6Address.php');
22include(dirname(__FILE__).'/Color.php');
23include(dirname(__FILE__).'/RandomHash.php');
24include(dirname(__FILE__).'/MacAddress.php');
25include(dirname(__FILE__).'/Image.php');
26include(dirname(__FILE__).'/TimeDiff.php');
27
28class Type
29{
30 public FormManager $FormManager;
31 public array $TypeDefinitionList;
32 public array $Values;
33
34 function __construct(FormManager $FormManager)
35 {
36 $this->FormManager = &$FormManager;
37 $this->TypeDefinitionList = array
38 (
39 'Enumeration' => array('Name' => 'Enumeration', 'Class' => 'Enumeration', 'ParentType' => '', 'Parameters' => array()),
40 'Boolean' => array('Name' => 'Boolean', 'Class' => 'Boolean', 'ParentType' => '', 'Parameters' => array()),
41 'Integer' => array('Name' => 'Integer', 'Class' => 'Integer', 'ParentType' => '', 'Parameters' => array()),
42 'String' => array('Name' => 'String', 'Class' => 'String', 'ParentType' => '', 'Parameters' => array()),
43 'Text' => array('Name' => 'Text', 'Class' => 'Text', 'ParentType' => '', 'Parameters' => array()),
44 'Date' => array('Name' => 'Date', 'Class' => 'Date', 'ParentType' => '', 'Parameters' => array()),
45 'Time' => array('Name' => 'Time', 'Class' => 'Time', 'ParentType' => '', 'Parameters' => array()),
46 'DateTime' => array('Name' => 'DateTime', 'Class' => 'DateTime', 'ParentType' => '', 'Parameters' => array()),
47 'Password' => array('Name' => 'Password', 'Class' => 'Password', 'ParentType' => '', 'Parameters' => array()),
48 'Float' => array('Name' => 'Float', 'Class' => 'Float', 'ParentType' => '', 'Parameters' => array()),
49 'Hyperlink' => array('Name' => 'Hyperlink', 'Class' => 'Hyperlink', 'ParentType' => '', 'Parameters' => array()),
50 'Hidden' => array('Name' => 'Hidden', 'Class' => 'Hidden', 'ParentType' => '', 'Parameters' => array()),
51 'File' => array('Name' => 'File', 'Class' => 'File', 'ParentType' => '', 'Parameters' => array()),
52 'GPS' => array('Name' => 'GPS', 'Class' => 'GPS', 'ParentType' => '', 'Parameters' => array()),
53 'IPv4Address' => array('Name' => 'IPv4Address', 'Class' => 'IPv4Address', 'ParentType' => '', 'Parameters' => array()),
54 'OneToOne' => array('Name' => 'OneToOne', 'Class' => 'OneToOne', 'ParentType' => '', 'Parameters' => array()),
55 'OneToMany' => array('Name' => 'OneToMany', 'Class' => 'OneToMany', 'ParentType' => '', 'Parameters' => array()),
56 'Color' => array('Name' => 'Color', 'Class' => 'Color', 'ParentType' => '', 'Parameters' => array()),
57 'RandomHash' => array('Name' => 'RandomHash', 'Class' => 'RandomHash', 'ParentType' => '', 'Parameters' => array()),
58 'MacAddress' => array('Name' => 'MacAddress', 'Class' => 'MacAddress', 'ParentType' => '', 'Parameters' => array()),
59 'IPv6Address' => array('Name' => 'IPv6Address', 'Class' => 'IPv6Address', 'ParentType' => '', 'Parameters' => array()),
60 'Image' => array('Name' => 'Image', 'Class' => 'Image', 'ParentType' => '', 'Parameters' => array()),
61 'TimeDiff' => array('Name' => 'TimeDiff', 'Class' => 'TimeDiff', 'ParentType' => 'Integer', 'Parameters' => array()),
62 'Reference' => array('Name' => 'Reference', 'Class' => 'Reference', 'ParentType' => 'Integer', 'Parameters' => array()),
63 'ManyToOne' => array('Name' => 'ManyToOne', 'Class' => 'ManyToOne', 'ParentType' => '', 'Parameters' => array()),
64 );
65 }
66
67 function ExecuteTypeEvent(string $TypeName, string $Event, array $Parameters = array()): ?string
68 {
69 if (array_key_exists($TypeName, $this->TypeDefinitionList))
70 {
71 $Type = $this->TypeDefinitionList[$TypeName];
72 $TypeClass = 'Type'.$Type['Class'];
73 $TypeObject = new $TypeClass($this->FormManager);
74 if (is_callable(array($TypeObject, $Event))) return $TypeObject->$Event($Parameters);
75 else return $TypeName.'->'.$Event.'('.serialize($Parameters).')';
76 } else return $TypeName;
77 }
78
79 function IsHidden(string $TypeName): bool
80 {
81 if (array_key_exists($TypeName, $this->TypeDefinitionList))
82 {
83 $Type = $this->TypeDefinitionList[$TypeName];
84 $TypeClass = 'Type'.$Type['Class'];
85 $TypeObject = new $TypeClass($this->FormManager);
86 return $TypeObject->Hidden;
87 } else return false;
88 }
89
90 function RegisterType(string $Name, string $ParentType, array $Parameters): void
91 {
92 if ($ParentType != '')
93 {
94 $Type = $this->TypeDefinitionList[$ParentType];
95 } else $Type = array();
96
97 $Type['Name'] = $Name;
98 $Type['Class'] = $Name;
99 if (array_key_exists('Parameters', $Type))
100 $Type['Parameters'] = array_merge($Type['Parameters'], $Parameters);
101 else $Type['Parameters'] = $Parameters;
102 $this->TypeDefinitionList[$Name] = $Type;
103 }
104
105 function UnregisterType(string $Name): void
106 {
107 unset($this->TypeDefinitionList[$Name]);
108 // TODO: remove dependent types
109 }
110
111 function GetTypeDefinition(string $TypeName): array
112 {
113 return $this->TypeDefinitionList[$TypeName];
114 }
115}
Note: See TracBrowser for help on using the repository browser.