handleActivation(static::$file); } } /** * Deactivate the plugin * @return void */ public static function deactivate() { // Framework specific implementation if necessary... if (class_exists('FluentForm\App\Modules\Deactivator')) { (new Deactivator)->handleDeactivation(static::$file); } } /** * Validate the plugin by checking all rquired files/settings * @return void */ public static function validatePlugin() { if(!file_exists($glueJson = static::$basePath.'glue.json')) { die('The [glue.json] file is missing from "'.$basePath.'" directory.'); } static::$config = json_decode(file_get_contents($glueJson), true); $configPath = static::$basePath.'config'; if(!file_exists($file = $configPath.'/app.php')) { die('The [config.php] file is missing from "'.$configPath.'" directory.'); } static::$config = array_merge(include $file, static::$config); if (!($autoload = @static::$config['autoload'])) { die('The [autoload] key is not specified or invalid in "'.$glueJson.'" file.'); } if (!($namespace = @$autoload['namespace'])) { die('The [namespace] key is not specified or invalid in "'.$glueJson.'" file.'); } $namespaceMapping = @$autoload['mapping']; if (!($namespaceMapping || empty((array) $namespaceMapping))) { die('The [mapping] key is not specified or invalid in "'.$glueJson.'" file.'); } } /** * Register the autoloader * @return void */ public static function registerAutoLoader() { if (!static::$config) { static::$config = json_decode(file_get_contents(static::$basePath.'glue.json'), true); static::$config = array_merge(include static::$basePath.'config/app.php', static::$config); } spl_autoload_register([__CLASS__, 'loader']); } /** * Framework's custom autoloader * @param string $class * @return mixed */ public static function loader($class) { $namespace = static::$config['autoload']['namespace']; if(substr($class, 0, strlen($namespace)) !== $namespace) { return false; } foreach (static::$config['autoload']['mapping'] as $key => $value) { $className = str_replace( array('\\', $key, $namespace), array('/', $value, ''), $class ); $file = static::$basePath.trim($className, '/').'.php'; if (is_readable($file)) { return include $file; } } } /** * Register "plugins_loaded" hook to run the plugin * @return void */ public static function registerApplication() { add_action('plugins_loaded', function() { return new Application(static::$file, static::$config); }); } }