Skip to content

Commit 76a7d0d

Browse files
committed
WIP
1 parent f2d1160 commit 76a7d0d

File tree

9 files changed

+288
-8
lines changed

9 files changed

+288
-8
lines changed

src/Cache/Handler.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace HTTPFriend\Cache;
4+
5+
class Handler {
6+
7+
}

src/Form/Handler.php

Lines changed: 233 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,238 @@
22

33
namespace HTTPFriend\Form;
44

5+
use HTTPFriend\Tags\Tag as Tag;
6+
57
class Handler {
6-
8+
9+
public $subittedData;
10+
public $files;
11+
12+
public function __construct(){
13+
$this->tag = new Tag;
14+
}
15+
16+
public function open( $formSettings = [] ){
17+
18+
if( !isset( $formSettings["method"] ) )
19+
{
20+
$attributes["method"] = "POST";
21+
}
22+
else{
23+
$attributes["method"] = trim( $formSettings["method"] );
24+
}
25+
26+
if( isset( $formSettings["action"] ) ) {
27+
$attributes["action"] = $formSettings["action"];
28+
}
29+
else {
30+
$attributes["action"] = "./";
31+
}
32+
33+
$formname = "http-friend-name-";
34+
35+
if( isset( $formSettings["controller"] ) && isset( $formSettings["method"] ) )
36+
{
37+
$formname .= "-{$formSettings["controller"]}-{$formSettings["method"]}";
38+
}
39+
40+
$formname .= "-{$this->formcount}";
41+
42+
if( isset( $_POST[$formname] ) ){
43+
44+
$this->processFormSubmission();
45+
}
46+
47+
ob_start();
48+
$this->tag->output([ "tag" => "form", "attr" => $attributes ] );
49+
50+
51+
52+
$this->tag->output([ "tag" => "input", "attr" => [ "type" => "hidden", "name" => "http-friend-name" ] ] );
53+
echo ob_get_clean();
54+
}
55+
56+
public function close(){
57+
$this->tag->output( [ "tag" => "form", "close" => true ] );
58+
}
59+
60+
61+
public function processFormSubmission()
62+
{
63+
64+
}
65+
66+
public function text( $attr = [], $options = [] )
67+
{
68+
$attr["type"] = strtolower( __METHOD__ );
69+
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
70+
}
71+
72+
public function phone( $attr = [], $options = [] )
73+
{
74+
$attr["type"] = strtolower( __METHOD__ );
75+
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
76+
}
77+
78+
public function email( $attr = [], $options = [] )
79+
{
80+
$attr["type"] = strtolower( __METHOD__ );
81+
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
82+
}
83+
84+
public function number( $attr = [], $options = [] )
85+
{
86+
$attr["type"] = strtolower( __METHOD__ );
87+
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
88+
}
89+
90+
public function button( $attr = [], $options = [] )
91+
{
92+
$attr["type"] = strtolower( __METHOD__ );
93+
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
94+
}
95+
96+
public function password( $attr = [], $options = [] )
97+
{
98+
$attr["type"] = strtolower( __METHOD__ );
99+
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
100+
}
101+
public function hidden( $attr = [], $options = [] )
102+
{
103+
$attr["type"] = strtolower( __METHOD__ );
104+
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
105+
}
106+
107+
public function checkbox( $attr = [], $options = [] )
108+
{
109+
$attr["type"] = strtolower( __METHOD__ );
110+
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
111+
}
112+
113+
public function radio( $attr = [], $options = [] )
114+
{
115+
$attr["type"] = strtolower( __METHOD__ );
116+
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
117+
}
118+
119+
public function file( $attr = [], $options = [] )
120+
{
121+
$attr["type"] = strtolower( __METHOD__ );
122+
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
123+
}
124+
125+
public function image( $attr = [], $options = [] )
126+
{
127+
$attr["type"] = strtolower( __METHOD__ );
128+
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
129+
}
130+
131+
public function color( $attr = [], $options = [] )
132+
{
133+
$attr["type"] = strtolower( __METHOD__ );
134+
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
135+
}
136+
137+
public function color( $attr = [], $options = [] )
138+
{
139+
$attr["type"] = strtolower( __METHOD__ );
140+
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
141+
}
142+
143+
public function date( $attr = [], $options = [] )
144+
{
145+
$attr["type"] = strtolower( __METHOD__ );
146+
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
147+
}
148+
149+
public function datetimeLocal( $attr = [], $options = [] )
150+
{
151+
$attr["type"] = strtolower( str_replace( "L", "-l", __METHOD__) );
152+
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
153+
}
154+
155+
public function month( $attr = [], $options = [] )
156+
{
157+
$attr["type"] = strtolower( __METHOD__ );
158+
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
159+
}
160+
161+
public function range( $attr = [], $options = [] )
162+
{
163+
$attr["type"] = strtolower( __METHOD__ );
164+
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
165+
}
166+
167+
public function reset( $attr = [], $options = [] )
168+
{
169+
$attr["type"] = strtolower( __METHOD__ );
170+
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
171+
}
172+
173+
public function search( $attr = [], $options = [] )
174+
{
175+
$attr["type"] = strtolower( __METHOD__ );
176+
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
177+
}
178+
179+
public function tel( $attr = [], $options = [] )
180+
{
181+
$attr["type"] = strtolower( __METHOD__ );
182+
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
183+
}
184+
185+
public function url( $attr = [], $options = [] )
186+
{
187+
$attr["type"] = strtolower( __METHOD__ );
188+
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
189+
}
190+
191+
public function week( $attr = [], $options = [] )
192+
{
193+
$attr["type"] = strtolower( __METHOD__ );
194+
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
195+
}
196+
197+
public function submit( $attr = [], $options = [] )
198+
{
199+
$attr["type"] = strtolower( __METHOD__ );
200+
$this->tag->output( [ "tag" => "input", "attr" => $attr ] );
201+
}
202+
203+
public function textarea( $attr = [], $options )
204+
{
205+
206+
$value = $attr["value"];
207+
unset( $attr["value"] );
208+
$this->tag->output( [ "tag" => "textarea", "attr" => $attr ] );
209+
echo $value;
210+
$this->tag->output( [ "tag" => "textarea", "close" => true ] );
211+
}
212+
213+
public function select( $attr = [], $options = [] )
214+
{
215+
$value = $attr["value"];
216+
unset( $attr["value"] );
217+
$this->tag->output( [ "tag" => "select", "attr" => $attr ] );
218+
219+
if( !empty( $options ) ) {
220+
221+
foreach( $options as $ak => $av ){
222+
echo "<option "
223+
if( isset( $attr["valueOnly"] ) ){
224+
echo " value=\"{$av}\" ";
225+
}
226+
else {
227+
echo " value=\"{$ak}\" ";
228+
}
229+
echo ">{$av}</option>";
230+
231+
}
232+
233+
}
234+
235+
$this->tag->output( [ "tag", "close" => true ] );
236+
237+
}
238+
7239
}

