Skip to content

Instantly share code, notes, and snippets.

<?php
/**
* MemcacheHandler
* @author letitride
*/
class MemcacheHandler
{
static private $memcache = null;
static private $hosts = array(
@letitride
letitride / iterator.sample.php
Created November 5, 2012 00:22
php iterator
<?php
class Object {
private $name;
public function __construct( $value ){
$this->name = $value;
}
public function print_name(){
print $this->name."\n";
}
@letitride
letitride / adapter.sample.php
Created November 5, 2012 23:35
php adapter
<?php
class BaseAPI {
static public function print_arg( $value ){
print "$value \n";
}
}
abstract class APIAdapter{
@letitride
letitride / template_method.sample.php
Created November 6, 2012 23:15
php template_method
<?php
abstract class AbstractList{
protected $_count;
protected $_list = array();
public function main(){
$this->_count();
@letitride
letitride / mvc_method_chain.sample.php
Created November 7, 2012 00:33
PHP MVC method chain sample
<?php
class Context{
static private $arg;
function __constract( $arg ){
self::$arg = $arg;
}
public function run(){
@letitride
letitride / factory_method.sample.php
Created November 8, 2012 01:31
php factory_method
<?php
abstract class BookFactory{
protected $_books = array();
function create( $name, $page ){
$book = $this->get_instance( $name );
$book->set_page( $page );
@letitride
letitride / search_tree.php
Created November 8, 2012 07:29
php search_tree
//src=arrayの2分木検索
function search_tree( $src = array(), $target, $end, $begin = false )
{
if( $begin === false )
{
$begin = floor( $end / 2 );
}
//配列ソートする?
@letitride
letitride / singleton.sample.php
Created November 8, 2012 23:15
php singleton
<?php
class GlobalCounter {
private static $instance = null;
private $cursol = 0;
private function __construct(){
$this->clean();
}
@letitride
letitride / prototype.sample.php
Created November 12, 2012 00:26
php prototype
<?php
/**
* object hash map
*/
class ProductManager{
private $_products = array();
/** hash map register */
function set( $name, $product ){
@letitride
letitride / builder.sample.php
Created November 12, 2012 23:20
php builder
<?php
abstract class ListBuilder{
protected $_text_count;
protected $_text_page;
abstract function set_count( $count );
abstract function set_page( $page );
abstract function set_list( $list );
abstract function get_list_data();