Skip to content

sircode/microfyPHP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

41 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

microfyPHP

Minimal utility helpers for everyday PHP tasks (object-oriented version)

Status: EXPERIMENTAL


🧰 What is it?

MicrofyClass.php is the object-oriented version of microfyPHP-Lite β€” a minimalist utility class packed with static helper methods to simplify everyday PHP development.

It brings the same no-bloat, no-dependency philosophy β€” now in a class-based format β€” offering tools for request handling, debugging, logging, HTML snippets, database access, and more.

Forget frameworks when all you need is power and speed β€” Microfy is your coding pocketknife.


πŸ’‘ Why use it?

  • You're tired of repetitive boilerplate like isset($_GET['x']) ? $_GET['x'] : ''
  • You want clean, expressive, and testable PHP code
  • You work in an OOP environment but don’t want bulky libraries
  • You need practical helpers like Microfy::getVar(), Microfy::pp(), Microfy::dbAll() right away
  • You value full control with zero magic

✨ Features

  • Request Access: getVar(), postVar(), requestVar() and prefixed variants
  • Debug Tools: pp(), pd(), mpp(), mlog(), with optional returns (pdd(), pdr())
  • Database: PDO helpers like dbPdo(), dbAll(), dbExists(), etc.
  • HTML Snippets: h(), br(), codePhp(), mark(), a(), b(), ul(), li() and more
  • Array Utils: getArray() (formerly getR()) for safe key lookups
  • Slugify: Easily generate SEO-safe slugs
  • JSON Reader: jsonf() for simple flat-file configs
  • List Helpers: cList(), cStr() for smart numbered headings and counters

🧱 HTML Builder Functions (v0.1.04+)

Use these to generate clean, semantic HTML in PHP β€” all methods return strings.

πŸ“¦ Core & Generic

  • tag(): Low-level generic tag builder
  • html_tag(): Alias to tag() for semantic grouping
  • pretty_html(): Formats raw HTML for human-friendly display

πŸ“„ Document Structure

  • html_html(), html_head(), html_body()
  • html_header(), html_footer(), html_section(), html_article(), html_nav(), html_aside()

πŸ“š Content Blocks

  • html_div(), html_span(), html_p(), html_blockquote(), html_pre(), html_code()
  • html_h1() β†’ html_h6()

πŸ“‘ Lists

  • html_ul(), html_ol(), html_li()
  • html_dl(): Takes an array of ['term' => ..., 'desc' => ...]

πŸ“Š Tables

  • html_table(), html_thead(), html_tbody()
  • html_tr(), html_th(), html_td()

πŸ“ Forms

  • html_form(), html_label(), html_input(), html_textarea(), html_select(), html_button()

🧩 Self-closing & Inline

  • html_br(), html_hr(), html_img(), html_meta(), html_link()

πŸ”§ Embeds & Styles

  • html_script(), html_style()

πŸ” Echoing Helpers (e_ aliases)

If you'd rather use functions like e_p(), e_div(), or e_html_ul() instead of writing echo Microfy::p(...), you can include the optional alias file:

require_once 'microfy_echo_aliases.php';

This file defines convenient e_ versions of all output-generating methods in Microfy. For example:

e_p("Hello"); // same as echo Microfy::p("Hello");
e_html_ul(["One", "Two"]); // same as echo Microfy::html_ul([...]);

These aliases are safe, optional, and designed for quick prototyping or simplified views.

Only methods that return markup or formatted output get e_ aliases β€” utilities like slugify() or now() are excluded.


πŸ“Œ When to Use MicrofyClass.php

Use MicrofyClass.php when:

  • You prefer structured, class-based projects but want minimal dependencies
  • You’re building tools, scripts, or APIs and don’t need full frameworks
  • You want to keep code readable, consistent, and DRY β€” especially in shared teams
  • You want the best of both worlds: OOP and shortcut-style aliases

πŸ›  Bonus: Procedural Aliases

Want the simplicity of pp($data) or dbAll(...) in your OOP project?

Just include microfy_aliases.php to use short, procedural-style aliases for all Microfy:: methods β€” no need to prefix everything manually.

require_once 'MicrofyClass.php';
require_once 'microfy_aliases.php'; // optional

pp(['quick', 'debug']); // works alongside Microfy::pp(...)

πŸš€ Usage Examples

require_once 'MicrofyClass.php';

πŸ” Access & Debug

Microfy::pp($_GET);
$name  = Microfy::getVar('name', 'Guest');
$email = Microfy::getArray(['email' => '[email protected]'], 'email', 'none');

🎯 Extract Prefixed GET Vars

extract(Microfy::getVarsPrefixed(['path', 'id']));

// Example: $_GET = ['path' => 'demo', 'id' => '42'];
// Results: $get_path = 'demo'; $get_id = '42';

πŸ—ƒοΈ Database Access

$pdo  = Microfy::dbPdo('localhost', 'mydb', 'user', 'pass');
$rows = Microfy::dbAll($pdo, "SELECT * FROM users");
Microfy::pp($rows);

πŸ•’ Utilities & Output

echo Microfy::now();
$data = Microfy::jsonf('users.json');
echo Microfy::a('example.com', 'Example');
echo Microfy::htmlTable($data);
echo Microfy::htmlTable($data, $class, $id);
Microfy::cList(['apple', 'banana', 'cherry']);

βš™οΈ Config & System

Microfy::def('APP_NAME', 'microfy');
Microfy::load('config');

πŸ–ΌοΈ HTML Helpers

Microfy::h(2, 'Welcome');
echo Microfy::b('Bold text');
echo Microfy::slugify('This is a title!');
Microfy::ok(); // JSON response

πŸ“ UI Components

Microfy::p('Paragraph text', 'highlight');
Microfy::codephp('<?php echo "Hello"; ?>');
Microfy::ul(['Item 1', 'Item 2']);
Microfy::br();
Microfy::c('Step A');

πŸ“˜ More Examples


🀝 Contributing

We welcome contributions! See CONTRIBUTING.md for details.


πŸ”’ License

MIT License β€” Β© 2024–2025 SirCode | This project is not affiliated with or endorsed by the PHP Foundation. Use at your own risk β€” no warranties, no guarantees, just useful code.


πŸ“¦ Also Available as Procedural Version

Prefer short global functions like pp(), getVar(), or dbAll()? πŸ‘‰ microfyPHP-Lite offers the same features β€” no classes required.


About

**Minimal utility helpers for everyday PHP tasks** (object-oriented version)

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages