/**
  * Constructor
  * 
  * @param string $module your module-name
  * @param array $subs the sub-module names that are possible
  * @param string $default the default sub-module
  */
 public function __construct($module, $subs = array(), $default = 'default')
 {
     $input = FWS_Props::get()->input();
     if (count($subs) == 0) {
         FWS_Helper::error('Please provide the possible submodules of this module!');
     }
     $sub = $input->correct_var('sub', 'get', FWS_Input::STRING, $subs, $default);
     // include the sub-module and create it
     include_once FWS_Path::server_app() . 'module/' . $module . '/sub_' . $sub . '.php';
     $classname = 'PC_SubModule_' . $module . '_' . $sub;
     $this->sub = new $classname();
 }
 /**
  * Determines the type from the operation (assumes that the type or the value is unknown)
  * 
  * @param string $op the operator
  * @param PC_Obj_MultiType $t1 the type of the first operand
  * @param PC_Obj_MultiType $t2 the type of the second operand (may be null for unary ops)
  * @return PC_Obj_MultiType the variable
  */
 protected function get_type_from_op($op, $t1, $t2 = null)
 {
     switch ($op) {
         // bitwise operators have always int as result
         case '|':
         case '&':
         case '^':
         case '>>':
         case '<<':
         case '~':
         case '?:':
             return PC_Obj_MultiType::create_int();
             // concatenation leads always to string
         // concatenation leads always to string
         case '.':
             return PC_Obj_MultiType::create_string();
         case '+':
         case '-':
         case '*':
         case '/':
         case '%':
             // if one of them is unknown we don't know whether we would get a float or int
             if ($t1->is_unknown() || $t1->is_multiple() || $t2 !== null && ($t2->is_unknown() || $t2->is_multiple())) {
                 return new PC_Obj_MultiType();
             }
             $ti1 = $t1->get_first()->get_type();
             $ti2 = $t2 === null ? -1 : $t2->get_first()->get_type();
             // if both are arrays, the result is an array
             if ($ti1 == PC_Obj_Type::TARRAY && $ti2 == PC_Obj_Type::TARRAY) {
                 return PC_Obj_MultiType::create_array();
             }
             // if one of them is float, the result is float
             if ($ti1 == PC_Obj_Type::FLOAT || $ti2 == PC_Obj_Type::FLOAT) {
                 return PC_Obj_MultiType::create_float();
             }
             // otherwise its always int
             return PC_Obj_MultiType::create_int();
         case '==':
         case '!=':
         case '===':
         case '!==':
         case '<':
         case '>':
         case '<=':
         case '>=':
         case '&&':
         case '||':
         case 'xor':
         case '!':
             // always bool
             return PC_Obj_MultiType::create_bool();
         default:
             FWS_Helper::error('Unknown operator "' . $op . '"');
     }
 }
 /**
  * Puts constants, fields and methods from the given statements into $class
  * 
  * @param PC_Obj_Class $class the class
  * @param array $stmts an array of PC_Obj_Constant, PC_Obj_Field and PC_Obj_Method
  */
 private function handle_class_stmts($class, $stmts)
 {
     foreach ($stmts as $stmt) {
         if ($stmt instanceof PC_Obj_Constant) {
             $class->add_constant($stmt);
         } else {
             if ($stmt instanceof PC_Obj_Field) {
                 $class->add_field($stmt);
             } else {
                 if ($stmt instanceof PC_Obj_Method) {
                     // methods in interfaces are implicitly abstract
                     if ($class->is_interface()) {
                         $stmt->set_abstract(true);
                     }
                     // convert old-style constructors to the new ones
                     if (strcasecmp($stmt->get_name(), $class->get_name()) == 0) {
                         $stmt->set_name('__construct');
                     }
                     // constructors return an object of the class
                     if ($stmt->is_constructor() && ($stmt->get_return_type() && !$stmt->get_return_type()->is_unknown())) {
                         $spec = $stmt->get_return_type();
                         $this->report_error('The constructor of class ' . $class->get_name() . ' specifies return type ' . $spec, PC_Obj_Error::E_T_RETURN_DIFFERS_FROM_DOC, $stmt->get_line());
                     }
                     $class->add_method($stmt);
                 } else {
                     FWS_Helper::error('Unknown statement: ' . $stmt);
                 }
             }
         }
     }
 }
Beispiel #4
0
 /**
  * Sets the array-element-type for the given key to given type
  *
  * @param mixed $key the key
  * @param PC_Obj_MultiType $type the element-type
  * @param bool $append whether to append the value
  */
 public function set_array_type($key, $type, $append = false)
 {
     if ($key === null) {
         $this->_value = null;
         return;
     }
     if ($type !== null && !$type instanceof PC_Obj_MultiType) {
         FWS_Helper::def_error('instance', 'type', 'PC_Obj_MultiType', $type);
     }
     if (!$key instanceof PC_Obj_MultiType && !is_scalar($key)) {
         FWS_Helper::error('$key has to be a scalar or PC_Obj_MultiType (got ' . gettype($key) . ')');
     }
     // if it is already an array, but unknown, leave it unknown
     if ($this->_type == self::TARRAY && $this->_value === null) {
         return;
     }
     // convert implicitly to an array
     $this->_type = self::TARRAY;
     if (!is_array($this->_value)) {
         $this->_value = array();
     }
     if ($key instanceof PC_Obj_MultiType) {
         // if we don't know what to set, we don't know the content of the whole array anymore
         if ($key->is_unknown() || $key->is_val_unknown() || $key->is_multiple()) {
             $this->_value = null;
             return;
         }
         $key = $key->get_first()->get_value_for_use();
     }
     $val = $type === null ? new PC_Obj_MultiType() : $type;
     if ($append) {
         $this->_value[] = $val;
     } else {
         $this->_value[$key] = $val;
     }
 }