Lack of interest New method to return dynamicresolved class

This suggestion has been closed automatically because it did not receive enough votes over an extended period of time. If you wish to see this, please search for an open suggestion and, if you don't find any, post a new one.

xf_phantom

Well-known member
1. thx again again again for the resolvedynamic usage :)

2. to avoid to have to write always the same 10 lines of code, wouldn't it be worth to include a new method to XenForo_Application doing something like:

PHP:
  public static function getDynamicClassInstance($class, $instanceTypeValidation=null){
    $class = XenForo_Application::resolveDynamicClass($class);
     if (XenForo_Application::autoload($class))
     {
       $obj = new $class;
       if ($instanceTypeValidation){
         if ($obj instanceof $instanceTypeValidation){
           return $obj;
         }
         else {
           throw new XenForo_Exception("$class isn't a instance of $instanceTypeValidation");
         }
       }
       return $obj;
     }
     throw new XenForo_Exception("$class doesn't exist");
   }

Just in case we want to do it the proper way and not just
$class = XenForo_Application::resolveDynamicClass($class);
$obj = new $class;
 
Last edited:
Upvote 1
This suggestion has been closed. Votes are no longer accepted.
Back
Top Bottom