class ReadonlymodeCommands in Read only mode 2.0.x
The drush commands.
Hierarchy
- class \Drupal\readonlymode\Commands\ReadonlymodeCommands extends \Drush\Commands\DrushCommands
Expanded class hierarchy of ReadonlymodeCommands
1 string reference to 'ReadonlymodeCommands'
1 service uses ReadonlymodeCommands
File
- src/
Commands/ ReadonlymodeCommands.php, line 12
Namespace
Drupal\readonlymode\CommandsView source
class ReadonlymodeCommands extends DrushCommands {
/**
* The read only mode manager.
*
* @var \Drupal\readonlymode\ReadonlymodeManager
*/
protected $manager;
/**
* ReadonlymodeCommands constructor.
*
* @param \Drupal\readonlymode\ReadonlymodeManager $manager
* The read only mode manager.
*/
public function __construct(ReadonlymodeManager $manager) {
parent::__construct();
$this->manager = $manager;
}
/**
* Get the status of the read only mode.
*
* @command readonlymode:status
*
* @usage drush readonlymode:status
* Prints the warning of the read-only mode.
*/
public function getStatus() {
if ($this->manager
->isReadonly()) {
$this
->io()
->warning($this->manager
->getWarningMessage());
return;
}
$this
->io()
->success("The read-only mode is inactive.");
}
/**
* Set the status of the read only mode.
*
* @param mixed $mode
* The new mode.
*
* @command readonlymode:set
*
* @usage drush readonlymode:set 1
* Activate the read only mode
*/
public function setMode($mode) {
// Cast the method argument to boolean.
switch (strtolower($mode)) {
case 'true':
case 'on':
$mode = TRUE;
break;
case 'false':
case 'off':
$mode = FALSE;
break;
default:
$mode = (bool) $mode;
}
$this->manager
->setReadonly($mode);
$message = 'Read-only mode ' . ($mode ? 'activated' : 'deactivated');
$this
->io()
->success($message);
}
/**
* After the deploy hook has run we can disable the readonly mode.
*
* @hook post-command deploy:hook
*/
public function postDeploy($result, CommandData $commandData) {
if ($result === 0) {
// We could make this configurable.
if ($this->manager
->isReadonly()) {
$this->manager
->setReadonly(FALSE);
$this
->io()
->success('Read-only mode disabled after deployment');
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ReadonlymodeCommands:: |
protected | property | The read only mode manager. | |
ReadonlymodeCommands:: |
public | function | Get the status of the read only mode. | |
ReadonlymodeCommands:: |
public | function | After the deploy hook has run we can disable the readonly mode. | |
ReadonlymodeCommands:: |
public | function | Set the status of the read only mode. | |
ReadonlymodeCommands:: |
public | function | ReadonlymodeCommands constructor. |