public static function getTask($task_type, $task_options = NULL) {
    if (!isset(self::$environment)) {
      throw new \Exception("Environment not set.");
    }

    $task_class = self::getTaskClass($task_type);

    // Set the environment handler on the task handler too.
    $task_handler = new $task_class(self::$environment, $task_options);

    // Find out what sanity level the task handler needs.
    $required_sanity = $task_handler->getSanityLevel();
    //dsm($required_sanity);

    // Check the environment for the required sanity level.
    self::$environment->verifyEnvironment($required_sanity);

    return $task_handler;
  }