src/Tags/Css.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace HTTPFriend\Tags;
4+
5+
class Css {
6+
7+
}

src/Tags/Js.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace HTTPFriend\Tags;
4+
5+
class Js {
6+
7+
}

src/Tags/Link.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
namespace HTTPFriend\Tags;
44

5-
class Link {
5+
class Link extends Tag {
6+
7+
public function __construct( ){
8+
parent::__construct();
9+
}
610

711
}

src/Tags/Meta.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
namespace HTTPFriend\Tags;
44

5-
class Meta {
6-
5+
class Meta extends Tag {
6+
7+
public function __construct(){
8+
parent::__construct( );
9+
}
10+
711
}

src/Tags/Tag.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,26 @@ public function cleanURLs( $html, $urlreplace = null )
4242
return $html;
4343
}
4444

45+
public function createElement( $tag, $attr = [], $selfClosing = false, $close = false )
46+
{
47+
$element = "<" . (( $close ) ? "/" : "" );
48+
$element .= "$tag";
49+
if( !empty( $attr ) ){
50+
foreach( $attr as $ak => $av ){
51+
$element .= " {$ak}=\"{$av}\" ";
52+
}
53+
}
54+
55+
$element = (( $selfClosing ) ? "/" : "" ) . ">";
56+
57+
return $element;
58+
}
59+
60+
public function output( $options = [] )
61+
{
62+
ob_start();
63+
echo $this->createElement( $options["tag"], $options["attr"], $options['selfClosing'], $options["close"] );
64+
echo ob_get_clean();
65+
}
66+
4567
}

test/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
require "../vendor/autoload.php";
77

8-
$HTTP = new HTTPHelper\HTTPHelper();
8+
$HTTP = new HTTPFriend\HTTPHelper();
99

1010

1111
$HTTP->setConfigParameter( "baseURL", "/_tom/httphelper/test/" );

test/php-error.log

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
[17-Jan-2019 11:51:48 Europe/London] PHP Warning: Invalid argument supplied for foreach() in /websites/active/_tom/httphelper/src/Tags/Tag.php on line 33
2-
[17-Jan-2019 11:51:52 Europe/London] PHP Warning: Invalid argument supplied for foreach() in /websites/active/_tom/httphelper/src/Tags/Tag.php on line 33
3-
[17-Jan-2019 11:53:44 Europe/London] PHP Fatal error: Class 'HTTP\HTTPHelper' not found in /websites/active/_tom/httphelper/test/index.php on line 8

0 commit comments

Comments
 (0)