Skip to content

Instantly share code, notes, and snippets.

@k-holy
k-holy / SplFileInfoTest.php
Last active August 29, 2015 14:05
Windowsで末尾に5Cを含むファイルの扱いを検証
<?php
namespace Acme\Test;
class SplFileInfoTest extends \PHPUnit_Framework_TestCase
{
private $isWin;
private $testDir;
public function setUp()
@k-holy
k-holy / factory.php
Last active December 29, 2015 01:49
ReflectionClassを使ったファクトリ
<?php
function factory($class, array $options = array())
{
if (count($options) === 0) {
return new $class();
}
$refClass = new \ReflectionClass($class);
@k-holy
k-holy / .htaccess
Last active February 21, 2021 21:17
Dynamic RewriteBase for Apache (mod_rewrite, mod_setenvif)
RewriteEngine On
#----------------------------------------------------------
# RewriteBase for develop
#----------------------------------------------------------
# SetEnvIf
SetEnvIf Host ^develop.example.com$ REWRITE_BASE=/path/to/develop
# or RewriteCond
#RewriteCond %{HTTP_HOST} ^develop.example.com$
@k-holy
k-holy / 日本語でTrait練習.php
Last active December 16, 2015 10:09
日本語でTrait練習
<?php
namespace 俺の;
trait プロパティ実行
{
public function __call($name, $args)
{
if (isset($this->{$name}) && is_callable($this->{$name})) {
return call_user_func_array($this->{$name}, $args);
}
@k-holy
k-holy / imagetypes.php
Created January 30, 2013 05:51
IMAGETYPE定数と拡張子とmimeTypeの一覧(遅延評価版)
<?php
namespace Acme;
class ImageType
{
private $name;
private $value;
private $supportedImageTypes;
public function __construct($name, $supportedImageTypes = null)
@k-holy
k-holy / conditional-get-silex.php
Last active December 10, 2015 00:29
Symfony-HttpFoundationで条件付きGET
<?php
namespace Acme;
/*
* 【Symfony-HttpFoundationで条件付きGET】
*
* @copyright 2012 k-holy <[email protected]>
* @license The MIT License (MIT)
*/
$loader = include __DIR__ . '/../../../vendor/autoload.php';
@k-holy
k-holy / SmartyFunctionRegistry.php
Created December 8, 2012 23:05
SmartyFunctionRegistry
<?php
namespace Holy;
/**
* Registry for Smarty plugin/filter functions
*
* @author [email protected]
*/
class SmartyFunctionRegistry
{
@k-holy
k-holy / composer.json
Created December 4, 2012 08:44
Silex + Volcanus_Csv + PDO_SQLITE で KEN_ALL.CSV の中身を調査
{
"require": {
"silex/silex": "1.0.*",
"volcanus/csv": "dev-master"
},
"minimum-stability": "dev"
}
@k-holy
k-holy / pdo.php
Created December 3, 2012 09:22
Volcanus\Csv\Reader
<?php
$app = new Application();
$app['pdo'] = $app->share(function(Application $app) {
$db = new \PDO(sprintf('sqlite:%s', __DIR__ . '/../test.sqlite'));
$db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
return $db;
});
@k-holy
k-holy / index.php
Created November 28, 2012 01:47
Volcanus\Csv\Writerの利用サンプル(Silex + DoctrineDBAL + StreamedResponse版)
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use Silex\Application;
use Silex\Provider\DoctrineServiceProvider;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\StreamedResponse;