Skip to content

Commit

Permalink
#29 - first attempt, needs way deeper testing
Browse files Browse the repository at this point in the history
  • Loading branch information
pettazz committed Apr 28, 2015
1 parent 7408b41 commit 22d60fc
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions JACKED/Syrup.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,21 @@ private function registerModule($moduleName){
$this->registeredModels[$moduleName] = new $modelName($this->config->driverConfig, $this->JACKED->Logr, $this->JACKED->Util, $modelName);
$thingy = $this->registeredModels[$moduleName];
}

/**
* Register a Model (not a module) with Syrup. This method accepts an already instantiated model object
* and adds it to registered models.
*
* @param $model SyrupModel The model object to be registered
* @param $modelName String The full (case-sensitive) class name of the Model to be registered
* @throws ModelAlreadyExistsException If the given name has already been registered
*/
public function registerModel($model, $modelName){
if(array_key_exists($modelName, $this->registeredModels)){
throw new ModelAlreadyExistsException($modelName);
}
$this->registeredModels[$modelName] = $model;
}
}


Expand All @@ -85,4 +100,12 @@ public function __construct($name, $code = 0, Exception $previous = null){
parent::__construct($message, $code, $previous);
}
}

class ModelAlreadyExistsException extends Exception{
public function __construct($name, $code = 0, Exception $previous = null){
$message = "Model named `$name` has already been registered.";

parent::__construct($message, $code, $previous);
}
}
?>

0 comments on commit 22d60fc

Please sign in to comment.