[]]; $options += $defaults; $context = []; $this->_context = $options['context'] + $this->_context; foreach (array_keys($this->_context) as $key) { $context[$key] = $this->__get($key); } $data = array_merge($this->_toString($context), $this->_toString($data)); return Text::insert($template, $data, $options); } /** * Returns a template string * * @param string $type * @param array $options * @return string */ public function template($type, $options) { if (isset($options[$type])) { return $options[$type]; } return isset($options['template']) ? $options['template'] : ''; } /** * Renders `$data` into an easier to understand, or flat, array. * * @param array $data Data to traverse. * @return array */ protected function _toString($data) { foreach ($data as $key => $val) { switch (true) { case is_object($val) && !$val instanceof \Closure: try { $data[$key] = (string) $val; } catch (Exception $e) { $data[$key] = ''; } break; case is_array($val): $data = array_merge($data, Set::flatten($val)); break; } } return $data; } } ?>