summaryrefslogtreecommitdiff
path: root/src/PluginLoader.php
blob: b2ac61d7e891e1aca14c40296d39c947a41822af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php

namespace FlatFileForms;

class PluginLoader
{
  public function __construct()
  {
    /**@var Utilities $utilities*/
    global $utilities;

    $pluginsDirectoryPath = $_ENV['app']['pluginsFolderPath'];

    spl_autoload_register(function ($classname) use ($pluginsDirectoryPath) {
      $classname = str_replace('FlatFileForms\\Plugins\\', '', $classname);

      require_once
        $pluginsDirectoryPath . '/' .
        str_replace('\\', '/', $classname) .
        '.php';
    });

    $pluginDirectories = $utilities->scandir($pluginsDirectoryPath);
    foreach ($pluginDirectories as $directory) {
      $pluginClass = 'FlatFileForms\\Plugins\\' . basename($directory) . '\\Plugin';
      $plugin = new $pluginClass();
    }
  }
}