1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Lack of Interest New method to return dynamicresolved class

Discussion in 'Closed Suggestions' started by xf_phantom, Jul 24, 2013.

  1. xf_phantom

    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: Jul 24, 2013
    James Freeman likes this.

Share This Page