Skip to content

Instantly share code, notes, and snippets.

@k-holy
k-holy / zf2.tests.Zend.Validator.HostnameTest.php
Created April 6, 2012 03:15
thisisaverylonghostnamewhichextendstwohundredfiftysixcharactersandthereforshouldnotbeallowedbythisvalidatorbecauserfc3986limitstheallowedcharacterstoalimitoftwohunderedfiftysixcharactersinsumbutifthistestwouldfailthenitshouldreturntruewhichthrowsanexcepti
<?php
/**
* @group ZF-10267
*/
public function testURI()
{
$valuesExpected = array(
array(Hostname::ALLOW_URI, true, array('localhost', 'example.com', '~ex%20ample')),
array(Hostname::ALLOW_URI, false, array('§bad', 'don?t.know', 'thisisaverylonghostnamewhichextendstwohundredfiftysixcharactersandthereforshouldnotbeallowedbythisvalidatorbecauserfc3986limitstheallowedcharacterstoalimitoftwohunderedfiftysixcharactersinsumbutifthistestwouldfailthenitshouldreturntruewhichthrowsanexceptionbytheunittest')),
);
@k-holy
k-holy / FilterableAccessor.php
Created April 6, 2012 08:55
値のセット時に任意のフィルタを行うアクセサクラス
<?php
namespace Acme;
class FilterableAccessor
{
private $attributes;
private $filters;
public function __construct(array $params = array())
{
@k-holy
k-holy / get-mimeType.html
Created May 30, 2012 10:42
RecursiveIteratorIterator+FileInfo関数でディレクトリ内のファイルから再帰的にMIME-Typeを取得
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8" />
</head>
<body>
<ul>
<li>
<dl>
<dt>cab.cab</dt>
@k-holy
k-holy / composer1.json
Created June 8, 2012 10:41
UniversalClassLoader::registerPrefix()
{
"require": {
"symfony/class-loader": "2.1.*"
}
}
<?php
// autoload_namespace.php generated by Composer
$vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);
return array(
'Volcanus\\Validation' => $vendorDir . '/volcanus/validation/src/',
'Symfony\\Component\\HttpFoundation' => $vendorDir . '/symfony/http-foundation/',
@k-holy
k-holy / 1.composer.json
Created June 13, 2012 03:36
名前空間を使わないPSR-0のライブラリをComposerでオートロード
{
"repositories": [
{
"type":"package",
"package": {
"name": "phanda/pathtranslator",
"version": "dev-master",
"dist": {
"url": "https://github.com/k-holy/Phanda_PathTranslator/zipball/master",
"type": "zip"
@k-holy
k-holy / Greeting.org.php
Created July 18, 2012 08:19
BEAR.Sundayはじめてのリソース
<?php
namespace sandbox\Resource\App\First;
use BEAR\Resource\AbstractObject;
/**
* Greeting resource
*/
class Greeting extends AbstractObject
{
@k-holy
k-holy / Greeting.App.php
Created July 20, 2012 09:51
BEAR.Sundayはじめてのページリソース
<?php
namespace sandbox\Resource\App\First;
use BEAR\Resource\AbstractObject;
/**
* Greeting resource
*/
class Greeting extends AbstractObject
{
@k-holy
k-holy / gd-ttf.php
Created July 26, 2012 09:52
GDでTTF
<?php
/**
* GDでTTF
* @author [email protected]
*/
$fontFile = __DIR__ . DIRECTORY_SEPARATOR . 'yojo.ttf';
$text = (isset($_GET['text'])) ? $_GET['text'] : null;
$fontSize = (isset($_GET['size']) && ctype_digit($_GET['size'])) ? intval($_GET['size']) : null;
@k-holy
k-holy / symfony-finder-with-fileinfo.php
Created August 30, 2012 08:22
Symfony-Finderコンポーネント+Fileinfoのサンプル
<?php
namespace Acme;
include_once realpath(__DIR__ . '/vendor/autoload.php');
use \Symfony\Component\Finder\Finder;
class U {
public static function H($data, $default=null) {