Skip to content

Instantly share code, notes, and snippets.

View kobus1998's full-sized avatar
😳
-10x programmer

Kobus kobus1998

😳
-10x programmer
View GitHub Profile
@kobus1998
kobus1998 / view-model-example.php
Created June 30, 2020 12:01
view model example
<?php
class ViewModel
{
public $title;
public $lang;
public $translations = [];
@kobus1998
kobus1998 / simple-template.php
Created June 2, 2020 12:22
super simple php/html template
<?php
function html($name, $attr = [], $value)
{
$s = "<{$name} ";
if (!empty($attr)) {
foreach ($attr as $key => $val) {
$s .= "{$key}=\"{$val}\" ";
}
@kobus1998
kobus1998 / Routing.php
Created May 27, 2020 14:22
aura router integrated with psr container
<?php
class Routing extends \Aura\Router\RouterContainer
{
protected $container;
public function __construct($container)
{
parent::__construct();
@kobus1998
kobus1998 / T.php
Created April 22, 2020 12:05
type casting class
<?php
class T
{
public static function __callStatic($name, $arguments)
{
if (isset($arguments[0])) {
if ($name == 'int') {
return (int) $arguments[0];
} elseif ($name == 'string') {
@kobus1998
kobus1998 / bootstrap.php
Created April 22, 2020 10:11
pseudo code for application flow idea
<?php
require './container.php';
require './event-handler.php';
$app = new Application();
$router = new Router($app);
$app->eventHandler->dispatch(Events::START);
@kobus1998
kobus1998 / ManyCalls.php
Last active April 9, 2020 12:20
execute any function by this
<?php
class ManyFunctions
{
/**
* @param string $sMethod
* @param array $aParams
* @return mixed|void
*/
public function __call($sMethod, $aParams = [])
@kobus1998
kobus1998 / period.php
Created February 17, 2020 11:36
check periods crosses another period
<?php
class Period extends \DatePeriod
{
public function crosses(\DatePeriod $period)
{
return $this->numbers_cross(
strtotime($this->getStartDate()->format('Y-m-d')),
strtotime($this->getEndDate()->format('Y-m-d')),
strtotime($period->getStartDate()->format('Y-m-d')),
@kobus1998
kobus1998 / ReflectionCache.php
Created February 12, 2020 15:10
reflectionclass cache
<?php
class ReflectionCache
{
protected $instance;
protected static $instances = [];
public function __construct($className)
{
@kobus1998
kobus1998 / Scalar.php
Created January 6, 2020 14:17
object scalar string
<?php
class Str
{
private $str;
public function __construct(string $str)
{
$this->str = $str;
}
@kobus1998
kobus1998 / checkout.php
Created December 11, 2019 15:39
abstraction shopping cart checkout
<?php
class Product
{
protected $id;
protected $name;
public function __construct($id, $name)
{
$this->id = $id;