Inpsyde\MultilingualPress\Module\Exception\ModuleAlreadyRegisteredException::for_id PHP Method

for_id() public static method

Returns a new exception object.
Since: 3.0.0
public static for_id ( string $id, string $action = 'register' ) : static
$id string Module ID.
$action string Optional. Action to be performed. Defaults to 'register'.
return static Exception object.
    public static function for_id($id, $action = 'register')
    {
        return new static(sprintf('Cannot %2$s "%1$s". There already is a module with this ID.', $id, $action));
    }

Usage Example

 /**
  * Registers the given module.
  *
  * @since 3.0.0
  *
  * @param Module $module Module object.
  *
  * @return bool Whether or not the module is active.
  *
  * @throws ModuleAlreadyRegisteredException if a module with the ID of the given module already has been registered.
  */
 public function register_module(Module $module)
 {
     $id = $module->id();
     if ($this->has_module($id)) {
         throw ModuleAlreadyRegisteredException::for_id($id, 'register');
     }
     if (isset($this->states[$id])) {
         if ($this->states[$id]) {
             $module->activate();
         } else {
             $module->deactivate();
         }
     } else {
         $this->states[$id] = $module->is_active();
         $this->save_modules();
     }
     $this->modules[$id] = $module;
     return $this->states[$id];
 }
ModuleAlreadyRegisteredException