|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace N98\Magento\Command\Customer\Token; |
|
4
|
|
|
|
|
5
|
|
|
use Exception; |
|
6
|
|
|
use Magento\Integration\Model\Oauth\Token; |
|
7
|
|
|
use Magento\Integration\Model\Oauth\TokenFactory; |
|
8
|
|
|
use N98\Magento\Command\Customer\AbstractCustomerCommand; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
10
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
11
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class CreateCommand |
|
16
|
|
|
* @package N98\Magento\Command\Customer\Token |
|
17
|
|
|
*/ |
|
18
|
|
|
class CreateCommand extends AbstractCustomerCommand |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var TokenFactory |
|
22
|
|
|
*/ |
|
23
|
|
|
private $tokenModelFactory; |
|
24
|
|
|
|
|
25
|
|
|
protected function configure() |
|
26
|
|
|
{ |
|
27
|
|
|
$this |
|
28
|
|
|
->setName('customer:token:create') |
|
29
|
|
|
->addArgument('email', InputArgument::OPTIONAL, 'Email') |
|
30
|
|
|
->addArgument('website', InputArgument::OPTIONAL, 'Website of the customer') |
|
31
|
|
|
->addOption('no-newline', null, InputOption::VALUE_NONE, 'do not output the trailing newline') |
|
32
|
|
|
->setDescription('Create a new token for a customer.'); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @param Token $tokenModelFactory |
|
|
|
|
|
|
37
|
|
|
*/ |
|
38
|
|
|
public function inject(TokenFactory $tokenModelFactory) |
|
39
|
|
|
{ |
|
40
|
|
|
$this->tokenModelFactory = $tokenModelFactory; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param InputInterface $input |
|
45
|
|
|
* @param OutputInterface $output |
|
46
|
|
|
* |
|
47
|
|
|
* @return int|void |
|
48
|
|
|
* @throws Exception |
|
49
|
|
|
*/ |
|
50
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
51
|
|
|
{ |
|
52
|
|
|
// Detect and Init Magento |
|
53
|
|
|
$this->detectMagento($output, true); |
|
54
|
|
|
if (!$this->initMagento()) { |
|
55
|
|
|
return; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
// Detect customer |
|
59
|
|
|
$customer = $this->detectCustomer($input, $output); |
|
60
|
|
|
if ($customer === null) { |
|
61
|
|
|
return; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** @var Token $tokenModel */ |
|
65
|
|
|
$tokenModel = $this->tokenModelFactory->create(); |
|
66
|
|
|
$tokenModel->createCustomerToken($customer->getId()); |
|
67
|
|
|
|
|
68
|
|
|
$output->write($tokenModel->getToken(), !$input->getOption('no-newline')); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.