Add preassigned template data.

@param  array             $data      ;
@param  null|string|array $templates ;

@return self
@throws \InvalidArgumentException
513366
public function addData(array $data, $templates = null): self
    {
        if (null === $templates) {
            $this->sharedVariables = \array_merge($this->sharedVariables, $data);

            return $this;
        }

        if (\is_string($templates)) {
            $templates = [$templates];
        }

        if (\is_array($templates)) {
            foreach ($templates as $template) {
                if (isset($this->templateVariables[$template])) {
                    $this->templateVariables[$template] = \array_merge($this->templateVariables[$template], $data);
                } else {
                    $this->templateVariables[$template] = $data;
                }
            }

            return $this;
        }

        throw new \InvalidArgumentException(
            'The templates variable must be null, an array or a string, ' . \gettype($templates) . ' given.'
        );
    }
1022160
public function setData(array $data, $replaceTemplateVariables = true) : self
    {
        $this->assertDataIsWritable();

        if ($replaceTemplateVariables) {
            $data = $this->replaceTemplateVariables($data);
        }

        $this->_data = $data;

        return $this;
    }
469653
protected function _compileTemplates(array $templates = [])
    {
        if (empty($templates)) {
            $templates = array_keys($this->_config);
        }
        foreach ($templates as $name) {
            $template = $this->get($name);
            if ($template === null) {
                $this->_compiled[$name] = [null, null];
            }

            $template = str_replace('%', '%%', $template);
            preg_match_all('#\{\{([\w\._]+)\}\}#', $template, $matches);
            $this->_compiled[$name] = [
                str_replace($matches[0], '%s', $template),
                $matches[1]
            ];
        }
    }
139619
public function add_data(array $data)
	{
		$ar = \func_get_args();
		foreach ( $ar as $d ){
			if ( \is_array($d) ){
				$this->data = $this->has_data() ? array_merge($this->data,$d) : $d;
			}
		}
		return $this;
	}
559235
public function htmlTemplate($template, $data=[]) {
		$data['message'] = $this;
		$res = $this->buildTemplate($template, $data);
		return $this->html($res);
	}
959204
public function appendData($data)
    {
        if (!is_array($data)) {
            throw new \InvalidArgumentException('Cannot append view data. Expected array argument.');
        }
        $this->data = array_merge($this->data, $data);
    }
143069
public function addData($data) {
        if (\is_string($data)) {
            $this->addDataSql($data);
        } elseif (\is_array($data)) {
            $this->addDataArray($data);
        } elseif (\is_object($data)) {
            $this->addDataObjectCollection($data);
        } elseif (\is_resource($data)) {
            $this->addDataQueryResource($data);
        } else {
            throw new InvalidArgumentException('Unsupported data type.');
        }
        return $this;
    }
786531
protected function setParsedBody($data)
    {
        if (! is_null($data) && ! is_array($data) && ! is_object($data)) {
            throw new InvalidArgumentException(sprintf(
                'Invalid parsed body provided; must be an null, or array, '
                . 'or object, "%s" provided.',
                gettype($data)
            ));
        }
        $this->parsedBody = $data;

        return $this;
    }
908193
public function template($template, $data = Array()){
        \Template::with($template, $data);
        \View::serve();
    }
