Created
August 2, 2010 11:17
-
-
Save fprochazka/504496 to your computer and use it in GitHub Desktop.
This file contains 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 | |
abstract class BaseModel extends Object | |
{ | |
/** @var Model instance */ | |
static $register = array(); | |
public static function getInstance($class) | |
{ | |
if( !isset(self::$register[$class]) OR !(self::$register[$class] instanceof BaseModel) ){ | |
self::$register[$class] = new $class; | |
} | |
return self::$register[$class]; | |
} | |
public function getName() | |
{ | |
return preg_replace("#Model$#", '', get_class($this)); | |
} | |
// ... | |
} |
This file contains 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 | |
abstract class BasePresenter extends Presenter | |
{ | |
/** @var Object */ | |
private $model; | |
public $oldLayoutMode = False; | |
public $oldModuleMode = False; | |
public function getModel($modelName = Null) | |
{ | |
if( !empty($modelName) ){ | |
$class = str_replace(":", "_", $modelName)."Model"; | |
$model = callback($class, 'getInstance')->invokeArgs($class); | |
return $model; | |
} | |
if( !($this->model instanceof BaseModel) ){ | |
$name = $this->getName(); | |
$class = str_replace(":", "_", $name)."Model"; | |
$this->model = callback($class, 'getInstance')->invokeArgs($class); | |
} | |
return $this->model; | |
} | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment