This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'FileUtils' | |
namespace :seed do | |
desc 'Dump a database to yaml fixtures. Set environment variables DB | |
and DEST to specify the target database and destination path for the | |
fixtures. DB defaults to development and DEST defaults to RAILS_ROOT/ | |
db/fixtures.' | |
task :dump => :environment do | |
path = ENV['DEST'] || "#{RAILS_ROOT}/db/fixtures" | |
db = ENV['DB'] || 'development' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class P extends Object { | |
static $something; | |
static function foo() { | |
return __METHOD__; | |
} | |
function bar() {} | |
} | |
$c = _class('P'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Backward compat version of get_called_class | |
*/ | |
if (!function_exists('get_called_class')): | |
function get_called_class() { | |
$bt = debug_backtrace(); | |
$lines = file($bt[1]['file']); | |
preg_match('/([a-zA-Z0-9\_]+)::'.$bt[1]['function'].'/', $lines[$bt[1]['line']-1], $matches); | |
return $matches[1]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Person extends Model { | |
var $hasMany = 'hobbies'; | |
} | |
class Hobby extends Model { | |
var $belongsTo = 'person'; | |
} | |
echo Person::create(array( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Openbet_Collection { | |
static function fromArray($array, $class) { | |
$instance = new Openbet_Collection; | |
foreach ($list as $item) { | |
$instance[] = new $class($item); | |
} | |
return $instance; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Blocks */ | |
$list->reduce(array(), '|$rs, $e| | |
$rs[$e->name] = $e->price; | |
$rs; | |
'); | |
/* Yielding |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function extend($object, $class) { | |
$attr = 'methods'; | |
$$attr = get_class_methods($class); | |
eval($object.'::$'.$attr.' = $methods;'); | |
} | |
class Object { | |
static $methods = array(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function evaluate_block($block, $arguments = array()) { | |
# implict return | |
$lines = explode(';', $block); | |
$last =& $lines[count($lines)-2]; | |
if (strpos($last, 'return') === false) { | |
$last = 'return '.$last; | |
} | |
$block = join(';', $lines); | |
if (isset($arguments['this'])) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'FileUtils' | |
namespace :seed do | |
desc 'Dump a database to yaml fixtures. Set environment variables DB | |
and DEST to specify the target database and destination path for the | |
fixtures. DB defaults to development and DEST defaults to RAILS_ROOT/ | |
db/fixtures.' | |
task :dump => :environment do | |
path = ENV['DEST'] || "#{RAILS_ROOT}/db/fixtures" | |
db = ENV['DB'] || 'development' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Patch isset($model->attr) problem for this | |
* php library http://lukebaker.org/projects/activerecord-in-php/ | |
*/ | |
class ActiveRecord { | |
function __isset($attr) { | |
try { | |
$value = $this->$attr; |