ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilUserPasswordEncoderFactory.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2014 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Services/User/exceptions/class.ilUserException.php';
5
12{
17
21 protected $encoders = array();
22
26 public function __construct(array $config = array())
27 {
28 if (!empty($config)) {
29 foreach ($config as $key => $value) {
30 switch (strtolower($key)) {
31 case 'default_password_encoder':
32 $this->setDefaultEncoder($value);
33 break;
34 }
35 }
36 }
37
38 $this->initEncoders($config);
39 }
40
44 protected function initEncoders(array $config)
45 {
46 $this->encoders = [];
47
48 $encoders = [
52 ];
53
54 foreach ($encoders as $encoder) {
55 if ($encoder->isSupportedByRuntime()) {
56 $this->encoders[$encoder->getName()] = $encoder;
57 }
58 }
59 }
60
64 public function getDefaultEncoder()
65 {
67 }
68
73 {
74 $this->default_encoder = $default_encoder;
75 }
76
80 public function getEncoders()
81 {
82 return $this->encoders;
83 }
84
89 public function setEncoders(array $encoders)
90 {
91 $this->encoders = array();
92 foreach ($encoders as $encoder) {
93 if (!($encoder instanceof ilPasswordEncoder)) {
94 throw new ilUserException(sprintf('One of the passed encoders is not valid: %s.', json_encode($encoder)));
95 }
96 $this->encoders[$encoder->getName()] = $encoder;
97 }
98 }
99
103 public function getSupportedEncoderNames()
104 {
105 return array_keys($this->getEncoders());
106 }
107
114 public function getEncoderByName($name, $get_default_on_mismatch = false)
115 {
116 if (!isset($this->encoders[$name])) {
117 if (!$get_default_on_mismatch) {
118 throw new ilUserException(sprintf('The encoder "%s" was not configured.', $name));
119 } elseif (!$this->getDefaultEncoder()) {
120 throw new ilUserException('No default encoder specified, fallback not possible.');
121 } elseif (!isset($this->encoders[$this->getDefaultEncoder()])) {
122 throw new ilUserException("No default encoder found for name: '{$this->getDefaultEncoder()}'.");
123 }
124
125 return $this->encoders[$this->getDefaultEncoder()];
126 }
127
128 return $this->encoders[$name];
129 }
130}
sprintf('%.4f', $callTime)
An exception for terminatinating execution or to throw for unit testing.
Class for user related exception handling in ILIAS.
getEncoderByName($name, $get_default_on_mismatch=false)
$key
Definition: croninfo.php:18
if($format !==null) $name
Definition: metadata.php:146