1333593
public function merge(array $templates, $description = null, array $additionalData = [])
    {
        if (count($templates) == 0) {
            throw new \InvalidArgumentException('No templates given');
        }

        $mergedTemplate = ['AWSTemplateFormatVersion' => '2010-09-09'];

        $mergeKeys = [
            'Parameters',
            'Mappings',
            'Conditions',
            'Resources',
            'Outputs',
            'Metadata',
        ];

        foreach ($templates as $template) {
            if (!$template instanceof \StackFormation\Template) {
                throw new \InvalidArgumentException('Expecting an array of \StackFormation\Template objects');
            }

            try {
                $array = $template->getDecodedJson();

                // Copy the current description into the final template
                if (!empty($array['Description'])) {
                    $mergedTemplate['Description'] = $array['Description'];
                }

                // Merge keys from current template with final template
                foreach ($mergeKeys as $mergeKey) {
                    if (isset($array[$mergeKey]) && is_array($array[$mergeKey])) {
                        foreach ($array[$mergeKey] as $key => $value) {
                            if (isset($mergedTemplate[$mergeKey][$key])) {
                                // it's ok if the parameter has the same name and type...
                                if (($mergeKey != 'Parameters') || ($value['Type'] != $mergedTemplate[$mergeKey][$key]['Type'])) {
                                    throw new \Exception("Duplicate key '$key' found in '$mergeKey'");
                                }
                            }
                            $mergedTemplate[$mergeKey][$key] = $value;
                        }
                    }
                }
            } catch (TemplateDecodeException $e) {
                if (Div::isProgramInstalled('jq')) {
                    $tmpfile = tempnam(sys_get_temp_dir(), 'json_validate_');
                    file_put_contents($tmpfile, $template->getProcessedTemplate());
                    passthru('jq . ' . $tmpfile);
                    unlink($tmpfile);
                }

                throw $e;
            }
        }

        // If a description override is specified use it
        if (!empty($description)) {
            $mergedTemplate['Description'] = trim($description);
        }
        if (empty($mergedTemplate['Description'])) {
            $mergedTemplate['Description'] = 'Merged Template';
        }

        $mergedTemplate = array_merge_recursive($mergedTemplate, $additionalData);

        $json = json_encode($mergedTemplate, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);

        // Check for max template size
        if (strlen($json) > self::MAX_CF_TEMPLATE_SIZE) {
            $json = json_encode($mergedTemplate, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);

            // Re-check for max template size
            if (strlen($json) > self::MAX_CF_TEMPLATE_SIZE) {
                throw new \Exception(sprintf('Template too big (%s bytes). Maximum template size is %s bytes.', strlen($json), self::MAX_CF_TEMPLATE_SIZE));
            }
        }

        return $json;
    }
632561
public function addData($data){
        foreach( $data as $key => $value ){
            $this->setData($key, $value);
        }
        return $this;
    }
626483
public function addData($data) : void
    {
        Assert::isInstanceOfAny($data, [Chunk::class, X509Certificate::class]);
        $this->data[] = $data;
    }
255363
public function setData($data)
    {
      if(!is_string($data) && strlen(trim($data)) == 0)
        throw new InvalidArgumentException(__METHOD__ . '; Invalid data, must be a non empty string');

      $this->data = $data;
    }
865927
public function add(array $data): Insert
    {
        if (!isset($data[0]) && count($this->fields) == 0) {
            $this->fields(array_keys($data));
        }

        $this->data[] = $data;
        return $this;
    }
343864
public function setData(array $data): self
    {
        list($this->foreignKeys, $this->belongsToMany, $this->relationshipTypes,
            $this->reversedRelationships,$this->tableNames, $this->primaryKeys,
            $this->attributeTypes, $this->attributeLengths, $this->attributes, $this->rawAttributes,
            $this->reversedClasses) = $data;

        return $this;
    }
1015661
public function render($templates, array $data = array())
    {
        $__templates = (array) $templates;

        extract($data);
        ob_start();

        foreach ($__templates as $__template) {
            $__template = $this->templatesPath.$__template;

            if (is_readable($__template) && is_file($__template)) {
                include $__template;
            } else {
                ob_end_clean();
                throw new \Shade\Exception('Template file "'.$__template.'" does not exists');
            }
            $content = ob_get_clean();
        }

        return $content;
    }
1280854
public function render($templates, array $data = array())
    {
        $templates = (array) $templates;

        foreach ($templates as $template) {
            if (!is_readable($template) || !is_file($template)) {
                throw new \Shade\Exception('Template file "'.$template.'" does not exists');
            }
            $content = str_replace(array_keys($data), $data, file_get_contents($template));
            $data[$this->layoutContentPlaceholder] = $content;
        }

        return $content;
    }