Skip to content

Instantly share code, notes, and snippets.

@fprochazka
Created August 2, 2010 11:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fprochazka/504496 to your computer and use it in GitHub Desktop.
Save fprochazka/504496 to your computer and use it in GitHub Desktop.
<?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));
}
// ...
}
<?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