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

Source for file argument.php

Documentation is available at argument.php

  1. <?php
  2. /**
  3.  * File containing the ezcConsoleArgument 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.  * The ezcConsoleArgument class represents an argument on the console.
  30.  * This class is the container to store information about an argument submitted
  31.  * to a shell application. It is used to define the appearance of an argument
  32.  * before parsing the parameter string and contains the received value
  33.  * afterwards. Argument objects are stored in an instance of the set class
  34.  * {@link ezcConsoleArguments} which is stored in
  35.  * {ezcConsoleInput::$argumentDefinition}.
  36.  * 
  37.  * @property string $name      The name for the argument. Must be unique.
  38.  * @property int $type         The value type.
  39.  * @property string $shorthelp A short help text.
  40.  * @property string $longhelp  A long help text-
  41.  * @property bool $mandatory   Whether the argument is mandatory.
  42.  * @property mixed $default    A default value, if not mandatory.
  43.  * @property bool $multiple    Whether the argument accepts multiple values.
  44.  * @property-read mixed $value The value parsed from the parameter string, using
  45.  *                              {@link ezcConsoleInput::process()}.
  46.  * @package ConsoleTools
  47.  * @version //autogen//
  48.  */
  49. {
  50.     /**
  51.      * Properties
  52.      * 
  53.      * @var array 
  54.      */
  55.     protected $properties = array(
  56.         "name"      => null,
  57.         "type"      => ezcConsoleInput::TYPE_STRING,
  58.         "shorthelp" => "No help available.",
  59.         "longhelp"  => "There is no help for this argument available.",
  60.         "mandatory" => true,
  61.         "multiple"  => false,
  62.         "default"   => null,
  63.         "value"     => null,
  64.     );
  65.  
  66.     /**
  67.      * Creates a new console argument object.
  68.      * Creates a new console argument object, which represents a single
  69.      * argument on the shell. Arguments are stored insiede
  70.      * {@link ezcConsoleArguments} which is used with {@link ezcConsoleInput}.
  71.      *
  72.      * For the type property see {@link ezcConsoleInput::TYPE_STRING} and
  73.      * {@link ezcConsoleInput::TYPE_INT}. If 1 argument is defined as optional
  74.      * ($mandatory = false), all following arguments are autolamtically
  75.      * considered optional, too.
  76.      * 
  77.      * @param string $name      The name for the argument. Must be unique.
  78.      * @param int $type         The value type.
  79.      * @param string $shorthelp A short help text.
  80.      * @param string $longhelp  A long help text-
  81.      * @param bool $mandatory   Whether the argument is mandatory.
  82.      * @param bool $multiple    Whether the argument accepts multiple values.
  83.      * @param mixed $default    A default value, if not mandatory.
  84.      * @return void 
  85.      */
  86.     public function __construct(
  87.         $name      null,
  88.         $type      ezcConsoleInput::TYPE_STRING,
  89.         $shorthelp "No help available.",
  90.         $longhelp  "There is no help for this argument available.",
  91.         $mandatory true,
  92.         $multiple  false,
  93.         $default   null
  94.     )
  95.     {
  96.         if !is_string$name || strlen$name )
  97.         {
  98.             throw new ezcBaseValueException"name"$name"string, length > 0" );
  99.         }
  100.         $this->properties["name"$name;
  101.  
  102.         $this->type               $type;
  103.         $this->shorthelp          $shorthelp;
  104.         $this->longhelp           $longhelp;
  105.         $this->mandatory          $mandatory;
  106.         $this->multiple           $multiple;
  107.         $this->default            $default;
  108.     }
  109.  
  110.     /**
  111.      * Property set access.
  112.      * 
  113.      * @param string $propertyName  Name of the property.
  114.      * @param string $propertyValue Valze for the property.
  115.      * @return void 
  116.      * @ignore
  117.      */
  118.     public function __set$propertyName$propertyValue )
  119.     {
  120.         switch $propertyName )
  121.         {
  122.             case "name":
  123.                 throw new ezcBasePropertyPermissionException$propertyNameezcBasePropertyPermissionException::READ );
  124.                 break;
  125.             case "type":
  126.                 if $propertyValue !== ezcConsoleInput::TYPE_INT && $propertyValue !== ezcConsoleInput::TYPE_STRING )
  127.                 {
  128.                     throw new ezcBaseValueException$propertyName$propertyValue"string, length > 0" );
  129.                 }
  130.                 break;
  131.             case "shorthelp":
  132.             case "longhelp":
  133.                 if is_string$propertyValue === false )
  134.                 {
  135.                     throw new ezcBaseValueException$propertyName$propertyValue"string" );
  136.                 }
  137.                 break;
  138.             case "mandatory":
  139.             case "multiple":
  140.                 if is_bool$propertyValue === false )
  141.                 {
  142.                     throw new ezcBaseValueException$propertyName$propertyValue"bool" );
  143.                 }
  144.                 break;
  145.             case "default":
  146.                 if is_scalar$propertyValue === false && is_array$propertyValue === false && $propertyValue !== null )
  147.                 {
  148.                     throw new ezcBaseValueException$propertyName$propertyValue"array, scalar or null" );
  149.                 }
  150.                 break;
  151.             case "value":
  152.                 if is_scalar$propertyValue === false && is_array$propertyValue === false && $propertyValue !== null )
  153.                 {
  154.                     throw new ezcBaseValueException$propertyName$propertyValue"string or null" );
  155.                 }
  156.                 break;
  157.             default:
  158.                 throw new ezcBasePropertyNotFoundException$propertyName );
  159.         }
  160.         $this->properties[$propertyName$propertyValue;
  161.     }
  162.  
  163.     /**
  164.      * Property read access.
  165.      *
  166.      * @throws ezcBasePropertyNotFoundException
  167.      *          If the the desired property is not found.
  168.      * 
  169.      * @param string $propertyName Name of the property.
  170.      * @return mixed Value of the property or null.
  171.      * @ignore
  172.      */
  173.     public function __get$propertyName )
  174.     {
  175.         if isset$this->$propertyName ) )
  176.         {
  177.             return $this->properties[$propertyName];
  178.         }
  179.         throw new ezcBasePropertyNotFoundException$propertyName );
  180.     }
  181.  
  182.     /**
  183.      * Property isset access.
  184.      * 
  185.      * @param string $propertyName Name of the property.
  186.      * @return bool True is the property is set, otherwise false.
  187.      * @ignore
  188.      */
  189.     public function __isset$propertyName )
  190.     {
  191.         return array_key_exists$propertyName$this->properties );
  192.     }
  193. }
  194.  
  195. ?>
Documentation generated by phpDocumentor 1.4.3