Skip to content

Instantly share code, notes, and snippets.

🐮
Milking...

Kobus kobus1998

🐮
Milking...
Block or report user

Report or block kobus1998

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@kobus1998
kobus1998 / Scalar.php
Created Jan 6, 2020
object scalar string
View Scalar.php
<?php
class Str
{
private $str;
public function __construct(string $str)
{
$this->str = $str;
}
@kobus1998
kobus1998 / checkout.php
Created Dec 11, 2019
abstraction shopping cart checkout
View checkout.php
<?php
class Product
{
protected $id;
protected $name;
public function __construct($id, $name)
{
$this->id = $id;
View simple-service-provider.php
<?php
interface PluginServiceProvider
{
public function register(Plugin $plugin): void;
}
class Plugin
{
protected $methods = [];
View Entity.php
<?php
abstract class Entity
{
abstract public function config(): array;
public function validate()
{
$config = $this->config();
$errors = [];
@kobus1998
kobus1998 / index.php
Created Nov 11, 2019
function in parameter with already set parameters
View index.php
<?php
$i = 1;
function plus1(int $i) {
return $i + 1;
}
$f = function () use ($i) {
echo plus1($i);
@kobus1998
kobus1998 / ComplexPeriod.php
Created Oct 24, 2019
added functionality to period
View ComplexPeriod.php
<?php
class ComplexPeriod extends DatePeriod
{
public function __construct($start, $end)
{
parent::__construct(
new \DateTime(date("Y-m-d", strtotime($start))),
new \DateInterval('P1D'),
new \DateTime(date("Y-m-d", strtotime($end)))
@kobus1998
kobus1998 / parseCsv.php
Created Oct 23, 2019
simple no abstraction csv parser
View parseCsv.php
<?php
function parseCsv($csv, $delimiter = ',')
{
// parse rows
$rows = explode("\n", trim($csv));
// parse header and header columns
$header = explode($delimiter, trim(reset($rows)));
@kobus1998
kobus1998 / slugify.php
Created Oct 22, 2019
slugify for url, id, var etc
View slugify.php
<?php
function slugify($sVal, $sDelimiter = '-')
{
$sVal = preg_replace("/[^a-zA-Z0-9_-]/", $sDelimiter, $sVal);
$sVal = preg_replace("/$sDelimiter{2,}/", $sDelimiter, $sVal);
return trim($sVal, $sDelimiter);
}
View simpleCalendar.php
<?php
// start date current month
$day = 01;
$month = date('m');
$year = date('Y');
$today = date('d-m-Y');
$period = new DatePeriod(
View index.php
<?php
class Match
{
public function __construct($pattern, $data, $match)
{
$this->pattern = $pattern;
$this->data = $data;
$this->match = $match;
}
You can’t perform that action at this time.