1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Load all classes from directory

Discussion in 'Development' started by SkyZone, Aug 18, 2018.

  1. SkyZone

    SkyZone Slime

    Messages:
    95
    Im making an plugin, which loads plugins from an directory which is set in the config. Now, the plugins are getting loaded but other plugins cant access the classes from these plugins.
    I tried this
    Code:
    foreach (glob("/home/atomic/plugins") as $file)
            {
                // get the file name of the current file without the extension
                // which is essentially the class name
                $class = basename($file, '.php');
    
                if (class_exists($class))
                {
                    $this->getServer()->getLoader()->loadClass($class);
                }
            }
    but it didnt work. The plugins are all in phar format.
    I get this error when trying to access the classes from other plugins:[​IMG]

    Does somebody know how to load the classes?
     
  2. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    774
    GitHub:
    dktapps
    You should add them as dependencies in the plugin.yml, to make sure the needed plugins load first.

    edit: my bad, misread the OP.
     
    Last edited: Aug 18, 2018
  3. SkyZone

    SkyZone Slime

    Messages:
    95
    They are loaded, but the server cant find the classes, because they are in anothor directory
     
  4. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    774
    GitHub:
    dktapps
    You fundamentally misunderstand class loading. `class_exists()` will return `false` for a not-loaded class. Additionally, `BaseClassLoader->loadClass()` is not supposed to be called by external things. You should add the `plugins` directory to the loader path instead of doing this.

    However, this makes no sense anyway because script plugins already have this functionality.
     
    RyanShaw likes this.
  5. SkyZone

    SkyZone Slime

    Messages:
    95
    I added them. Still class not found
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.