function drush_op

8.0.x drush.inc drush_op($callable)
6.x drush.inc drush_op($function)
7.x drush.inc drush_op($callable)
3.x drush.inc drush_op($function)
4.x drush.inc drush_op($function)
5.x drush.inc drush_op($function)
master drush.inc drush_op($callable)

Calls a given function, passing through all arguments unchanged.

This should be used when calling possibly mutative or destructive functions (e.g. unlink() and other file system functions) so that can be suppressed if the simulation mode is enabled.

Important: Call or shell output.

Parameters

$callable: The name of the function. Any additional arguments are passed along.

Return value

The return value of the function, or TRUE if simulation mode is enabled.

See also

drush_op_system() to execute a shell command,

drush_shell_exec() to execute a shell command and capture the

34 calls to drush_op()
DrushMakeProject::applyPatches in commands/make/make.project.inc
Retrieve and apply any patches specified by the makefile to this project.
drush_archive_dump in commands/core/archive.drush.inc
Command callback. Generate site archive file.
drush_archive_restore in commands/core/archive.drush.inc
Command callback. Restore web site(s) from a site archive file.
drush_cache_command_clear in commands/core/cache.drush.inc
Command callback for drush cache-clear.
drush_cache_command_get in commands/core/cache.drush.inc
Print an object returned from the cache.

... See full list

File

includes/drush.inc, line 677
The drush API implementation and helpers.

Code

function drush_op($callable) {
  $args_printed = array();
  $args = func_get_args();
  array_shift($args); // Skip function name
  foreach ($args as $arg) {
    $args_printed[] = is_scalar($arg) ? $arg : (is_array($arg) ? 'Array' : 'Object');
  }

  if (!is_array($callable)) {
    $callable_string = $callable;
  }
  else {
    if (is_object($callable[0])) {
      $callable_string = get_class($callable[0]) . '::' . $callable[1];
    }
    else {
      $callable_string = implode('::', $callable);
    }
  }

  // Special checking for drush_op('system')
  if ($callable == 'system') {
    drush_log(dt("Do not call drush_op('system'); use drush_op_system instead"), LogLevel::DEBUG);
  }

  if (drush_get_context('DRUSH_VERBOSE') || drush_get_context('DRUSH_SIMULATE')) {
    drush_log(sprintf("Calling %s(%s)", $callable_string, implode(", ", $args_printed)), LogLevel::DEBUG);
  }

  if (drush_get_context('DRUSH_SIMULATE')) {
    return TRUE;
  }

  return drush_call_user_func_array($callable, $args);
}