1<?php
2/**
3 * File containing the ezcConsoleProgressbarOptions class.
4 *
5 * @package ConsoleTools
6 * @version 1.6.1
7 * @copyright Copyright (C) 2005-2010 eZ Systems AS. All rights reserved.
8 * @license http://ez.no/licenses/new_bsd New BSD License
9 * @filesource
10 */
11
12/**
13 * Struct class to store the options of the ezcConsoleOutput class.
14 * This class stores the options for the {@link ezcConsoleOutput} class.
15 *
16 * @property string $barChar
17 *           The character to fill the bar with, during progress indication.
18 * @property string $emptyChar
19 *           The character to pre-fill the bar, before indicating progress.
20 * @property string $formatString
21 *           The format string to describe the complete progressbar.
22 * @property string $fractionFormat
23 *           Format to display the fraction value.
24 * @property string $processChar
25 *           The character for the end of the progress area (the arrow!).
26 * @property int $redrawFrequency
27 *           How often to redraw the progressbar (on every Xth call to advance()).
28 * @property int $step
29 *           How many steps to advance the progressbar on each call to advance().
30 * @property int $width
31 *           The width of the bar itself.
32 * @property string $actFormat
33 *           The format to display the actual value with.
34 * @property string $maxFormat
35 *           The format to display the actual value with.
36 * @property int $minVerbosity
37 *           Defines the minimum {ezcConsoleOutputOptions->$verbosityLevel}
38 *           that is needed by the progress bar to be rendered. If
39 *           $verbosityLevel is lower, the bar is skipped. Default is 0 to
40 *           render always.
41 * @property int $maxVerbosity
42 *           Defines the maximum {ezcConsoleOutputOptions->$verbosityLevel} on
43 *           which the progress bar is rendered. If $verbosityLevel is higher,
44 *           the bar is skipped. Default is false, to render always.
45 *
46 * @package ConsoleTools
47 * @version 1.6.1
48 */
49class ezcConsoleProgressbarOptions extends ezcBaseOptions
50{
51
52    protected $properties = array(
53        'barChar'         => "+",
54        'emptyChar'       => "-",
55        'formatString'    => "%act% / %max% [%bar%] %fraction%%",
56        'fractionFormat'  => "%01.2f",
57        'progressChar'    => ">",
58        'redrawFrequency' => 1,
59        'step'            => 1,
60        'width'           => 78,
61        'actFormat'       => '%.0f',
62        'maxFormat'       => '%.0f',
63        'minVerbosity'    => 1,
64        'maxVerbosity'    => false,
65    );
66
67    /**
68     * Option write access.
69     *
70     * @throws ezcBasePropertyNotFoundException
71     *         If a desired property could not be found.
72     * @throws ezcBaseValueException
73     *         If a desired property value is out of range.
74     *
75     * @param string $key Name of the property.
76     * @param mixed $value  The value for the property.
77     * @ignore
78     */
79    public function __set( $key, $value )
80    {
81        switch ( $key )
82        {
83            case "barChar":
84            case "emptyChar":
85            case "progressChar":
86            case "formatString":
87            case "fractionFormat":
88            case "actFormat":
89            case "maxFormat":
90                if ( is_string( $value ) === false || strlen( $value ) < 1 )
91                {
92                    throw new ezcBaseValueException( $key, $value, 'string, not empty' );
93                }
94                break;
95            case "width":
96                if ( !is_int( $value ) || $value < 5 )
97                {
98                    throw new ezcBaseValueException( $key, $value, 'int >= 5' );
99                }
100                break;
101            case "redrawFrequency":
102            case "step":
103                if ( ( !is_int( $value ) && !is_float( $value ) ) || $value < 1 )
104                {
105                    throw new ezcBaseValueException( $key, $value, 'int > 0' );
106                }
107                break;
108            case 'minVerbosity':
109                if ( !is_int( $value ) || $value < 0 )
110                {
111                    throw new ezcBaseValueException( $key, $value, 'int >= 0' );
112                }
113                break;
114            case 'maxVerbosity':
115                if ( ( !is_int( $value ) || $value < 0 ) && $value !== false )
116                {
117                    throw new ezcBaseValueException( $key, $value, 'int >= 0 or false' );
118                }
119                break;
120            default:
121                throw new ezcBasePropertyNotFoundException( $key );
122        }
123        $this->properties[$key] = $value;
124    }
125}
126
127?>
128