Zephir\ClassMethod::setReturnTypes PHP Method

setReturnTypes() public method

public setReturnTypes ( $returnType )
    public function setReturnTypes($returnType)
    {
        $this->returnTypesRaw = $returnType;
        if (isset($returnType['void']) && $returnType['void']) {
            $this->void = true;
            return;
        }
        if (isset($returnType['list'])) {
            $types = array();
            $castTypes = array();
            foreach ($returnType['list'] as $returnTypeItem) {
                if (isset($returnTypeItem['cast'])) {
                    if (isset($returnTypeItem['cast']['collection'])) {
                        continue;
                    }
                    $castTypes[$returnTypeItem['cast']['value']] = $returnTypeItem['cast']['value'];
                } else {
                    $types[$returnTypeItem['data-type']] = $returnTypeItem;
                }
            }
            if (count($castTypes)) {
                $types['object'] = array();
                $this->returnClassTypes = $castTypes;
            }
            if (count($types)) {
                $this->returnTypes = $types;
            }
        }
    }

Usage Example

Esempio n. 1
0
 /**
  * Generate internal method's based on the equivalent PHP methods,
  * allowing bypassing php userspace for internal method calls
  */
 public function setupOptimized(CompilationContext $compilationContext)
 {
     if (!$compilationContext->config->get('internal-call-transformation', 'optimizations')) {
         return;
     }
     $classDefinition = $this->getClassDefinition();
     /* Skip for closures */
     if ($this->getName() == '__invoke' || $classDefinition->isInterface()) {
         return;
     }
     if (!$this->isInternal() && !$classDefinition->isBundled()) {
         /* Not supported for now */
         if ($this->getNumberOfRequiredParameters() != $this->getNumberOfParameters()) {
             return $this;
         }
         if ($this->isConstructor()) {
             return $this;
         }
         $optimizedName = $this->getName() . '_zephir_internal_call';
         $visibility = array('internal');
         $statements = null;
         if ($this->statements) {
             $statements = new StatementsBlock(json_decode(json_encode($this->statements->getStatements()), true));
         }
         $optimizedMethod = new ClassMethod($classDefinition, $visibility, $optimizedName, $this->parameters, $statements, $this->docblock, null, $this->expression);
         $optimizedMethod->typeInference = $this->typeInference;
         $optimizedMethod->setReturnTypes($this->returnTypes);
         $classDefinition->addMethod($optimizedMethod);
     }
 }