/** * @test */ public function cameCaseToUnderscore() { $this->assertEquals('camel_case', RegexHelper::cameCaseToUnderscore('camelCase')); }
/** * Helper method to render twig templates more dynamically * * @param array $data optional Data to pass to Twig * @param string|null $templatePathOverride optional Manually specify which template to use (without the .twig) * * @return string The rendered template */ protected function renderTwig($data = array(), $templatePathOverride = null) { if (!is_array($data)) { $data = array(); } $calledMethod = $this->getCalledActionMethod(); $htmlPageIdentifier = RegexHelper::cameCaseToUnderscore(substr($this->getNonNamespacedCalledClass(), 0, -10) . ucfirst(substr($calledMethod, 0, -6))); $htmlPageIdentifier = str_replace('_', '-', $htmlPageIdentifier); $data['globalLayoutTemplate'] = self::$globalLayoutTemplate; $data['layoutTemplate'] = $this->getLayoutTemplate(); $data['cssFiles'] = $this->cssFiles; $data['javascriptFiles'] = $this->javascriptFiles; $data['session'] = self::$session; $data['htmlPageIdentifier'] = $htmlPageIdentifier; if (empty($templatePathOverride)) { $folder = RegexHelper::cameCaseToUnderscore(substr($this->getNonNamespacedCalledClass(), 0, -10)); $templateName = RegexHelper::cameCaseToUnderscore(substr($calledMethod, 0, -6)); $templatePath = $folder . '/' . $templateName; } else { $templatePath = $templatePathOverride; } return $this->renderResponse(self::$twig->render($templatePath . '.twig', $data)); }