Completed
Push — drop-container-aware-command ( 55eeca )
by Christian
02:20
created

CreateEncodingCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 23
ccs 0
cts 18
cp 0
rs 9.552
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
/*
4
 * This file is part of the XabbuhPandaBundle package.
5
 *
6
 * (c) Christian Flothmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Xabbuh\PandaBundle\Command;
13
14
use Symfony\Component\Console\Input\InputArgument;
15
use Symfony\Component\Console\Input\InputInterface;
16
use Symfony\Component\Console\Input\InputOption;
17
use Symfony\Component\Console\Output\OutputInterface;
18
use Xabbuh\PandaClient\Model\Video;
19
20
/**
21
 * Command to create an encoding.
22
 *
23
 * @author Christian Flothmann <[email protected]>
24
 *
25
 * @final since 1.5
26
 */
27
class CreateEncodingCommand extends CloudCommand
28
{
29
    protected static $defaultName = 'panda:encoding:create';
30
31
    /**
32
     * {@inheritDoc}
33
     */
34
    protected function configure()
35
    {
36
        $this->setDescription('Create an encoding');
37
        $this->addArgument(
38
            'video-id',
39
            InputArgument::REQUIRED,
40
            'Id of the video being encoded'
41
        );
42
        $this->addOption(
43
            'profile-id',
44
            null,
45
            InputOption::VALUE_REQUIRED,
46
            'Id of the profile'
47
        );
48
        $this->addOption(
49
            'profile-name',
50
            null,
51
            InputOption::VALUE_REQUIRED,
52
            'A profile\'s name'
53
        );
54
55
        parent::configure();
56
    }
57
58
    /**
59
     * {@inheritDoc}
60
     */
61
    protected function doExecuteCommand(InputInterface $input, OutputInterface $output)
62
    {
63
        $profileId = $input->getOption('profile-id');
64
        $profileName = $input->getOption('profile-name');
65
66
        if (null !== $profileId && null === $profileName) {
67
            $video = new Video();
68
            $video->setId($input->getArgument('video-id'));
69
            $encoding = $this->getCloud($input)->createEncodingWithProfileId(
70
                $video,
71
                $profileId
72
            );
73
            $output->writeln(
74
                sprintf(
75
                    '<info>Successfully created encoding with id %s</info>',
76
                    $encoding->getId()
77
                )
78
            );
79
        } elseif (null === $profileId && null !== $profileName) {
80
            $video = new Video();
81
            $video->setId($input->getArgument('video-id'));
82
            $encoding = $this->getCloud($input)->createEncodingWithProfileName(
83
                $video,
84
                $profileName
85
            );
86
            $output->writeln(
87
                sprintf(
88
                    '<info>Successfully created encoding with id %s</info>',
89
                    $encoding->getId()
90
                )
91
            );
92
        } else {
93
            $output->writeln(
94
                '<error>Exactly one option of --profile-id or --profile-name must be given.</error>'
95
            );
96
        }
97
    }
98
}
99