Skip to content

Instantly share code, notes, and snippets.

View muhamed-didovic's full-sized avatar
😎

Muhamed muhamed-didovic

😎
View GitHub Profile
<?php
$dispatcher = new EventDispatcher;
class SendWelcomeEmail implements QueuedEventHandler {
public function when(Event $event) {
// delegate to whenUserHasRegistered, whenFoo..
}
private function whenUserHasRegistered(UserHasRegistered $event) {
<?php
require_once __DIR__ . 'path/to/src/Verraes/Lambdalicious/load.php';
assert(
isatom(@my_atom)
);
atom(@my_atom);
assert(
isatom(my_atom)
<?php
/**
* Filtering a array by its keys using a callback.
*
* @param $array array The array to filter
* @param $callback Callback The filter callback, that will get the key as first argument.
*
* @return array The remaining key => value combinations from $array.
*/
<?php
/**
* Will handle downloads for $_REQUEST['file']
* @author Julius Beckmann
*/
function handleForcedDownloads($parameterName='file', $exit=true)
{
if(isset($_REQUEST[$parameterName])) {
<?php
/**
* Creating MongoDB like ObjectIDs.
* Using current timestamp, hostname, processId and a incremting id.
*
* @author Julius Beckmann
*/
function createMongoDbLikeId($timestamp, $hostname, $processId, $id)
{
<?php
final class Basket implements RecordsEvents
{
private $basketCanOnlyContainFiveProducts;
private function __construct()
{
$this->basketCanOnlyContainFiveProducts = new BasketCanOnlyContainFiveProducts();
}
<?php
$addOne = partial(operator('+'), 1);
$double = partial(operator('*'), 2);
$greaterThan3 = partial(operator('>'), …(), 3);
assert(
map([1, 2, 3], $double)->§
== [2, 4, 6]
);
@muhamed-didovic
muhamed-didovic / Role.php
Last active August 29, 2015 14:11 — forked from texdc/Role.php
<?php
namespace My\Role;
use RoleId as BaseId;
class RoleId extends BaseId
{
const ADMIN = 'Admin';
const GUEST = 'Guest';
<?php
namespace Category\Command;
use Category\CategoryId;
use Message\AbstractMessage;
use Message\Message;
use Message\MessageId;
use Message\MessageTrait;
use Product\Command\ProductsCommandTrait;
<?php
/**
* Custom error handler
*
* @see http://www.php.net/manual/en/class.errorexception.php#95415
*/
set_error_handler(function ($number, $string, $file, $line) {
// Determine if this error is enabled (php.ini, .htaccess, etc)
if (!(error_reporting() & $number)) {