Skip to content

Instantly share code, notes, and snippets.

@n1215
n1215 / 01_routing.php
Last active August 23, 2019 14:22
Event based notifications library idea
<?php
$container = new SomePSR11Container();
// $container->regiseter();
$notifications = new N1215\Notification\Registrar($container);
$notifications
->source(N1215\Events\UserRegistered::class)
->to(N1215\Notification\UserTargetSelector::class)
->inSingleFormOf(
@n1215
n1215 / 01_usage.php
Last active May 9, 2019 12:07
LaraSeedGraph_idea
<?php
use FlowFactory as Flow;
use SourceFactory as Source;
use SinkFactory as Sink;
$builder = new GraphBuilder();
/** @var GraphInterface $seedGraph */
$seedGraph = $builder
@n1215
n1215 / StringBladeRenderer.php
Last active December 5, 2022 09:16
Compile string by Blade template engine.
<?php
declare(strict_types=1);
namespace App\View;
use Illuminate\View\Compilers\BladeCompiler;
use Illuminate\View\Factory;
use Symfony\Component\Debug\Exception\FatalThrowableError;
/**
@n1215
n1215 / laravel-playground.php
Created February 9, 2019 02:06
simple Laravel play ground
#!/usr/bin/env php
<?php
declare(strict_types=1);
namespace MyPlayGround;
use App\User;
use Illuminate\Support\Facades\Hash;
/**
@n1215
n1215 / float2bin.php
Created November 15, 2018 16:23
float2bin.php
<?php
declare(strict_types=1);
function float2bin(float $float) {
return join('', array_map(function($char) {
return str_pad(decbin(ord($char)), 8, '0', STR_PAD_LEFT);
}, str_split(strrev(pack('d', $float)))));
}
var_dump(float2bin((float)1));
<?php
$query = RelationShipQuery::new(
'select * from `posts` where id = :id',
function (array $record) {
return new Post($record['id'], $record['title'], $record['body'], $record['author'], $record['comments']);
},
[
'author' => PostBelongsToAuthor::hydratedBy(
function (array $record) {
@n1215
n1215 / psr15_framework_memo.php
Last active December 1, 2017 02:06
minimal PSR-15 framework
<?php
// コンテナ生成とキャッシュ
class ContainerBuilder implements ContainerBuilderInterface {
private $providers;
public function __construct(array $providers) {
$this->prividers = $providers;
}
@n1215
n1215 / psr7_15-router.php
Last active December 2, 2017 06:50
PSR-7 / psr-15 ルータ
<?php
interface RouterInterface {
public function match(): RoutingResultInterface;
}
interface RoutingResultInterface {
public function getHandler(): ?RouteInterface;
public function getParams(): array;
public function isSuccess(): bool;
<?php
interface RequestMatcherInterface
{
match(RequestInterface $request) : RequestMatchResultInterface
}
interface RequestMatchResultInterface
{
public function getRequest(): ServerRequestInterface;
public function getMatcher(): RequestMatcherInterface;
@n1215
n1215 / Concrete5ValetDriver.php
Created May 16, 2016 10:48
Laravel Valet custom driver for concrete5.
<?php
class Concrete5ValetDriver extends ValetDriver
{
/**
* Determine if the driver serves the request.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri