shareWithAll($data); } if (is_array($templates)) { return $this->shareWithSome($data, $templates); } if (is_string($templates)) { return $this->shareWithSome($data, array($templates)); } throw new LogicException( 'The templates variable must be null, an array or a string, ' . gettype($templates) . ' given.' ); } /** * Add data shared with all templates. * @param array $data; * @return Data */ public function shareWithAll($data) { $this->sharedVariables = array_merge($this->sharedVariables, $data); return $this; } /** * Add data shared with some templates. * @param array $data; * @param array $templates; * @return Data */ public function shareWithSome($data, 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; } /** * Get template data. * @param null|string $template; * @return array */ public function get($template = null) { if (isset($template, $this->templateVariables[$template])) { return array_merge($this->sharedVariables, $this->templateVariables[$template]); } return $this->sharedVariables; } }