PHP Classes

File: docs/ReturnClauseMgr.md

Recommend this page to a friend!
  Classes of Kjell-Inge Gustafsson   PcGen   docs/ReturnClauseMgr.md   Download  
File: docs/ReturnClauseMgr.md
Role: Auxiliary data
Content type: text/markdown
Description: Auxiliary data
Class: PcGen
Generate PHP code from parameters
Author: By
Last change: 1.1.47
Date: 3 years ago
Size: 7,084 bytes
 

Contents

Class file image Download

[comment]: # (This file is part of PcGen, PHP Code Generation support package. Copyright 2020 Kjell-Inge Gustafsson, kigkonsult, All rights reserved, licence GPL 3.0)

ReturnClauseMgr

The `ReturnClauseMgr` manages return code of

  • source class property or variable (value), opt (int/variable) index
  • (scalar) fixedSourceValue
  • PHP expression
  • single function/method or chained invokes
  • ex ```return $this->property[32];```

Note, return (result from) function/method invoke is managed by [VariableMgr]::setBody() (or [PropertyMgr]) and use of [FcnInvokeMgr]

ReturnClauseMgr Methods

Inherited [Common methods]


* ```class``` _string_ if string, one of null, self, $this, 'otherClass', '$class'
   convenient constants found in PcGenInterface 
* ```variable``` _string_ variable/property name
  uppercase is autodetected as CONSTANT
  variable $-prefixed
* ```index```  _int_|_string_ opt array index, if _string_, index will be $-prefixed 
* For eol and indents, defaults are used
* Return _static_
* Throws InvalidException


  • note ```EntityMgr``` below
    
    
  • Return _static_
  • Throws InvalidException


* Return _array_, result code rows (null-bytes removed) no trailing eol
* Throws _RuntimeException_


  • Return _string_ with code rows (extends toArray), each code row with trailing eol
  • Throws _RuntimeException_


* Return _bool_|_int_|_float_|_string_, scalar

  • Return _bool_ true if set, false not

* ```fixedSourceValue``` _bool_|_int_|_float_|_string_, scalar
* Return _static_
* Throws InvalidException

---

  • Set a PHP expression
  • 
    
  • Return _static_
  • Throws InvalidException


* Return [EntityMgr]


  • Return _bool_ true if set, false not

* ```class``` _string_ one of null, self, $this, 'otherClass', '$class'
  convenient constants found in PcGenInterface 
* ```variable``` _string_ class/variable/property name
  uppercase is autodetected as CONSTANT
  variable $-prefixed
* ```index```  _int_|_string_ opt array index, if _string_, index will be $-prefixed 
* Return _static_
* Throws _InvalidArgumentException_


  • note ```EntityMgr``` below
    
    
  • Return _static_
  • Throws _InvalidArgumentException_

* convenient shortcut for ```ReturnClauseMgr::setSource()```
* Give source result ```$this->property```
* ```property``` _string_
* ```index```  _int_|_string_ opt array index
* Return _static_
* Throws _InvalidArgumentException_

  • convenient shortcut for ```ReturnClauseMgr::setSource()```
  • Give source result ```$variable```
  • 
    
  • Return _static_
  • Throws _InvalidArgumentException_

 * Results in uppercase constant
* ```isConst``` _bool_
  true : force ```$class::CONSTANT```
  false : NOT, (default) ```$class->$constant``` 
* Return _static_


* Results in uppercase constant * `isConst` _bool_ true : force `$class::variable` false : NOT, default, `$class->$variable` * Return _static_


* Return [TernaryNullCoalesceMgr]


  • Return _bool_ true if set, false not

* ```expr1``` _string_|[EntityMgr]|[FcnInvokeMgr]|[TernaryNullCoalesceMgr]
* ```expr2``` _string_|[EntityMgr]|[FcnInvokeMgr]
* ```expr3``` _string_|[EntityMgr]|[FcnInvokeMgr]
* ```ternaryOperator``` _bool_ true (default) : ternary expr, false : null coalesce expr
* Return _static_
* Throws _InvalidArgumentException_

---


* Return _bool_ true if set, false not


  • 
    
  • Return _static_
  • Throws _InvalidArgumentException_

* ```fcnInvoke``` [FcnInvokeMgr]\[]
* Return _static_
* Throws _InvalidArgumentException_


Notes on chained invokes

* The first must have a "class" : parent, self, $this, 'otherClass', '$class' when next is set
* All but first must have $this, 'otherClass', '$class'

Ex on _ReturnClauseMgr::setFcnInvoke_ input

[

FcnInvokeMgr::factory( 'aClass', 'factory', [ 'arg1', 'arg2' ] ),
FcnInvokeMgr::factory( 'aClass', 'someMethod', [ 'arg3', 'arg4' ] )

]

results in 

aClass::factory( $arg1, $arg2 )

->someMethod( $arg3, $arg4 );
---


#### Misc

_EntityMgr_ instance creation ([EntityMgr])

  • * convenient constants found in PcGenInterface
    
    

Example 1

<?php

$code = ReturnClauseMgr::factory( null, 'variable' )
    ->toString();

$code .= ReturnClauseMgr::factory( ReturnClauseMgr::THIS_KW, 'variable' )
    ->toString();

$code .= ReturnClauseMgr::factory( ReturnClauseMgr::THIS_KW )
    ->toString();

Result :

    return $variable;
    return $this->variable;
    return $this;

Example 2

<?php

$rcm = ReturnClauseMgr::init()
    ->setBaseIndent()
    ->setFcnInvoke( 
        FcnInvokeMgr::factory( 'SourceClass', FcnInvokeMgr::FACTORY, [ 'arg11', 'arg12' ] ),
        FcnInvokeMgr::factory( 'SourceClass', 'method2', [ 'arg21', 'arg22' ] ),
        FcnInvokeMgr::factory( 'SourceClass', 'method3', [ 'arg31', 'arg32' ] ),
        FcnInvokeMgr::factory( 'SourceClass', 'method4', [ 'arg41', 'arg42' ] ),
        FcnInvokeMgr::factory( 'SourceClass', 'method5' )
    )
    ->toString());

Result :

return SourceClass::factory( $arg11, $arg12 )
    ->method2( $arg21, $arg22 )
    ->method3( $arg31, $arg32 )
    ->method4( $arg41, $arg42 )
    ->method5();

<small>Return to PcGen [README], [Summary]</small>

[ChainInvokeMgr]:ChainInvokeMgr.md [Common methods]:CommonMethods.md [EntityMgr]:EntityMgr.md [FcnInvokeMgr]:FcnInvokeMgr.md [PropertyMgr]:PropertyMgr.md [README]:../README.md [Summary]:Summary.md [TernaryNullCoalesceMgr]:TernaryNullCoalesceMgr.md [VariableMgr]:VariableMgr.md