Overview

Namespaces

  • None
  • Peg
    • Cli
      • Commands
    • Config
    • Custom
      • Command
        • Action
          • Generate
          • Parse
      • CommandLine
      • Config
      • Localization
      • Utilities
    • Lib
      • Definitions
        • Element
      • Generator
      • Lexers
      • Plugins
      • Signals
        • Data
          • Definitions
          • Lexers
        • Type
  • PHP

Classes

  • ClassElement
  • ClassVariable
  • Constant
  • Enumeration
  • FunctionElement
  • GlobalVariable
  • Header
  • NamespaceElement
  • Overload
  • Parameter
  • ReturnType
  • TypeComponents
  • TypeDef
  • VariableType
  • Overview
  • Namespace
  • Class
  • Tree
  • Todo
  1: <?php
  2: /**
  3:  * @author Jefferson González
  4:  * @license MIT
  5:  * @link http://github.com/peg-org/peg-src Source code.
  6:  */
  7: 
  8: namespace Peg\Lib\Definitions\Element;
  9: 
 10: /**
 11:  * Represents a function or class method overload element.
 12:  */
 13: class Overload
 14: {
 15: 
 16:     /**
 17:      * Description of the element.
 18:      * @var string
 19:      */
 20:     public $description;
 21:     
 22:     /**
 23:      * List of platforms where the element is supported.
 24:      * @var array 
 25:      */
 26:     public $platforms;
 27:     
 28:     /**
 29:      * The return type of the overload.
 30:      * @var \Peg\Lib\Definitions\Element\ReturnType
 31:      */
 32:     public $return_type;
 33:     
 34:     /**
 35:      * Holds the list of parameters for the overload.
 36:      * @var \Peg\Lib\Definitions\Element\Parameter[]
 37:      */
 38:     public $parameters;
 39:     
 40:     /**
 41:      * Flag that indicate if the method is protected.
 42:      * @var bool
 43:      */
 44:     public $protected;
 45:     
 46:     /**
 47:      * Flag that indicate if the method is const.
 48:      * @var bool
 49:      */
 50:     public $constant;
 51:     
 52:     /**
 53:      * Flag that indicate if the method is static.
 54:      * @var bool
 55:      */
 56:     public $static;
 57:     
 58:     /**
 59:      * Flag that indicate if the method is virtual.
 60:      * @var bool
 61:      */
 62:     public $virtual;
 63:     
 64:     /**
 65:      * Flag that indicate if the method is pure virtual.
 66:      * @var bool
 67:      */
 68:     public $pure_virtual;
 69:     
 70:     /**
 71:      * Flag that indicate if the method/function is deprecated.
 72:      * @var bool
 73:      */
 74:     public $deprecated;
 75:     
 76:     /**
 77:      * Reference to the parent function element.
 78:      * @var \Peg\Lib\Definitions\Element\FunctionElement
 79:      */
 80:     public $function;
 81:     
 82:     /**
 83:      * Create a function or method overload.
 84:      * @param string $description
 85:      */
 86:     public function __construct($description="")
 87:     {
 88:         $this->description = $description;
 89:         
 90:         $this->parameters = array();
 91:         $this->platforms = array();
 92:     }
 93:     
 94:     /**
 95:      * Helper function to set the overload return type.
 96:      * @param \Peg\Lib\Definitions\Element\ReturnType $return_type
 97:      * @return \Peg\Lib\Definitions\Element\Overload
 98:      */
 99:     public function SetReturnType(\Peg\Lib\Definitions\Element\ReturnType $return_type)
100:     {
101:         $return_type->overload =& $this;
102:         
103:         $this->return_type = $return_type;
104:         
105:         return $this;
106:     }
107:     
108:     /**
109:      * Adds a new parameter.
110:      * @param \Peg\Lib\Definitions\Element\Parameter $parameter
111:      * @return \Peg\Lib\Definitions\Element\Overload
112:      */
113:     public function AddParameter(\Peg\Lib\Definitions\Element\Parameter $parameter)
114:     {
115:         $parameter->overload =& $this;
116:         
117:         if(!isset($this->parameters[$parameter->name]))
118:         {
119:             $this->parameters[$parameter->name] = $parameter;
120:         }
121:         else
122:         {
123:             /*throw new \Exception(
124:                 sprintf(
125:                     t("You are trying to add a parameter which is already listed: %s"),
126:                     $parameter->name
127:                 )
128:             );*/
129:         }
130:         
131:         return $this;
132:     }
133:     
134:     /**
135:      * Check if the overload has parameters.
136:      * @return bool
137:      */
138:     public function HasParameters()
139:     {
140:         return count($this->parameters) > 0 ? true : false;
141:     }
142:     
143:     public function GetParametersCount()
144:     {
145:         return count($this->parameters);
146:     }
147:     
148:     public function GetRequiredParametersCount()
149:     {
150:         $required = 0;
151:         
152:         foreach($this->parameters as $parameter)
153:         {
154:             if(!$parameter->default_value)
155:                 $required++;
156:         }
157:         
158:         return $required;
159:     }
160: 
161: }
162: 
PEG Api API documentation generated by ApiGen 2.8.0