Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Customer.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
19 
23 class Customer implements ResolverInterface
24 {
28  private $customerResolver;
29 
33  public function __construct(
34  CustomerDataProvider $customerResolver
35  ) {
36  $this->customerResolver = $customerResolver;
37  }
38 
42  public function resolve(
43  Field $field,
44  $context,
46  array $value = null,
47  array $args = null
48  ) {
50  if ((!$context->getUserId()) || $context->getUserType() == UserContextInterface::USER_TYPE_GUEST) {
52  __(
53  'Current customer does not have access to the resource "%1"',
54  [\Magento\Customer\Model\Customer::ENTITY]
55  )
56  );
57  }
58 
59  try {
60  $data = $this->customerResolver->getCustomerById($context->getUserId());
61  return !empty($data) ? $data : [];
62  } catch (NoSuchEntityException $exception) {
63  throw new GraphQlNoSuchEntityException(__('Customer id %1 does not exist.', [$context->getUserId()]));
64  }
65  }
66 }
__()
Definition: __.php:13
$value
Definition: gender.phtml:16
foreach( $_productCollection as $_product)() ?>" class $info
Definition: listing.phtml:52
__construct(CustomerDataProvider $customerResolver)
Definition: Customer.php:33
resolve(Field $field, $context, ResolveInfo $info, array $value=null, array $args=null)