1
|
|
|
<?php |
2
|
|
|
namespace BarenoteCli\Command\Note; |
3
|
|
|
|
4
|
|
|
use Barenote\Domain\Identity\NoteId; |
5
|
|
|
use BarenoteCli\BarenoteApplication; |
6
|
|
|
use Symfony\Component\Console\Command\Command; |
7
|
|
|
use Symfony\Component\Console\Helper\QuestionHelper; |
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
10
|
|
|
use Symfony\Component\Console\Question\ConfirmationQuestion; |
11
|
|
|
use Symfony\Component\Console\Question\Question; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class ViewOneNote |
15
|
|
|
* @package BarenoteCli\Command\Note |
16
|
|
|
* @method BarenoteApplication getApplication() |
17
|
|
|
*/ |
18
|
|
|
class ViewOneNote extends Command |
19
|
|
|
{ |
20
|
|
|
protected function configure() |
21
|
|
|
{ |
22
|
|
|
$this |
23
|
|
|
->setName('barenote:note:one') |
24
|
|
|
->setDescription('Detailed information about one of your notes') |
25
|
|
|
->setHelp('Help for command'); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
29
|
|
|
{ |
30
|
|
|
$client = $this->getApplication()->getClient(); |
31
|
|
|
/** @var QuestionHelper $helper */ |
32
|
|
|
$helper = $this->getHelper('question'); |
33
|
|
|
|
34
|
|
|
$question = new Question('Please provide ID of the note you would like to read' . PHP_EOL, '1'); |
35
|
|
|
$question->setAutocompleterValues(['1']); |
36
|
|
|
$id = $helper->ask($input, $output, $question); |
37
|
|
|
$note = $client->getNotesEndpoint()->getOne(new NoteId((int)$id)); |
38
|
|
|
|
39
|
|
|
$output->writeln("<info>ID:</info>" . PHP_EOL . $note->getId()->getValue()); |
|
|
|
|
40
|
|
|
$output->writeln("<info>Title:</info>" . PHP_EOL . $note->getTitle()); |
|
|
|
|
41
|
|
|
$output->writeln("<info>Content:</info>" . PHP_EOL . $note->getContent()); |
|
|
|
|
42
|
|
|
|
43
|
|
|
$question = new ConfirmationQuestion('Do you want to exit the app? (y/N)' . PHP_EOL, false); |
44
|
|
|
|
45
|
|
|
if ($helper->ask($input, $output, $question)) { |
46
|
|
|
exit(0); |
|
|
|
|
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
} |
PHP provides two ways to mark string literals. Either with single quotes
'literal'
or with double quotes"literal"
. The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (
\'
) and the backslash (\\
). Every other character is displayed as is.Double quoted string literals may contain other variables or more complex escape sequences.
will print an indented:
Single is Value
If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.
For more information on PHP string literals and available escape sequences see the PHP core documentation.