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 / index.php
Created September 16, 2019 09:25
Manage user timezones
<?php
$timezones = [];
foreach(DateTimeZone::listIdentifiers() as $timezone)
{
$timezoneWithContinent = explode('/', $timezone);
if (count($timezoneWithContinent) == 1) {
// skip UTC
continue;
@kobus1998
kobus1998 / index.php
Created September 10, 2019 09:28
Simple Command bus
<?php
interface Command
{
public function handle();
}
class CommandBus
{
protected $events;
@kobus1998
kobus1998 / index.php
Last active November 11, 2019 12:45
automatic api error response
<?php
// placeholder
class Response
{
}
class ApiError extends \Exception
{
protected static $errorCodes = [
@kobus1998
kobus1998 / PaymentCheckout.php
Created September 5, 2019 13:26
flow pattern
<?php
interface Flow
{
public function execute();
}
class PaymentCheckout implements Flow
{
public function __construct($manadtoryParameters)
@kobus1998
kobus1998 / Pool.php
Created August 13, 2019 13:03
simple pool trait
<?php
trait Pool
{
/** @var array **/
protected static $aPool = [];
public static function addToPool($key, $val)
{
self::$aPool[$key] = $val;
@kobus1998
kobus1998 / translation.php
Created August 13, 2019 10:05
php translator
<?php
class TranslationMissing extends \Exception
{
public function __construct($lang, $trans)
{
parent::__construct("translation missing of $trans in language $lang");
}
}
@kobus1998
kobus1998 / strategy.php
Created August 13, 2019 09:32
Strategy pattern
<?php
interface ApiOutputStrategy
{
public function handle(): string;
}
class JsonOutput implements ApiOutputStrategy
{
public function __construct($data)
<?php
class clonable
{
public function __construct(...$args)
{
$this->args = func_get_args();
}
public function __clone()
@kobus1998
kobus1998 / index.php
Created July 29, 2019 12:48
simple service api
<?php
interface ServiceProvider
{
public function register($container);
}
class UserServiceProvider implements ServiceProvider
{
public function register($container)
@kobus1998
kobus1998 / index.php
Last active June 5, 2019 13:23
php dictonary
<?php
trait Dictionary
{
public function __call($method, $args = [])
{
if (empty($args)) {
return $this->{$method};
}