Development

/branches/1.2/lib/command/sfFormatter.class.php

You must first sign up to be able to contribute.

root/branches/1.2/lib/command/sfFormatter.class.php

Revision 17858, 2.0 kB (checked in by FabianLange, 5 years ago)

[1.1, 1.2, 1.3] fixed some codeing standards (fixes #6376 - patch from gimler)

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1 <?php
2
3 /*
4  * This file is part of the symfony package.
5  * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 /**
12  * sfFormatter provides methods to format text to be displayed on a console.
13  *
14  * @package    symfony
15  * @subpackage command
16  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
17  * @version    SVN: $Id$
18  */
19 class sfFormatter
20 {
21   protected
22     $size = 65;
23
24   function __construct($maxLineSize = 65)
25   {
26     $this->size = $maxLineSize;
27   }
28
29   /**
30    * Formats a text according to the given parameters.
31    *
32    * @param string $text       The test to style
33    * @param mixed  $parameters An array of parameters
34    * @param stream $stream     A stream (default to STDOUT)
35    *
36    * @return string The formatted text
37    */
38   public function format($text = '', $parameters = array(), $stream = STDOUT)
39   {
40     return $text;
41   }
42
43   /**
44    * Formats a message within a section.
45    *
46    * @param string  $section The section name
47    * @param string  $text    The text message
48    * @param integer $size    The maximum size allowed for a line (65 by default)
49    */
50   public function formatSection($section, $text, $size = null)
51   {
52     return sprintf(">> %-9s %s", $section, $this->excerpt($text, $size));
53   }
54
55   /**
56    * Truncates a line.
57    *
58    * @param string  $text The text
59    * @param integer $size The maximum size of the returned string (65 by default)
60    *
61    * @return string The truncated string
62    */
63   public function excerpt($text, $size = null)
64   {
65     if (!$size)
66     {
67       $size = $this->size;
68     }
69
70     if (strlen($text) < $size)
71     {
72       return $text;
73     }
74
75     $subsize = floor(($size - 3) / 2);
76
77     return substr($text, 0, $subsize).'...'.substr($text, -$subsize);
78   }
79
80   /**
81    * Sets the maximum line size.
82    *
83    * @param integer $size The maximum line size for a message
84    */
85   public function setMaxLineSize($size)
86   {
87     $this->size = $size;
88   }
89 }
90
Note: See TracBrowser for help on using the browser.