Apache Zeta Components Manual :: File Source for output_format.php

Source for file output_format.php

Documentation is available at output_format.php

  1. <?php
  2. /**
  3.  * File containing the ezcConsoleOutputFormat 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.  */
  27.  
  28. /**
  29.  * Struct class to store formating entities used by ezcConsoleOutput.
  30.  *
  31.  * Struct class to store formating entities used by ezcConsoleOutput.
  32.  *
  33.  * Possible values of {@link ezcConsoleOutputFormat::$color} are:
  34.  * - gray
  35.  * - red
  36.  * - green
  37.  * - yellow
  38.  * - blue
  39.  * - magenta
  40.  * - cyan
  41.  * - white
  42.  * - default (representing the consoles default color)
  43.  *
  44.  * For {@link ezcConsoleOutputFormat::$bgcolor} the following values are valid:
  45.  * - black
  46.  * - red
  47.  * - green
  48.  * - yellow
  49.  * - blue
  50.  * - magenta
  51.  * - cyan
  52.  * - white
  53.  * - default (representing the consoles default background color)
  54.  *
  55.  * The {@link ezcConsoleOutputFormat::$style} attribute takes an array of
  56.  * (possibly) multiple attributes. Choose from the lists below:
  57.  *
  58.  * - default (resets all attributes to default)
  59.  *
  60.  * - bold
  61.  * - faint
  62.  * - normal
  63.  *
  64.  * - italic
  65.  * - notitalic
  66.  *
  67.  * - underlined
  68.  * - doubleunderlined
  69.  * - notunderlined
  70.  *
  71.  * - blink
  72.  * - blinkfast
  73.  * - noblink
  74.  *
  75.  * - negative
  76.  * - positive
  77.  *
  78.  * @property string $color 
  79.  *            Contains the color for this format.
  80.  * @property array(string) $style 
  81.  *            Contains the lists of styles that are associated with
  82.  *            this format.
  83.  * @property string $bgcolor 
  84.  *            Contains the background color for this format.
  85.  * @property string $target 
  86.  *            Contains the output target to use. Pick one of
  87.  *            ezcConsoleOutput::TARGET_OUTPUT, ezcConsoleOutput::TARGET_STDOUT
  88.  *            or ezcConsoleOutput::TARGET_STDERR.
  89.  *
  90.  * @package ConsoleTools
  91.  * @version //autogen//
  92.  */
  93. {
  94.     /**
  95.      * Container to hold the properties
  96.      *
  97.      * @var array(string=>mixed) 
  98.      */
  99.     protected $properties = array
  100.         'color'     => 'default',
  101.         'style'     => array'default' ),
  102.         'bgcolor'   => 'default',
  103.         'target'    => ezcConsoleOutput::TARGET_OUTPUT,
  104.     );
  105.  
  106.     /**
  107.      * Create a new ezcConsoleOutputFormat object.
  108.      * Creates a new object of this class.
  109.      * 
  110.      * @param string $color             Name of a color value.
  111.      * @param array(string) $style Names of style values.
  112.      * @param string $bgcolor           Name of a bgcolor value.
  113.      * @param string $target            Target output stream.
  114.      */
  115.     public function __construct$color 'default'array $style null$bgcolor 'default'$target ezcConsoleOutput::TARGET_OUTPUT )
  116.     {
  117.         $this->__set'color'$color );
  118.         $this->__set'style'isset$style $style array'default' ) );
  119.         $this->__set'bgcolor'$bgcolor );
  120.         $this->__set'target'$target );
  121.     }
  122.     
  123.     /**
  124.      * Overloaded __get() method to gain read-only access to some attributes.
  125.      * 
  126.      * @param string $propertyName Name of the property to read.
  127.      * @return mixed Desired value if exists, otherwise null.
  128.      * @ignore
  129.      */
  130.     public function __get$propertyName )
  131.     {
  132.         switch $propertyName )
  133.         {
  134.             case 'style':
  135.                 return (array) $this->properties[$propertyName];
  136.             case 'color':
  137.             case 'bgcolor':
  138.             case 'target':
  139.                 return $this->properties[$propertyName];
  140.             default:
  141.                 throw new ezcBasePropertyNotFoundException$propertyName );
  142.         }
  143.     }
  144.  
  145.     /**
  146.      * Overloaded __set() method to gain read-only access to properties.
  147.      * It also performs checks on setting others.
  148.      *
  149.      * @throws ezcBasePropertyNotFoundException
  150.      *          If the setting you try to access does not exists
  151.      * @throws ezcBaseValueException
  152.      *          If trying to set an invalid value for a setting.
  153.      * 
  154.      * @param string $propertyName Name of the attrinbute to access.
  155.      * @param string $val The value to set.
  156.      * @ignore
  157.      */
  158.     public function __set$propertyName$val )
  159.     {
  160.         if !isset$this->properties[$propertyName) )
  161.         {
  162.             throw new ezcBasePropertyNotFoundException$propertyName );
  163.         }
  164.         // Extry handling of multi styles
  165.         if $propertyName === 'style' )
  166.         {
  167.             if !is_array$val ) ) $val array$val );
  168.             foreach $val as $style )
  169.             {
  170.                 if !ezcConsoleOutput::isValidFormatCode$propertyName$style ) )
  171.                 {
  172.                     throw new ezcBaseValueException$propertyName$style'valid ezcConsoleOutput format code' );
  173.                 }
  174.             }
  175.             $this->properties['style'$val;
  176.             return;
  177.         }
  178.         // Continue normal handling
  179.         if ( ( $propertyName === "color" || $propertyName === "bgcolor" )
  180.              && !ezcConsoleOutput::isValidFormatCode$propertyName$val ) )
  181.         {
  182.             throw new ezcBaseValueException$propertyName$val'valid ezcConsoleOutput format code' );
  183.         }
  184.         $this->properties[$propertyName$val;
  185.     }
  186.  
  187.     /**
  188.      * Property isset access.
  189.      * 
  190.      * @param string $propertyName Name of the property.
  191.      * @return bool True is the property is set, otherwise false.
  192.      * @ignore
  193.      */
  194.     public function __isset$propertyName )
  195.     {
  196.         return isset$this->properties[$propertyName);
  197.     }
  198.     
  199. }
  200.  
  201. ?>
Documentation generated by phpDocumentor 1.4.3