OptimizedHtml PHPLibrary
Design for backend optimizedHTML PHPWine written in PHP (Hypertext Preprocessor)
About: Formerly known as PHPWine Vanilla flavour which end life beta version 1.4.0 was announce September 3, 2023 11PM PH. Officially released the PHPWine OptimizedHtml v1.3.0 which have a structured and methods, not just html but also fully optimized and organized inspired with the beauty of Laravel building app approach "similar" to MVC with three major class for more details will discuss with you soon! the Doctrines Class for templates, App Class for main application last but not the least is Components Classes.
When?: You can use PHPWine OptimizedHtml with any PHP Framework such Laravel, CodeIgniter, Symfony also compatible with any CMS such WordPress, Drupal etc... or even non-framework php web application.
Installation:
/* required version *v1.4.0 */
composer require phpwine/optimizedhtml v1.4.0
/* Installing Doctrine local available soon! */
composer require phpwine/doctrine v1.0
/* Installing Doctrine local tailwindcss available soon! */
composer require phpwine/doctrine-tailwindcss v1.0
/* Installing Doctrine local bootstrapt available soon! */
composer require phpwine/doctrine-boostrapt v1.0
Usage:
/* Basic Usage */
require dirname(__FILE__) . DIRECTORY_SEPARATOR .'/vendor/autoload.php';
$tag = new PHPWineOptimizedHtml\OptimizedHtml;
print $tag->wine(h1,'Hello World');
Congratulations you are now in PHPWine overview!
PHPWine Class Structure insights
/* Structure Optimizing HTML */
| - Doctrine
|- Class HomePageDoctrine { ... }
| - App
|- Class HeaderApp { ... }
| - Components
|- Class Branding { ... }
|- Class MainMenu { ... }
Doctrine Class php file
Set your namespace and follow by Class keyword then you Doctrine class named
/* Here is the example of Doctrine Class file .php */
| - Doctrine
namespace \YourLoader\folder;
Class HomePageDoctrine {
...
}
Application Class php file
/* Here is the example of App Class file .php */
| - App (Main application)
namespace \YourLoader\folder;
use \YourLoader\folder\HomePageDoctrine;
Class HeaderApp Extends HomePageDoctrine {
...
}
Component Brading Class php file
/* Here is the example of Components Branding Class file .php */
| - App (Main application)
namespace \YourLoader\folder;
use \YourLoader\folder\HeaderApp;
Class Branding Extends HeaderApp {
...
}
Component MainMenu Class php file
/* Here is the example of Components Main menu Class file .php */
| - App (Main application)
namespace \YourLoader\folder;
use \YourLoader\folder\HeaderApp;
Class MainMenu Extends HeaderApp {
...
}
Quick Start
/* Quick Start file .php */
| - Quick Start
Download for wine v1.3.2 to v1.3.4 higher
/* init doctrine class */
< html lang="en">
< body>
...
< ?php
/**
* --------------------------------------------------------------------------------------------
* @class
* @hide_those
* @source: project/Components\HomePageThose.php
* --------------------------------------------------------------------------------------------
* DT: 11.17.2023 **/
$those_boxes = new \PHPWineShowcase\Components\HomePageThose;
wine_doctrine_init(); ?>
< /body>
< /html>
< ?php
/* Instead of using doctrine selecting 1 by 1 you can use those
property and select the class and those */
namespace PHPWineShowcase\Components;
use \PHPWineOptimizedHtml\Doctrine\Doctrine;
class HomePageThose {
public function __construct()
{
// Hide in mobile
$page_box = new Doctrine([
those => '.hide-m'
]);
print $page_box->visible([
'sm_mobile' => false
])->screen([
'sm_mobile' => 540
])->layout();
... // add more
}
}
PHPWine Methods
PHPWine OptimizedHtml has predefined methods, these methods are helpful for developer to minimize and lessen the workload, and it makes the structure simpler and effective.
wine function|method : Use to generate optimized html. - wine(); is primary init function in order to have optimized html it is also use in order to create a condition before using "please" reserve keyword, The "try" or "please" is more secured when you wrap them in wine before you use.
- Inside the wine(); you can also create a child using predefined array child and it's keyword "child" with this key you can create a descendant element like div or any within the providers property inside the wine class, more than that you can do custom HTML tag just using wine.
- In order to use a value, attr and magic hooks you have to call the wine function.
NOTE: Keep in mind : wine second parameter or content value is accept single single type of data! - wine(div,""); If you are working with array you always working with child array if you are working with string you must be stick on string type value. - wine(div,""); might accept different type of data however when you create child you must be stick on single type of data inside "please" or "try" it only rendered single type of data due to optimization, imagine you running holding cake or pizza?
wine(); | Type: function|method
Defined: wine function or method is use to generate optimized html
wine(
string $tag,
string|callable|array $content = [],
string|array $attr = [],
$enable_html = false
);
@param string $tag : < require >
- This is where you will assigned any html tag such as 'h1', 'div', 'p' etc..
@param string|callable|array $content : < optional >
- String : Any string value you want to display in a browser from a-Z and 0-inifinite
inlcuding special characters as long as in a form of string.
- Callable : It is in a form of string but actually name of your method or function
ex. "my_call_back".
- Array : It is predefined and reserved keyword "child key" it will able you to
create a child element html.
@param string|array $attr : < optional >
- String: Directly use string to be your html attributes.
- Array : Array approach to be your html attributes.
@param $enable_html : < optional >
- Boolean : optional true or false default value is false.
wine with HTML tag < require >
/* wine with div tag HTML */
print wine('div');
wine with HTML Tag and value "String" < optional >
/* wine with div tag HTML value string */
print wine('div','Hello World');
wine with HTML Tag and value "String call back" function < optional >
/* wine with div tag HTML value string call back */
print wine('div','my_call_back_function');
function my_call_back_function() {
return "Hello World";
}
wine with HTML Tag and value "Array" child element < optional >
/* wine with div tag HTML value Array child element */
print wine('div',[
child => [
['div', value =>['Hello World']]
]
]);
wine with HTML Tag and attribute String < optional >
/* wine with div tag HTML Attributes string */
print wine('div','Hello World','class="my-class" id="my_ids"'); /* make sure remove extrass spacing it reflect to html */
wine with HTML Tag and attribute Array < optional >
/* wine with div tag HTML Attributes array */
print wine('div','Hello World',[classes=>"one my-class" id=>"my_id"]); /*automatic removed extra spacing*/
wine enable html < optional >
/* wine with div tag HTML enable html optional */
print wine('div','Hello World',[classes=>"one my-class" id=>"my_id"], true ); /* default value is false*/
Wine Hooks
PHPWine has predefined Hooks, these hooks are helpful for developer to minimize and lessen the workload, and it makes the structure simpler and effective.
later function|hook : Use to return content for a call back function. - later(); is a string function that provide a callback for magic hook and "value" reserved keyword when you working with the child array there is a reserved keyword "value" and "attr" with these keys you can add attributes in your array custom html and write the "value" you can return a any form of string value to have a content that child array element or you can use the later() hook function to have a return call back that mostly do in procedural pages in you view php files. In addition later() hook is a optional function it doesnt matter if this exists unlike value hook is mandatory call back.
value method|hook : Use to return content for a call back function. - value(); is a string function that provide a callback for "value" reserved keyword when you working with the child array there is a reserved keyword "value" and "attr" with these keys you can add attributes in your array custom html and write the "value" you can return a any form of string value to have a content that child array element or you can use the value() hook function to have a return call back that mostly do in main app files, with that value function you can extract the content you want to return in your child array key html
magic method|hook : Use to filter the current content and replace. - magic(); is exactly the same as value(); aside to the time of execution however the return argument is the current value, The magic hook is use when you want to replace the current value of the html or the full app html, this magic hook method are mostly use in a session, for instance you have a different layout header when the user is login or active session else you have a default navigation once the user is logout. - you can also add magic if your client want to update the layout without touching the current structure so if ever there's a change of mind you don't need to do it over and over again and you can restore back the default immediately because you using magic hook for the temporary of time you are working with the new layout structure.
attr method|hook : Use to add or filter and replace the current attribute of your html. - attr(); is exactly the same as magic(); the same with the time of execution however the return argument is the current attribute, The attr hook is use when you want to replace the current attribute in the html, this attr() hook method are mostly use in a doctrine class php file, for instance you decided to develop or create a doctrine that exact match to your custom layout, with this hook you can use the doctrine as your parent template to have a reusable asset and replace the attributes according to your project next section layout.
later(); | Type: function|hook
Defined: later hook or function is use to create a content to the wine
later(
string|callable $function_name = null,
mixed ...$args
);
@param string|callable| $function_back : < optional&nullable >
- Callable : It is in a form of string but actually name of your method or function
ex. "my_call_back".
@param mixed ...$args : < optional&nullable >
- mixed: arguments data call back
later function/hook basic usage
/* later function|hook */
/* $this if you are within the class */
print wine('div',[
child => [
[div, value=>[later('function_name', 1, 4, 3)]]
]
]);
/* later stand for it doesnt matter if this function is exist or not, or might be later! */
function function_name( $love, $sign, $wine ) {
return "Hello World $love $sign $wine";
}
value(); | Type: method|hook
Defined: value hook or method is use to create a reusable or single callable function
value(
object $class = null,
string|callable $call_back = null,
mixed ...$args
);
@param object $class : < optional&nullable >
- This object is the class of method you are working with the call-back
@param string|callable| $call_back : < optional&nullable >
- Callable : It is in a form of string but actually name of your method or function
ex. "my_call_back".
@param mixed ...$args : < optional&nullable >
- mixed: arguments data call back
value method/hook basic usage
/* value function|method */
/* $this if you are within the class */
print value($this,'my_call_back', 'Developer');
function my_call_back( $param ) {
return "Hello World ".$param;
}
value with in HTML
/* value hook in HTML */
return wine('section', [
child => [
/* $this replace of object name you are working with your call back */
['div', value=>[value((new Branding),'component_top_logo_header')]]
]
]);
magic(); | Type: method|hook
Defined: magic hook or method is use to filter and replace a current value with the callback
magic(
object $class = null,
string|callable $call_back = null,
mixed ...$current_value /* first argument is a function */
);
@param object $class : < optional&nullable >
- This object is the class of method you are working with the call-back
@param string|callable| $call_back : < optional&nullable >
- Callable : It is in a form of string but actually name of your method or function
ex. "my_call_back".
@param mixed ...$current_value : < optional&nullable >
- mixed: arguments data call back
magic method/hook basic usage
/* magic can wait until the exact Date and Time you wish to call or invoke it */
/* $this if you are within the class */
magic($this,'my_call_back', 'Developer');
function my_call_back( $param ) {
return "Hello World ".$param;
}
function Developer( $dev ) {
/* return any... */
}
magic with in HTML
/* working with magic method */
function current_value( $dev, $sign, $of, $love ) {
/* Keep in mind first argument is name of function */
return "I really fall with wine $sign $of $love";
}
/* working with magic method */
/* using value in case of method in magic */
/*
$value = value($object, 'callable_method',$any);
['div', value=>[magic((new object),'method_filter',$value)]]
*/
return wine('section', [
child => [
/* $this replace of object name you are working with your call back */
['div', value=>[magic((new object),'method_filter','current_value', 1, 4, 3)]]
]
]);
attr(); | Type: method|hook
Defined: attr hook or method is use to add or filter and replace the current attribute of your html
attr(
object $class = null,
string|callable $call_back = null,
mixed ...$args
);
@param object $class : < optional&nullable >
- This object is the class of method you are working with the call-back
@param string|callable| $call_back : < optional&nullable >
- Callable : It is in a form of string but actually name of your method or function
ex. "my_call_back".
@param mixed ...$args : < optional&nullable >
- mixed: arguments data call back
attr method/hook basic usage
/* attr hook|method */
/* $this if you are within the class */
public function doctrine_method_name($session) {
return wine('section', [
child => [
['div', attr=> [ attr((new object),'filter_attr',[ /* current attributes */ ]) ]],
]
]);
}
Reserved Keywords
Defined: Reserved keyword is a type of constant that predefined in wine class those keys are uses in each significant purposes.
wine(__, [
Child=> [
/* goes here */
]
]);
/* First Layer */
wine('div', [
child => [
please => function() { ... },
]
]);
/* Second Layer */
wine('div', [
child => [
['try' => function() { ... } ],
]
]);
/* Third layer */
wine('div', [
child => [
[div, value => [ 'try' => function() { ... }] ],
]
]);
attr | Type: constant|ReservedKeyword
Defined: "attr" key use to add attribute in your html inside in php file
attr => [ ]
@key constant attr : < optional&require >
attr constant basic usage
/* attr constant will only available inside the child key predefined array child element */
print wine(div, [
child => [
[div, attr => [ classes=>"my-class" id=>"my_id"] ]
]
]);
child | Type: constant|ReservedKeyword
Defined: "child" key use to add array child element in your html inside in php file
child => [ ]
@key constant child : < optional&require >
child constant basic usage
/* child key predefined array child element */
print wine(div, [
child => [
[div, attr => [ classes=>"my-class" id=>"my_id"] ],
[div,
attr => [
classes=>"my-class"
id=>"my_id"
]]
]
]);
value | Type: constant|ReservedKeyword
Defined: "value" key use to add content to your array child element in your html inside in php file
value => [ ]
@key constant child : < optional&require >
child constant basic usage
/* will accept any string value */
print wine(div, [
child => [
[div, value => ["Hello World"]]
]
]);
__ | Type: constant|ReservedKeyword
Defined: "__" (double underscore) or known as magic entity key use to removed parent element in wine your html inside in php file
wine(__,);
@key constant child : < optional&require >
magic entity constant basic usage
/* will only return child div with content "Hello World" */
print wine(__, [
child => [
[div, value => ["Hello World"]]
]
]);
please | Type: constant|ReservedKeyword
Defined: "please" key use to add conidition or statement in your element in wine your html inside in php file
please => function() { ... }
@key constant please : < optional&require >
please constant basic usage
/* wine() and array child cannot work togther inside the please keyword! */
/* create condition before each child array */
print wine(__, [
child => [
['div', value => [ please => function() {
$dd = [];
$dd[] = wine('h1', 'Hello!' ); /* only wine or child array element works */
/* $dd[] = ['h1', value => ['Hello World'] ]; if you use array child remove wine(); */
foreach([1,2,3] as $data ) {
$dd[] = wine('div', $data);
/* $dd[] = ['div',value => [$data] ,attr => [ classes => 'w-full'] ]; */
} /* end of statement or condition */
return $dd;
} /* end of please */
]]
]]);
"try" | Type: string|ReservedKeyword
Defined: "try" key use to add conidition or statement in your element in wine your html inside in php file
"try" => function() { ... }
@key string "try" : < optional&require >
"try" string basic usage
/* wine() and array child cannot work togther inside the please keyword! */
/* create condition before each child array */
print wine(__, [
child => [
['div', value => [ "try" => function() {
$new = new class () extends \AppNameSpace\ClassName {
public function my_value_in_array() {
return "Coffee";
}
public function my_filter() {
return "No sugar!";
}
};
return [
['div', value => [value($new,'my_value_in_array')]],
['div', value => [magic($new,'my_filter',value($new,'my_value_in_array'))]]
];
}]]
]]);
Entity Attribute
Defined: Entity attribute keyword is a predefined constant that only available inside the wine class, these also available in your php file once you initialized the OptimizedHtml PHPWine library.This is merging the layout like feel in literal HTML, in php file you are not able to add entity attribute just the same as html, because it’s rendered you need to put these inside array then print as string in html, like ex.[ “key” => “val”]; but with these entity constant you can now feel the super natural approach adding entity attributes with these registered constant lists it help to developer to make the wine more effective.
Alt Type: Constant|ReservedKeyword
Defined: Alt Attributealt: Key is mostly use in image HTML it is alternative use once the image cannot load to the browser so the client will be able to determined which image are they see through the alt name, imagine you have a product that have link using images? And your server getting issue then the images cannot load? This “alt” key may help your visitor to figure out which button are they should to click, in addition this alt key are being use in SEO for search engine optimization in all types of browser.
print wine(img,null,[alt=>"name-any"]);
classses Type: Constant|ReservedKeyword
Defined: class Attributeclass is mostly use to add a layout through css you can have multiple classes at the time.
print wine(div,"Hello World",[classes=>"name-any"]);
controls Type: Constant|ReservedKeyword
Defined: class AttributeIf this attribute is present, the browser will offer controls to allow the user to control video playback, including volume, seeking, and pause/resume playback.
for Type: Constant|ReservedKeyword
Defined: for Attributethe for attribute has a value which is the id of the form element it relates to.
href Type: Constant|ReservedKeyword
Defined: href AttributeThe href property of the Location interface is a stringifier that returns a string containing the whole URL, and allows the href to be updated.
height Type: Constant|ReservedKeyword
Defined: height AttributeThe height CSS property specifies the height of an element.
id Type: Constant|ReservedKeyword
Defined: id AttributeThe id property of the Element interface represents the element's identifier, reflecting the id global attribute.
lists Type: Constant|ReservedKeyword
Defined: lists AttributeLists behave like any other text for the most part, but there are some CSS properties specific to lists that you need to know about, as well as some best practices to consider. This article explains all.
max Type: Constant|ReservedKeyword
Defined: max AttributeThe max attribute defines the maximum value that is acceptable and valid for the input containing the attribute.
min Type: Constant|ReservedKeyword
Defined: min AttributeThe min() CSS function lets you set the smallest (most negative) value from a list of comma-separated expressions as the value of a CSS property value.
name Type: Constant|ReservedKeyword
Defined: name Attribute
style Type: Constant|ReservedKeyword
Defined: style AttributeThe read-only style property of the HTMLElement returns the inline style of an element in the form of a live CSSStyleDeclaration object that contains a list of all styles properties for that element with values assigned only for the attributes that are defined in the element's inline style attribute.
script Type: Constant|ReservedKeyword
Defined: script Attribute
src Type: Constant|ReservedKeyword
Defined: src Attribute
type Type: Constant|ReservedKeyword
Defined: type Attribute
target Type: Constant|ReservedKeyword
Defined: target Attribute
val Type: Constant|ReservedKeyword
Defined: val Attribute
with Type: Constant|ReservedKeyword
Defined: with Attribute