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

Source for file standard.php

Documentation is available at standard.php

  1. <?php
  2. /**
  3.  * File containing the ezcConsoleStandardInputValidator 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.  * Validates ezcConsoleOption in terms of dependencies/exclusion and more.
  29.  * 
  30.  * @package ConsoleTools
  31.  * @version //autogen//
  32.  *
  33.  * @access private
  34.  */
  35. class ezcConsoleStandardInputValidator implements ezcConsoleInputValidator
  36. {
  37.     /**
  38.      * Validates the given $options and $arguments.
  39.      *
  40.      * Validates the given $options against their registered rules. Throws an
  41.      * exception, if any condition is not met. $hasArguments indicates if
  42.      * arguments have been submitted in addition.
  43.      *
  44.      * @param array(ezcConsoleOption) $options 
  45.      * @param bool $hasArguments 
  46.      *
  47.      * @throws ezcConsoleOptionDependencyViolationException
  48.      *          If a dependency was violated.
  49.      * @throws ezcConsoleOptionExclusionViolationException
  50.      *          If an exclusion rule was violated.
  51.      * @throws ezcConsoleOptionArgumentsViolationException
  52.      *          If arguments are passed although a parameter dissallowed them.
  53.      * @throws ezcConsoleOptionMandatoryViolationException
  54.      *          If an option that was marked mandatory was not submitted.
  55.      * @throws ezcConsoleOptionMissingValueException
  56.      *          If an option that expects a value was submitted without one.
  57.      */
  58.     public function validateOptionsarray $options$hasArguments )
  59.     {
  60.         foreach $options as $id => $option )
  61.         {
  62.             if $option->mandatory === true && $option->value === false )
  63.             {
  64.                 throw new ezcConsoleOptionMandatoryViolationException$option );
  65.             }
  66.  
  67.             $this->validateDependencies$option );
  68.             $this->validateExclusions$option );
  69.  
  70.             if $option->arguments === false && $option->value !== false && $hasArguments )
  71.             {
  72.                 throw new ezcConsoleOptionArgumentsViolationException$option );
  73.             }
  74.         }
  75.     }
  76.  
  77.     /**
  78.      * Validated option dependencies.
  79.      *
  80.      * Validates dependencies by $option.
  81.      *
  82.      * @param ezcConsoleOption $option. 
  83.      */
  84.     private function validateDependenciesezcConsoleOption $option )
  85.     {
  86.         $optSet $option->value !== false
  87.             && !is_array$option->value || $option->value !== array() ) );
  88.  
  89.         foreach $option->getDependencies(as $dep )
  90.         {
  91.             if $dep->ifSet === $optSet )
  92.             {
  93.                 $this->validateDependency$option$dep );
  94.             }
  95.         }
  96.     }
  97.  
  98.     /**
  99.      * Validates a single dependency.
  100.      *
  101.      * Validates the dependency $dep, which is set in the $srcOpt.
  102.      *
  103.      * @param ezcConsoleOption $srcOpt 
  104.      * @param ezcConsoleOptionRule $dep 
  105.      */
  106.     private function validateDependencyezcConsoleOption $srcOptezcConsoleOptionRule $dep )
  107.     {
  108.         $optValue $dep->option->value;
  109.  
  110.         if $optValue === false || $optValue === array() )
  111.         {
  112.             throw new ezcConsoleOptionDependencyViolationException(
  113.                 $srcOpt,
  114.                 $dep->option
  115.             );
  116.         }
  117.  
  118.         if $dep->values !== array() )
  119.         {
  120.             $optVals is_array$optValue $optValue array$optValue) );
  121.             $unrecognizedVals array_diff$optVals$dep->values );
  122.             if $unrecognizedVals !== array() )
  123.             {
  124.                 throw new ezcConsoleOptionDependencyViolationException(
  125.                     $srcOpt,
  126.                     $dep->option,
  127.                     implode', '$dep->values )
  128.                 );
  129.             }
  130.         }
  131.     }
  132.  
  133.     /**
  134.      * Validated option exclusions.
  135.      *
  136.      * Validates exclusions by $option.
  137.      *
  138.      * @param ezcConsoleOption $option. 
  139.      */
  140.     private function validateExclusionsezcConsoleOption $option )
  141.     {
  142.         $optSet $option->value !== false
  143.             && !is_array$option->value || $option->value !== array() ) );
  144.  
  145.         foreach $option->getExclusions(as $excl )
  146.         {
  147.             if $excl->ifSet === $optSet )
  148.             {
  149.                 $this->validateExclusion$option$excl );
  150.             }
  151.         }
  152.     }
  153.  
  154.     /**
  155.      * Validates a single exclusion.
  156.      *
  157.      * Validates the exclusion $excl, which is set in the $srcOpt.
  158.      *
  159.      * @param ezcConsoleOption $srcOpt 
  160.      * @param ezcConsoleOptionRule $excl 
  161.      */
  162.     private function validateExclusionezcConsoleOption $srcOptezcConsoleOptionRule $excl )
  163.     {
  164.         $optValue $excl->option->value;
  165.  
  166.         if $optValue !== false && $optValue !== array(&& $excl->values === array() )
  167.         {
  168.             throw new ezcConsoleOptionExclusionViolationException(
  169.                 $srcOpt,
  170.                 $excl->option
  171.             );
  172.         }
  173.  
  174.         $optVals is_array$optValue $optValue array$optValue ) );
  175.         $forbiddenVals array_intersect$optVals$excl->values );
  176.         if $forbiddenVals !== array() )
  177.         {
  178.             throw new ezcConsoleOptionExclusionViolationException(
  179.                 $srcOpt,
  180.                 $excl->option,
  181.                 implode', '$excl->values )
  182.             );
  183.         }
  184.     }
  185. }
  186.  
  187. ?>
Documentation generated by phpDocumentor 1.4.3