Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/*
3
 * This file is part of the symfony package.
4
 * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
 
10
/*
11
 *  $Id: Formatter.php 2702 2007-10-03 21:43:22Z Jonathan.Wage $
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
14
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
15
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
16
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
17
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
 *
25
 * This software consists of voluntary contributions made by many individuals
26
 * and is licensed under the LGPL. For more information, see
27
 * <http://www.doctrine-project.org>.
28
 */
29
 
30
/**
31
 * Doctrine_Cli_Formatter provides methods to format text to be displayed on a console.
32
 * This class was taken from the symfony-project source
33
 *
34
 * @package     Doctrine
35
 * @subpackage  Cli
36
 * @author      Fabien Potencier <fabien.potencier@symfony-project.com>
37
 * @author      Jonathan H. Wage <jonwage@gmail.com>
38
 * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
39
 * @link        www.doctrine-project.org
40
 * @since       1.0
41
 * @version     $Revision: 2761 $
42
 */
43
class Doctrine_Cli_Formatter
44
{
45
    protected $_size = 65;
46
 
47
    /**
48
     * __construct
49
     *
50
     * @param string $maxLineSize
51
     * @return void
52
     */
53
    function __construct($maxLineSize = 65)
54
    {
55
        $this->_size = $maxLineSize;
56
    }
57
 
58
    /**
59
     * Formats a text according to the given parameters.
60
     *
61
     * @param  string The test to style
62
     * @param  mixed  An array of parameters
63
     * @param  stream A stream (default to STDOUT)
64
     *
65
     * @return string The formatted text
66
     */
67
    public function format($text = '', $parameters = array(), $stream = STDOUT)
68
    {
69
        return $text;
70
    }
71
 
72
    /**
73
     * Formats a message within a section.
74
     *
75
     * @param string  The section name
76
     * @param string  The text message
77
     * @param integer The maximum size allowed for a line (65 by default)
78
     */
79
    public function formatSection($section, $text, $size = null)
80
    {
81
        return sprintf(">> %-$9s %s", $section, $this->excerpt($text, $size));
82
    }
83
 
84
    /**
85
     * Truncates a line.
86
     *
87
     * @param string  The text
88
     * @param integer The maximum size of the returned string (65 by default)
89
     *
90
     * @return string The truncated string
91
     */
92
    public function excerpt($text, $size = null)
93
    {
94
        if ( ! $size) {
95
            $size = $this->_size;
96
        }
97
 
98
        if (strlen($text) < $size) {
99
            return $text;
100
        }
101
 
102
        $subsize = floor(($size - 3) / 2);
103
 
104
        return substr($text, 0, $subsize).'...'.substr($text, -$subsize);
105
    }
106
 
107
    /**
108
     * Sets the maximum line size.
109
     *
110
     * @param integer The maximum line size for a message
111
     */
112
    public function setMaxLineSize($size)
113
    {
114
        $this->_size = $size;
115
    }
116
}