php - PHP 中如果 case 等于 'merge' 则跳过父函数

标签 php

我有一个try catch声明 switch里面有声明。

我是 PHP 新手,所以请耐心等待。我知道这对于专业人士来说可能很简单。

我想要实现的是跳过前 2 if顶部的语句 if case is 'merge'

try {
    if (!make_thumbnail($videoFile, $thumbLocal))
        throw new \Exception ($thumbLocal);
    if (!put_file($thumbLocal, $thumbRemote))
        throw new \Exception($thumbRemote);
    switch($message->priority) {
        case 'mp4':
            make_mp4($videoFile, $mp4file);
            if (!file_exists($mp4file))
                throw new \Exception($mp4file);
            if (!put_file($mp4file, $remotemp4))
                throw new \Exception($remotemp4);
            send_ready_ping($message->ping, $message->id, VIDEO_MP4);
            make_webm($videoFile,$webmfile);
            if (!file_exists($webmfile))
                throw new \Exception($webmfile);
            if (!put_file($webmfile, $remotewebm))
                throw new \Exception($remotewebm);
            send_ready_ping($message->ping,$message->id,VIDEO_BOTH);
            break;
        case 'merge':
            make_merged_video($videoFile, $audioFile, $mp4file, $message->options);
            if (!file_exists($mp4file))
                throw new \Exception($mp4file);
            if (!put_file($mp4file, $remotemp4))
                throw new \Exception($remotemp4);
            send_ready_ping($message->ping, $message->id, VIDEO_MP4);
            break;
        default;
            make_webm($videoFile,$webmfile);
            if (!file_exists($webmfile))
                throw new \Exception($webmfile);
            if (!put_file($webmfile, $remotewebm))
                throw new \Exception($remotewebm);
            send_ready_ping($message->ping, $message->id, VIDEO_WEBM);
            make_mp4($videoFile,$mp4file);
            if (!file_exists($mp4file))
                throw new \Exception($mp4file);
            if (!put_file($mp4file, $remotemp4))
                throw new \Exception($remotemp4);
            send_ready_ping($message->ping,$message->id,VIDEO_BOTH);
            break;
    }
}
catch (\Exception $e) {
    echo "Exception: " . $e->getMessage() . "\n";
    send_ready_ping($message->ping, $message->id, VIDEO_FAIL);
}

每当case时我想跳过缩略图生成器等于'合并'

这些是我想跳过的代码/事件:

  if (!make_thumbnail($videoFile,$thumbLocal))
      throw new \Exception ($thumbLocal);
  if (!put_file($thumbLocal, $thumbRemote))
      throw new \Exception($thumbRemote);

我尝试将其放入 switch 语句中,如下所示,但没有成功:

if (case != "merge") {
    if(!make_thumbnail($videoFile, $thumbLocal))
        throw new \Exception ($thumbLocal);
    if (!put_file($thumbLocal, $thumbRemote))
        throw new \Exception($thumbRemote);
}

有什么想法吗?

最佳答案

我可能会重构和重组,但目前我没有这方面的建议。鉴于现有代码:

if($message->priority != 'merge' && !make_thumbnail($videoFile,$thumbLocal))
    throw new \Exception ($thumbLocal);

if($message->priority != 'merge' && !put_file($thumbLocal,$thumbRemote))
    throw new \Exception($thumbRemote);

关于php - PHP 中如果 case 等于 'merge' 则跳过父函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22487157/

相关文章:

php - 如何使用正则 exp 从段落中选择电话号码

php - 如何在 laravel4 中针对 INSERT IGNORE 的 sql 注入(inject)使用安全的原始查询

javascript - 在 Twig SYMFONY 302 中渲染 Controller 时的重定向

php - 对象数组返回相同的值

php - 按单维数组对多维数组进行排序

php - 如何在 PHP 代码中正确设置错误报告?

php - 我如何检测客户端浏览器是否安装了 adobe reader 插件

php - 我无法对出生数据进行排序

java - 如何使用 SOAP 将对象从 PHP 发送到 Java Web 服务?

php - 特定用户表