<commit_before><?php

class dmCoreLayoutHelper
{
  protected
    $dispatcher,
    $serviceContainer,
    $baseWebPath,
    $isHtml4,
    $isHtml5;
    

  public function __construct(sfEventDispatcher $dispatcher, dmBaseServiceContainer $serviceContainer)
  {
    $this->dispatcher = $dispatcher;
    $this->serviceContainer = $serviceContainer;
    
    $this->initialize();
  }
  
  protected function initialize()
  {
    $this->isHtml4 = 4 == $this->getDocTypeOption('version', 4);
    $this->isHtml5 = 5 == $this->getDocTypeOption('version', 5);
  }
  
  public function renderHead()
  {
    return
    $this->renderHttpMetas().
    $this->renderMetas().
    $this->renderStylesheets().
    $this->renderFavicon().
    $this->renderIeHtml5Fix().
    $this->renderHeadJavascripts();
  }

  public function renderBodyTag($options = array())
  {
    return $this->getHelper()->open('body', dmString::toArray($options));
  }
  
  protected function getDocTypeOption($name, $default)
  {
    $value = dmArray::get(sfConfig::get('dm_html_doctype'), $name, $default);
    
    if ('version' === $name && 1 == $value)
    {
      $value = '1.0';
    }
    
    return $value;
  }

  protected function isHtml5()
  {
    return $this->isHtml5;
  }

  public function renderDoctype()
  {
    if ($this->isHtml5())
    {
      $doctype = '<!DOCTYPE html>';
    }
    else if ($this->isHtml4)
    {
      $doctype = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">';
    }
    else
    {
      $doctype = sprintf(
        '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML %s%s//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1%s.dtd">',
        $this->getDocTypeOption('version', '1.0'),
        '1.1' == $this->getDocTypeOption('version', '1.0') ? ''  : ' '.ucfirst(strtolower($this->getDocTypeOption('compliance', 'transitional'))),
        '1.1' == $this->getDocTypeOption('version', '1.0') ? '1' : '-'.strtolower($this->getDocTypeOption('compliance', 'transitional'))
      );
    }
    
    return $doctype."\n";
  }
  
  public function renderHtmlTag()
  {
    if ($this->isHtml5() || $this->isHtml4)
    {
      return '<html>';
    }
    
    $culture = $this->serviceContainer->getParameter('user.culture');

    return sprintf(
      '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="%s" >',
      $culture,
      '1.1' == $this->getDocTypeOption('version', '1.0') ? '' : "lang=\"$culture\""
    );
  }
  
  
  protected function getMetas()
  {
    return array(
      'title'       => $this->getService('response')->getTitle(),
      'language'    => $this->serviceContainer->getParameter('user.culture'),
    );
  }
  
  public function renderMetas()
  {
    /*
     * Allow listeners of dm.response.filter_metas event
     * to filter and modify the metas list
     */
    $metas = $this->dispatcher->filter(
      new sfEvent($this, 'dm.layout.filter_metas'),
      $this->getMetas()
    )->getReturnValue();<commit_msg>Add lang attribute to HTML5 document HTML tag - Closes #148<commit_after><?php

class dmCoreLayoutHelper
{
  protected
    $dispatcher,
    $serviceContainer,
    $baseWebPath,
    $isHtml4,
    $isHtml5;
    

  public function __construct(sfEventDispatcher $dispatcher, dmBaseServiceContainer $serviceContainer)
  {
    $this->dispatcher = $dispatcher;
    $this->serviceContainer = $serviceContainer;
    
    $this->initialize();
  }
  
  protected function initialize()
  {
    $this->isHtml4 = 4 == $this->getDocTypeOption('version', 4);
    $this->isHtml5 = 5 == $this->getDocTypeOption('version', 5);
  }
  
  public function renderHead()
  {
    return
    $this->renderHttpMetas().
    $this->renderMetas().
    $this->renderStylesheets().
    $this->renderFavicon().
    $this->renderIeHtml5Fix().
    $this->renderHeadJavascripts();
  }

  public function renderBodyTag($options = array())
  {
    return $this->getHelper()->open('body', dmString::toArray($options));
  }
  
  protected function getDocTypeOption($name, $default)
  {
    $value = dmArray::get(sfConfig::get('dm_html_doctype'), $name, $default);
    
    if ('version' === $name && 1 == $value)
    {
      $value = '1.0';
    }
    
    return $value;
  }

  protected function isHtml5()
  {
    return $this->isHtml5;
  }

  public function renderDoctype()
  {
    if ($this->isHtml5())
    {
      $doctype = '<!DOCTYPE html>';
    }
    else if ($this->isHtml4)
    {
      $doctype = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">';
    }
    else
    {
      $doctype = sprintf(
        '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML %s%s//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1%s.dtd">',
        $this->getDocTypeOption('version', '1.0'),
        '1.1' == $this->getDocTypeOption('version', '1.0') ? ''  : ' '.ucfirst(strtolower($this->getDocTypeOption('compliance', 'transitional'))),
        '1.1' == $this->getDocTypeOption('version', '1.0') ? '1' : '-'.strtolower($this->getDocTypeOption('compliance', 'transitional'))
      );
    }
    
    return $doctype."\n";
  }

  public function renderHtmlTag()
  {
    $culture = $this->serviceContainer->getParameter('user.culture');

    if ($this->isHtml5() || $this->isHtml4)
    {
      $htmlTag = sprintf('<html lang="%s">', $culture);
    }
    else
    {
      $htmlTag = sprintf(
        '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="%s"%s >',
        $culture,
        '1.1' == $this->getDocTypeOption('version', '1.0') ? '' : " lang=\"$culture\""
      );
    }

    return $htmlTag;
  }
  
  protected function getMetas()
  {
    return array(
      'title'       => $this->getService('response')->getTitle(),
      'language'    => $this->serviceContainer->getParameter('user.culture'),
    );
  }
  
  public function renderMetas()
  {
    /*
     * Allow listeners of dm.response.filter_metas event
     * to filter and modify the metas list
     */
    $metas = $this->dispatcher->filter(
      new sfEvent($this, 'dm.layout.filter_metas'),
      $this->getMetas()
    )->getReturnValue();
{'fraction_non_alphanumeric': 0.18426706329532308, 'fraction_numerical': 0.016526194017517766, 'mean_word_length': 2.8425396825396825, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 89, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1083861', 'n_tokens_mistral': 2169, 'n_tokens_neox': 2059, 'n_words': 343}