Skip to content

Commit

Permalink
HTML: Implement select/option objects, add to form
Browse files Browse the repository at this point in the history
  • Loading branch information
AniLeo committed Sep 15, 2024
1 parent d154c75 commit 3f8f497
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 0 deletions.
2 changes: 2 additions & 0 deletions html/HTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@
if (!@include_once(__DIR__."/HTMLA.php")) throw new Exception("Compat: HTMLA.php is missing. Failed to include HTMLA.php");
if (!@include_once(__DIR__."/HTMLImg.php")) throw new Exception("Compat: HTMLImg.php is missing. Failed to include HTMLImg.php");
if (!@include_once(__DIR__."/HTMLDiv.php")) throw new Exception("Compat: HTMLDiv.php is missing. Failed to include HTMLDiv.php");
if (!@include_once(__DIR__."/HTMLSelect.php")) throw new Exception("Compat: HTMLSelect.php is missing. Failed to include HTMLSelect.php");
if (!@include_once(__DIR__."/HTMLOption.php")) throw new Exception("Compat: HTMLOption.php is missing. Failed to include HTMLOption.php");
14 changes: 14 additions & 0 deletions html/HTMLForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class HTMLForm
public string $method;
/** @var array<HTMLInput> $inputs **/
public array $inputs;
/** @var array<HTMLSelect> $selects **/
public array $selects;
/** @var array<HTMLButton> $buttons **/
public array $buttons;

Expand All @@ -34,6 +36,7 @@ function __construct(string $action, string $method)
$this->action = $action;
$this->method = $method;
$this->inputs = array();
$this->selects = array();
$this->buttons = array();
}

Expand All @@ -42,6 +45,11 @@ public function add_input(HTMLInput $input) : void
$this->inputs[] = $input;
}

public function add_select(HTMLSelect $select) : void
{
$this->selects[] = $select;
}

public function add_button(HTMLButton $button) : void
{
$this->buttons[] = $button;
Expand All @@ -61,6 +69,12 @@ public function to_string() : ?string
$ret .= "<br>".PHP_EOL;
}

foreach ($this->selects as $select)
{
$ret .= $select->to_string();
$ret .= "<br>".PHP_EOL;
}

foreach ($this->buttons as $button)
{
$ret .= $button->to_string();
Expand Down
43 changes: 43 additions & 0 deletions html/HTMLOption.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/*
RPCS3.net Compatibility List (https://github.com/AniLeo/rpcs3-compatibility)
Copyright (C) 2017 AniLeo
https://github.com/AniLeo or [email protected]
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/


class HTMLOption
{
public string $value;
public string $text;

function __construct(string $value, string $text)
{
$this->value = $value;
$this->text = $text;
}

public function to_string() : string
{
return "<option value=\"{$this->value}\">{$this->text}</option>".PHP_EOL;
}

public function print() : void
{
echo $this->to_string();
}
}
58 changes: 58 additions & 0 deletions html/HTMLSelect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
/*
RPCS3.net Compatibility List (https://github.com/AniLeo/rpcs3-compatibility)
Copyright (C) 2017 AniLeo
https://github.com/AniLeo or [email protected]
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/


class HTMLSelect
{
public string $name;
/** @var array<HTMLOption> $options **/
public array $options;

function __construct(string $name)
{
$this->name = $name;
$this->options = array();
}

public function add_option(HTMLOption $option) : void
{
$this->options[] = $option;
}

public function to_string() : string
{
$ret = "<select name=\"{$this->name}\">".PHP_EOL;

foreach ($this->options as $option)
{
$ret .= $option->to_string();
}

$ret .= "</select>".PHP_EOL;

return $ret;
}

public function print() : void
{
echo $this->to_string();
}
}

0 comments on commit 3f8f497

Please sign in to comment.