Skip to content

Instantly share code, notes, and snippets.

@n1215
n1215 / BCThemeSwitchByUA.php
Last active August 29, 2015 14:07
【baserCMS】 ユーザーエージェントに応じて適用するテーマを変えるテスト
<?php
/**
* app/Controller/AppController.php
*/
App::uses('BcAppController', 'Controller');
App::uses('BcAgent', 'Lib');
class AppController extends BcAppController {
/**
@n1215
n1215 / BaserCMS.php
Last active August 29, 2015 14:16
【baserCMS 】サイトとbaserCMSの設定に責任を持つクラスの導入イメージ
<?php
class BaserCMS {
protected $settings;
protected $_server;
protected $_env;
/**
* ファクトリ用のstaticメソッドを定義
* ConfigureやDB・環境変数等、外部への関与はここに集約
*/
@n1215
n1215 / Compose.php
Last active August 29, 2015 14:19
PHPでFizzBuzz 関数合成風味
<?php
namespace Compose;
/**
* 関数を合成
* pipe(f, g, h) なら h(g(f))
*
* @return callable
*/
function pipe()
@n1215
n1215 / AppView.php
Created April 20, 2015 10:30
baserCMS 親テーマもどき
<?php
App::uses('BcAppView', 'View');
class AppView extends BcAppView {
protected $baseTheme = 'hoge';
protected function _paths($plugin = null, $cached = true) {
//プラグインの場合はそのまま
if ($plugin != null)
@n1215
n1215 / BcCommonViewVariables.php
Last active February 8, 2016 01:06
baserCMS 共通のビュー変数を利用する設定
<?php
/**
* {テーマのディレクトリ}/Config/bootstrap.phpとして配置する
* テーマ内で <?php echo $siteTitle ?> などと通常のビュー変数同様に利用可能
*/
/**
* 今回のビュー変数に限らず、テーマ用の設定はまとめておくとすっきりする
*/
$config['MyTheme'] = array(
trait RequiresServerRequestTrait
{
/**
* @param RequestInterface $request
* @return ServerRequestInterface
* @throws ServerRequestRequiredException
*/
private function ensureServerRequest(RequestInterface $request)
{
if (($request instanceof ServerRequestInterface) === false) {
@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
<?php
interface RequestMatcherInterface
{
match(RequestInterface $request) : RequestMatchResultInterface
}
interface RequestMatchResultInterface
{
public function getRequest(): ServerRequestInterface;
public function getMatcher(): RequestMatcherInterface;
@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;
@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;
}