ZF\Apigility\Admin\Model\ModuleModel::deleteModule PHP Method

deleteModule() public method

Delete an existing module
public deleteModule ( string $module, string $path = '.', boolean $recursive = false ) : boolean
$module string
$path string
$recursive boolean
return boolean
    public function deleteModule($module, $path = '.', $recursive = false)
    {
        $application = (require sprintf('%s/config/application.config.php', $path));
        if (!is_array($application) || !isset($application['modules']) || !in_array($module, $application['modules'], true)) {
            // Module does not exist in configuration; nothing to do
            return true;
        }
        $modules = array_filter($application['modules'], function ($value) use($module) {
            return $module !== $value;
        });
        $application['modules'] = $modules;
        if (!$this->writeApplicationConfig($application, $path)) {
            // error writing application config
            return false;
        }
        if (!$recursive) {
            // Not a recursive deletion? done
            return true;
        }
        $modulePath = sprintf('%s/module/%s', $path, $module);
        if (!file_exists($modulePath)) {
            // module path does not exist; we can be done.
            return true;
        }
        Utility::recursiveDelete($modulePath);
        return true;
    }

Usage Example

 /**
  * Delete a module (and, optionally, all code within it)
  *
  * @param  string $id
  * @return bool
  */
 public function delete($id)
 {
     $request = $this->getEvent()->getRequest();
     $recursive = $request->getQuery('recursive', false);
     $module = $this->modules->getModule($id);
     if (!$module instanceof ModuleEntity) {
         return new ApiProblem(404, 'Module not found or is not apigility-enabled');
     }
     $name = $module->getName();
     return $this->modules->deleteModule($name, $this->modulePath, $recursive);
 }