Zend\Code\Generator\ValueGenerator::__construct PHP Method

__construct() public method

public __construct ( mixed $value = null, string $type = self::TYPE_AUTO, string $outputMode = self::OUTPUT_MULTIPLE_LINE, null | ArrayObject | Zend\Stdlib\ArrayObject $constants = null )
$value mixed
$type string
$outputMode string
$constants null | ArrayObject | Zend\Stdlib\ArrayObject
    public function __construct($value = null, $type = self::TYPE_AUTO, $outputMode = self::OUTPUT_MULTIPLE_LINE, $constants = null)
    {
        // strict check is important here if $type = AUTO
        if ($value !== null) {
            $this->setValue($value);
        }
        if ($type !== self::TYPE_AUTO) {
            $this->setType($type);
        }
        if ($outputMode !== self::OUTPUT_MULTIPLE_LINE) {
            $this->setOutputMode($outputMode);
        }
        if ($constants === null) {
            $constants = new SplArrayObject();
        } elseif (!($constants instanceof SplArrayObject || $constants instanceof StdlibArrayObject)) {
            throw new InvalidArgumentException('$constants must be an instance of ArrayObject or Zend\\Stdlib\\ArrayObject');
        }
        $this->constants = $constants;
    }

Usage Example

 /**
  * @param array      $configData
  * @param Parameters $params
  */
 public function __construct(array $configData = [], Parameters $params)
 {
     // set params
     $this->params = $params;
     // reset constant compilation
     $configData = $this->resetConfigDirCompilation($configData);
     $configData = $this->resetTemplateMapCompilation($configData);
     // call parent constructor
     parent::__construct($configData, ValueGenerator::TYPE_ARRAY);
     // init constants
     $this->initEnvironmentConstants();
     $this->addConstant($this->params->moduleRootConstant);
     $this->addConstant($this->params->applicationRootConstant);
 }