Exemplo n.º 1
0
 /**
  * Factory method that returns a Singleton instance of the ModelManager class
  * that is used for performing CRUD actions on Models of the type specified.
  *
  * @param string $modelName The name of the Model whose manager we want to retrieve
  * @return \Buan\ModelManager
  */
 public static final function create($modelName)
 {
     // Vars
     static $modelManagerInstances = [];
     // Return instance if already created
     if (isset($modelManagerInstances[$modelName])) {
         return $modelManagerInstances[$modelName];
     }
     // Create new instance and return
     $managerClassName = Inflector::modelName_modelManagerClass($modelName);
     try {
         $modelManagerInstances[$modelName] = new $managerClassName($modelName);
     } catch (Exception $e) {
         SystemLog::add($e->getMessage(), SystemLog::CORE);
         $modelManagerInstances[$modelName] = new ModelManager($modelName);
     }
     return $modelManagerInstances[$modelName];
 }
Exemplo n.º 2
0
 /**
  * @param string $actionCommand Action to invoke (lower-hyphenated format, ie. action-command)
  * @return View
  */
 public final function invokeAction($actionCommand)
 {
     // Convert the action name to the format used for class method names
     // (ie. ActionName)
     $actionMethodName = Inflector::actionCommand_actionMethod($actionCommand);
     // Disregard this invocation if the $actionMethodName is listed in the
     // $allPrivateMethods array
     if (in_array($actionMethodName, $this->allPrivateMethods)) {
         return $this->unknown($this->params, $actionMethodName);
     }
     // Invoke the method (ensuring it's "public"), or the 'unknown' method
     // if it doesn't exist
     if (method_exists($this, $actionMethodName)) {
         $r = new ReflectionClass($this);
         $m = $r->getMethod($actionMethodName);
         if (!$m->isPublic() || $m->getName() !== $actionMethodName) {
             SystemLog::add(['Attempting to call a non-public action method: %s', $actionMethodName], SystemLog::FATAL);
             return new View();
         } else {
             return $this->{$actionMethodName}($this->params);
         }
     } else {
         return $this->unknown($this->params, $actionCommand);
     }
 }