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

## Source for file dialog_viewer.php

Documentation is available at dialog_viewer.php

1. <?php
2. /**
3. * File containing the ezcConsoleDialogViewer 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. * @package ConsoleTools
23. * @version //autogentag//
24. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
25. * @filesource
26. */
28. /**
29. * Utility class for ezcConsoleDialog implementations.
30. * This class contains utility methods for working with {@link }
31. * ezcConsoleDialog} implementations.
32. *
33. * To display a dialog in a loop until a valid result is received do:
34. * <code>
35. * // Instatiate dialog in $dialog ...
36. * ezcConsoleDialogViewer::displayDialog( $dialog );
37. * </code>
38. *
39. * For implementing a custom dialog, the method {@link readLine()} method can be
40. * used to read a line of input from the user.
41. *
42. * @package ConsoleTools
43. * @version //autogen//
44. */
45. class ezcConsoleDialogViewer
46. {
47. /**
48. * Displays a dialog and returns a valid result from it.
49. * This methods displays a dialog in a loop, until it received a valid
50. * result from it and returns this result.
51. *
52. * @param ezcConsoleDialog $dialog The dialog to display.
53. * @return mixed The result from this dialog.
54. */
55. public static function displayDialog ( ezcConsoleDialog $dialog )
56. {
57. do
58. {
59. $dialog->display();
60. }
61. while ( $dialog->hasValidResult() === false );
62. return $dialog->getResult();
63. }
65. /**
66. * Returns a line from STDIN.
67. * The returned line is fully trimmed.
68. *
69. * @return string
70. * @throws ezcConsoleDialogAbortException
71. * if the user closes STDIN using <CTRL>-D.
72. */
73. public static function readLine ()
74. {
75. $res = trim ( fgets ( STDIN ) );
76. if ( feof ( STDIN ) )
77. {
78. throw new ezcConsoleDialogAbortException ();
79. }
80. return $res;
81. }
82. }
84. ?>

Documentation generated by phpDocumentor 1.4.3