Created
May 21, 2016 19:59
-
-
Save tedbow/abcf8359b2118b01adf080282e7bba02 to your computer and use it in GitHub Desktop.
test_constructor.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Constructs a new UserLoginResource object. | |
* | |
* @param \Drupal\Core\Flood\FloodInterface $flood | |
* The flood controller. | |
* @param \Drupal\user\UserStorageInterface $user_storage | |
* The user storage. | |
* @param \Drupal\Core\Access\CsrfTokenGenerator $csrf_token | |
* The CSRF token generator. | |
* @param \Drupal\user\UserAuthInterface $user_auth | |
* The user authentication. | |
* @param array $serializer_formats | |
* The available serialization formats. | |
*/ | |
public function __construct(FloodInterface $flood, UserStorageInterface $user_storage, CsrfTokenGenerator $csrf_token, UserAuthInterface $user_auth, Serializer $serializer, array $serializer_formats) { | |
$this->flood = $flood; | |
$this->userStorage = $user_storage; | |
$this->csrfToken = $csrf_token; | |
$this->userAuth = $user_auth; | |
$this->serializerFormats = $serializer_formats; | |
$this->serializer = $serializer; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public static function create(ContainerInterface $container) { | |
if ($container->hasParameter('serializer.formats') && $container->has('serializer')) { | |
$serializer = $container->get('serializer'); | |
$formats = $container->getParameter('serializer.formats'); | |
} | |
else { | |
$formats = ['json', 'xml']; | |
$encoders = [new JsonEncoder(), new XmlEncoder()]; | |
$serializer = new Serializer([], $encoders); | |
} | |
return new static( | |
$container->get('flood'), | |
$container->get('entity_type.manager')->getStorage('user'), | |
$container->get('csrf_token'), | |
$container->get('user.auth'), | |
$serializer, | |
$formats | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment