## Apache Zeta Components Manual :: File Source for typekey_options.php

## Source for file typekey_options.php

Documentation is available at typekey_options.php

1. <?php
2. /**
3. * File containing the ezcAuthenticationTypekeyOptions class.
4. *
5. * Licensed to the Apache Software Foundation (ASF) under one
6. * or more contributor license agreements. See the NOTICE file
7. * distributed with this work for additional information
8. * regarding copyright ownership. The ASF licenses this file
9. * to you under the Apache License, Version 2.0 (the
10. * "License"); you may not use this file except in compliance
11. * with the License. You may obtain a copy of the License at
12. *
13. * http://www.apache.org/licenses/LICENSE-2.0
14. *
15. * Unless required by applicable law or agreed to in writing,
16. * software distributed under the License is distributed on an
17. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18. * KIND, either express or implied. See the License for the
19. * specific language governing permissions and limitations
20. * under the License.
21. *
22. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
23. * @filesource
24. * @package Authentication
25. * @version //autogen//
26. */
28. /**
29. * Class containing the options for the TypeKey authentication filter.
30. *
31. * Example of use:
32. * <code>
33. * // create an options object
34. * $options = new ezcAuthenticationTypekeyOptions();
35. * $options->validity = 60;
36. * $options->keysFile = '/tmp/typekey_keys.txt';
37. * $options->requestSource = $_POST;
38. *
39. * // use the options object when creating a new TypeKey filter
40. * $filter = new ezcAuthenticationTypekeyFilter( $options );
41. *
42. * // alternatively, you can set the options to an existing filter
43. * $filter = new ezcAuthenticationTypekeyFilter();
44. * $filter->setOptions( $options );
45. * </code>
46. *
47. * @property int $validity
48. * The maximum timespan that can exist between the timestamp
49. * sent by the application server at log-in and the timestamp sent
50. * by the TypeKey server. A value of 0 means the validity value
51. * is not taken into consideration when validating the response
52. * sent by the TypeKey server. Do not use a value too small, as
53. * the servers might not be synchronized.
54. * @property string $keysFile
55. * The file from where to retrieve the public keys which are used
56. * for checking the TypeKey signature. Can be a local file or a
57. * URL. Default is http://www.typekey.com/extras/regkeys.txt.
58. * Developers can save the file locally once per day to improve the
59. * speed of the TypeKey authentication (which reads this file
60. * at every authentication attempt).
61. * @property array(string=>mixed) $requestSource
62. * From where to get the parameters returned by the TypeKey server.
63. * Default is $_GET.
64. *
65. * @package Authentication
66. * @version //autogen//
67. */
68. class ezcAuthenticationTypekeyOptions extends ezcAuthenticationFilterOptions
69. {
70. /**
71. * Constructs an object with the specified values.
72. *
73. * @throws ezcBasePropertyNotFoundException
74. * if $options contains a property not defined
75. * @throws ezcBaseValueException
76. * if $options contains a property with a value not allowed
77. * @throws ezcBaseFileNotFoundException
78. * if the $value file does not exist
79. * @throws ezcBaseFilePermissionException
80. * if the $value file cannot be opened for reading
81. * @param array(string=>mixed) $options Options for this class
82. */
83. public function __construct ( array $options = array() )
84. {
85. $this->validity = 0; // seconds
86. $this->keysFile = 'http://www.typekey.com/extras/regkeys.txt';
87. $this->requestSource = ( $_GET !== null ) ? $_GET : array();
89. parent:: __construct ( $options );
90. }
92. /**
93. * Sets the option $name to $value.
94. *
95. * @throws ezcBasePropertyNotFoundException
96. * if the property $name is not defined
97. * @throws ezcBaseValueException
98. * if $value is not correct for the property $name
99. * @throws ezcBaseFileNotFoundException
100. * if the $value file does not exist
101. * @throws ezcBaseFilePermissionException
102. * if the $value file cannot be opened for reading
103. * @param string $name The name of the property to set
104. * @param mixed $value The new value of the property
105. * @ignore
106. */
107. public function __set( $name, $value )
108. {
109. switch ( $name )
110. {
111. case 'validity':
112. if ( ! is_numeric ( $value ) || ( $value < 0 ) )
113. {
114. throw new ezcBaseValueException ( $name, $value, 'int >= 0' );
115. }
116. $this-> properties [$name] = $value;
117. break;
119. case 'keysFile':
120. if ( ! is_string ( $value ) )
121. {
122. throw new ezcBaseValueException ( $name, $value, 'string' );
123. }
125. if ( strpos ( $value, '://' ) === false )
126. {
127. // if $value is not an URL
128. if ( ! file_exists ( $value ) )
129. {
130. throw new ezcBaseFileNotFoundException ( $value );
131. }
133. if ( ! is_readable ( $value ) )
134. {
135. throw new ezcBaseFilePermissionException ( $value, ezcBaseFileException ::READ );
136. }
137. }
138. else
139. {
140. // if $value is an URL
142. // hide the notices caused by getaddrinfo (php_network_getaddresses)
143. // in case of unreachable hosts ("Name or service not known")
144. $headers = @ get_headers ( $value );
145. if ( $headers === false
146. || count ( $headers ) === 0 // get_headers returns an empty array for unreachable hosts
147. || strpos ( $headers[0], '404 Not Found' ) !== false
148. )
149. {
150. throw new ezcBaseFileNotFoundException ( $value );
151. }
152. }
153. $this-> properties [$name] = $value;
154. break;
156. case 'requestSource':
157. if ( ! is_array ( $value ) )
158. {
159. throw new ezcBaseValueException ( $name, $value, 'array' );
160. }
161. $this-> properties [$name] = $value;
162. break;
164. default:
165. parent::__set( $name, $value );
166. }
167. }
168. }
169. ?>

Documentation generated by phpDocumentor 1.4.3