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 / Entity.php
Created June 4, 2019 07:51
Simple Entity class
<?php
class Entity
{
protected $touched = false;
public function __construct($aData)
{
foreach($aData as $key => $val) {
$this->{$key} = $val;
@kobus1998
kobus1998 / index.php
Created May 23, 2019 14:51
simple queue design
<?php
class QueueList
{
public function __construct()
{
$this->data = [];
}
public function isEmpty()
@kobus1998
kobus1998 / index.php
Created May 22, 2019 12:10
Parse function doc block
<?php
$s = '
/**
* Send request
*
* @throws \Exception
* @param string $sEvent
* @param \com\realexpayments\remote\sdk\domain\iRequest $oRequest
* @param boolean $bReturnResponse
@kobus1998
kobus1998 / code-gen.php
Last active January 5, 2021 15:45
code generation
<?php
$namespace = "App";
$classname = "Kernel";
$extends = "\\Symfony\\Kernel";
$implements = [
"\\App\\Contract\\KernelContract"
];
$properties = [
[
@kobus1998
kobus1998 / index.php
Created May 14, 2019 10:07
Router design
<?php
$router->add('GET', '/user/:userId', /* All callable */, $middleware1, $middleware2, $controller);
try {
$router->execute($request);
} catch (\HttpError\Code500 $e) {
$e->viewMessage();
} catch (\HttpError\Code403 $e) {
$e->viewMessage();
@kobus1998
kobus1998 / file.php
Created May 8, 2019 14:38
Autowire container with league\container
<?php
require __DIR__ . '/vendor/autoload.php';
use \App\Foo;
use \App\Bar;
use \League\Container\Container;
class CachedReflection
{
@kobus1998
kobus1998 / file.php
Created May 8, 2019 14:38
Autowire container with league\container
<?php
require __DIR__ . '/vendor/autoload.php';
use \App\Foo;
use \App\Bar;
use \League\Container\Container;
class CachedReflection
{
@kobus1998
kobus1998 / router.php
Created April 29, 2019 15:02
Routing design
<?php
$router = new Router();
$router->addService('twig', $twig);
$router->addService('logger', function ($msg) {
echo $msg;
});
$router->addRoute('GET', '/users', [Controller::class, 'getUsers']);
@kobus1998
kobus1998 / script.php
Last active April 29, 2019 09:24
Detect csv delimiter
<?php
class UnsupportedDelimiter extends \Exception
{
}
class Csv
{
public function __construct(string $csv)
{
@kobus1998
kobus1998 / Enum.php
Created April 16, 2019 10:53
Enum in php
<?php
abstract class Enum
{
/**
* @var array
*/
private static $constCacheArray = null;
/**