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

Source for file option_rule.php

Documentation is available at option_rule.php

  1. <?php
  2. /**
  3.  * File containing the ezcConsoleOptionRule 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 a parameter rule.
  30.  *
  31.  * This struct stores relation rules between parameters. A relation consists of
  32.  * a parameter that the relation refers to and optionally the value(s) the
  33.  * referred parameter may have assigned. Rules may be used for dependencies and
  34.  * exclusions between parameters.
  35.  *
  36.  * The ezcConsoleOptionRule class has the following properties:
  37.  * - <b>option</b> <i>ezcConsoleOption</i>, contains the parameter that this rule refers to.
  38.  * - <b>values</b> <i>array(string)</i>, contains a list of values that are accepted.
  39.  *
  40.  * @see ezcConsoleOption
  41.  * 
  42.  * @package ConsoleTools
  43.  * @version //autogen//
  44.  */
  45. {
  46.     /**
  47.      * Properties.
  48.      *
  49.      * @var array 
  50.      */
  51.     protected $properties = array
  52.         'option' => null,
  53.         'values' => array(),
  54.         'ifSet'  => true
  55.     );
  56.  
  57.     /**
  58.      * Creates a new option rule.
  59.      *
  60.      * Creates a new option rule. Per default the $values parameter
  61.      * is an empty array, which determines that the option may accept any
  62.      * value. To indicate that a option may only have certain values,
  63.      * place them inside tha $values array. For example to indicate an option
  64.      * may have the values 'a', 'b' and 'c' use:
  65.      *
  66.      * <code>
  67.      * $rule = new ezcConsoleOptionRule( $option, array( 'a', 'b', 'c' ) );
  68.      * </code>
  69.      *
  70.      * If you want to allow only 1 specific value for an option, you do not
  71.      * need to wrap this into an array, when creating the rule. Simply use
  72.      *
  73.      * <code>
  74.      * $rule = new ezcConsoleOptionRule( $option, 'a' );
  75.      * </code>
  76.      *
  77.      * to create a rule, that allows the desired option only to accept the
  78.      * value 'a'.
  79.      *
  80.      * The $ifSet parameter determines, if the rule is validated when its option
  81.      * is set or left out. If $ifSet is true, the rule is validated when the
  82.      * option is set. Otherwise the rule is validated if the option was not set
  83.      * by the user.
  84.      *
  85.      * @param ezcConsoleOption $option The option to refer to.
  86.      * @param mixed $values            The affected values.
  87.      * @param bool $ifSet 
  88.      */
  89.     public function __constructezcConsoleOption $optionarray $values array()$ifSet true )
  90.     {
  91.         $this->__set'option'$option );
  92.         $this->__set'values'$values );
  93.         $this->__set'ifSet'$ifSet );
  94.     }
  95.     
  96.     /**
  97.      * Property read access.
  98.      *
  99.      * @throws ezcBasePropertyNotFoundException
  100.      *          If the the desired property is not found.
  101.      * 
  102.      * @param string $propertyName Name of the property.
  103.      * @return mixed Value of the property or null.
  104.      * @ignore
  105.      */
  106.     public function __get$propertyName 
  107.     {
  108.         switch $propertyName )
  109.         {
  110.             case 'option':
  111.                 return $this->properties['option'];
  112.             case 'values':
  113.                 return $this->properties['values'];
  114.             case 'ifSet':
  115.                 return $this->properties['ifSet'];
  116.         }
  117.         throw new ezcBasePropertyNotFoundException$propertyName );
  118.     }
  119.     
  120.     /**
  121.      * Property write access.
  122.      * 
  123.      * @param string $propertyName Name of the property.
  124.      * @param mixed $propertyValue The value for the property.
  125.      *
  126.      * @throws ezcBasePropertyPermissionException
  127.      *          If the property you try to access is read-only.
  128.      * @throws ezcBasePropertyNotFoundException
  129.      *          If the the desired property is not found.
  130.      * @ignore
  131.      */
  132.     public function __set$propertyName$propertyValue 
  133.     {
  134.         switch $propertyName )
  135.         {
  136.             case 'option':
  137.                 if !$propertyValue instanceof ezcConsoleOption ) )
  138.                 {
  139.                     throw new ezcBaseValueException$propertyName$propertyValue'ezcConsoleOption' );
  140.                 }
  141.                 $this->properties['option'$propertyValue;
  142.                 return;
  143.             case 'values':
  144.                 if !is_array$propertyValue ) )
  145.                 {
  146.                     throw new ezcBaseValueException$propertyName$propertyValue'array' );
  147.                 }
  148.                 $this->properties['values'$propertyValue;
  149.                 return;
  150.             case 'ifSet':
  151.                 if !is_bool$propertyValue ) )
  152.                 {
  153.                     throw new ezcBaseValueException$propertyName$propertyValue'bool' );
  154.                 }
  155.                 $this->properties['ifSet'$propertyValue;
  156.                 return;
  157.         }
  158.         throw new ezcBasePropertyNotFoundException$propertyName );
  159.     }
  160.  
  161.     /**
  162.      * Property isset access.
  163.      * 
  164.      * @param string $propertyName Name of the property to check.
  165.      * @return bool If the property exists or not.
  166.      * @ignore
  167.      */
  168.     public function __isset$propertyName )
  169.     {
  170.         switch $propertyName )
  171.         {
  172.             case 'option':
  173.             case 'values':
  174.             case 'ifSet':
  175.                 return true;
  176.         }
  177.         return false;
  178.     }
  179.  
  180. }
  181.  
  182. ?>
Documentation generated by phpDocumentor 1.4.3