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 / FormParams.php
Created April 4, 2019 08:25
Form parameters abstraction
<?php
/**
* ```php
* echo (new FormParams())->set('name', 'x')->set('secondName', 'y'); // name=x&secondName=y
* ```
*/
class FormParams
{
protected $params = [];
@kobus1998
kobus1998 / index.php
Created March 20, 2019 10:19
pattern edit class inside class
<?php
class First
{
private $second;
public function __construct($second)
{
$this->second = $second;
}
@kobus1998
kobus1998 / router.php
Last active November 26, 2020 14:03
Very simple router
<?php
/**
* Route
*
* @param string $method
* @param string $path
* @param callable|array $callback
* @return void
*/
@kobus1998
kobus1998 / script.php
Last active February 27, 2019 13:51
generate html
<?php
function arrayToAttrs($attrs)
{
if (!is_array($attrs)) {
return '';
}
$result = '';
@kobus1998
kobus1998 / script.php
Created February 27, 2019 08:35
Parse docblocks
<?php
$s = '
/**
* Does something
* Some description
*
* @param string $type
* @return string
*/
@kobus1998
kobus1998 / GetAndSet.php
Created February 26, 2019 09:42
Get and set anything
<?php
trait GetAndSet
{
/**
* Magic method __call
*
* @param string $method
* @param array $params
* @return mixed
@kobus1998
kobus1998 / Url.php
Created February 25, 2019 16:00
parse_url abstraction
<?php
namespace Http;
class Url
{
public $scheme;
public $host;
@kobus1998
kobus1998 / CustomFunctionality.php
Created February 25, 2019 11:59
Trait that catches custom methods that are not in the class
<?php
trait CustomFunctionality
{
protected $functions = [];
public function addMethod(string $name, callable $function)
{
$this->functions[$name] = $function;
return $this;
@kobus1998
kobus1998 / NonStaticTest.php
Created January 28, 2019 16:07
Performance test static vs non-static methods
<?php
class NonStaticTest
{
public function execute()
{
array_fill(0, 100, 'a');
}
}
@kobus1998
kobus1998 / index.php
Created January 17, 2019 12:07
Implode assoc
<?php
/**
* @param string|array
* @param string|array
* @param string
*/
function implodeAssoc($glue, $arr, $key = null)
{
if (is_array($l)) {