<commit_before><?php
/**
 * =============================================================================
 * Copyright (c) 2010, <NAME>
 * All rights reserved.
 *
 * This file is part of Oboe and is licensed by the Copyright holder under the
 * 3-clause BSD License.  The full text of the license can be found in the
 * LICENSE.txt file included in the root directory of this distribution or at
 * the link below.
 * =============================================================================
 *
 * @license http://www.opensource.org/licenses/bsd-license.php
 */
namespace oboe;

/**
 * This class implements attribute getters and setters.  It also provides
 * syntactic sugar for the id, class and style attributes.
 *
 * @author <NAME> <<EMAIL>>
 */
abstract class ElementBase {

  /** The element's tag name */
  protected $_tag;

  /** The element's id attribute */
  protected $_id;

  /** The element's css class attribute */
  protected $_class = Array();

  /** The element's style attribute */
  protected $_style;

  /** The element's attributes */
  protected $_attributes;

  /**
   * Base class constructor.
   *
   * @param string The element's tag name
   * @param string The element's id attribute
   * @param string The element's class attribute
   */
  protected function __construct($tag, $id = null, $class = null) {
    $this->_tag = $tag;
    $this->_id = $id;
    $this->_attributes = array();
    $this->_style = array();

    if ($class !== null) {
      $this->setClass($class);
    }
  }

  /**
   * Generates the HTML markup for the element.
   *
   * @return string
   */
  public function __toString() {
    // Get the opening tag for the element
    $str = self::openTag($this);
    
    // Make the opening tag self closing
    return substr($str, 0, -1).'/>';
  }

  /** 
   * Add the given class name to the element.
   *
   * @param string $class
   * @return $this For chainability
   */
  public function addClass($class) {
    $this->_class[] = $class;

    return $this;
  }

  /**
   * This method adds the element to the <body> element.  In order for this
   * method to work the implementing class needs to implement the
   * item\Body interface.
   */
  public function addToBody() {
    Page::addElementToBody($this);
  }

  /**
   * This method adds the element to the <head> element.  In order for this
   * method to work the implementing class needs to implement the
   * item\Head interface.
   */
  public function addToHead() {
    Page::addElementToHead($this);
  }

  /**
   * Retriever for an attribute value.  If the attribute is not set null is
   * returned.
   *
   * @param string The name of the attribute to retrieve
   * @return string The value of the given attribute
   */
  public function getAttribute($attribute) {
    if ($attribute == 'id') {
      return $this->getId();
    } else if ($attribute == 'class') {
      return $this->getClass();
    } else if ($attribute == 'style') {
      return $this->getStyle();
    } else if (array_key_exists($attribute, $this->_attributes)) {
      return $this->_attributes[$attribute];
    } else {
      return null;
    }
  }

  /**
   * Getter for the element's class attribute.
   *<commit_msg>Updated ElementBase addToHead and ElementBase addToBody to support method chaining<commit_after><?php
/**
 * =============================================================================
 * Copyright (c) 2010, <NAME>
 * All rights reserved.
 *
 * This file is part of Oboe and is licensed by the Copyright holder under the
 * 3-clause BSD License.  The full text of the license can be found in the
 * LICENSE.txt file included in the root directory of this distribution or at
 * the link below.
 * =============================================================================
 *
 * @license http://www.opensource.org/licenses/bsd-license.php
 */
namespace oboe;

/**
 * This class implements attribute getters and setters.  It also provides
 * syntactic sugar for the id, class and style attributes.
 *
 * @author <NAME> <<EMAIL>>
 */
abstract class ElementBase {

  /** The element's tag name */
  protected $_tag;

  /** The element's id attribute */
  protected $_id;

  /** The element's css class attribute */
  protected $_class = Array();

  /** The element's style attribute */
  protected $_style;

  /** The element's attributes */
  protected $_attributes;

  /**
   * Base class constructor.
   *
   * @param string The element's tag name
   * @param string The element's id attribute
   * @param string The element's class attribute
   */
  protected function __construct($tag, $id = null, $class = null) {
    $this->_tag = $tag;
    $this->_id = $id;
    $this->_attributes = array();
    $this->_style = array();

    if ($class !== null) {
      $this->setClass($class);
    }
  }

  /**
   * Generates the HTML markup for the element.
   *
   * @return string
   */
  public function __toString() {
    // Get the opening tag for the element
    $str = self::openTag($this);
    
    // Make the opening tag self closing
    return substr($str, 0, -1).'/>';
  }

  /** 
   * Add the given class name to the element.
   *
   * @param string $class
   * @return $this For chainability
   */
  public function addClass($class) {
    $this->_class[] = $class;

    return $this;
  }

  /**
   * This method adds the element to the <body> element.  In order for this
   * method to work the implementing class needs to implement the
   * item\Body interface.
   */
  public function addToBody() {
    Page::addElementToBody($this);
    return $this;
  }

  /**
   * This method adds the element to the <head> element.  In order for this
   * method to work the implementing class needs to implement the
   * item\Head interface.
   */
  public function addToHead() {
    Page::addElementToHead($this);
    return $this;
  }

  /**
   * Retriever for an attribute value.  If the attribute is not set null is
   * returned.
   *
   * @param string The name of the attribute to retrieve
   * @return string The value of the given attribute
   */
  public function getAttribute($attribute) {
    if ($attribute == 'id') {
      return $this->getId();
    } else if ($attribute == 'class') {
      return $this->getClass();
    } else if ($attribute == 'style') {
      return $this->getStyle();
    } else if (array_key_exists($attribute, $this->_attributes)) {
      return $this->_attributes[$attribute];
    } else {
      return null;
    }
  }

  /**
   * Getter for the element's class attribute.
   *
{'fraction_non_alphanumeric': 0.16393442622950818, 'fraction_numerical': 0.002144936417956182, 'mean_word_length': 2.932530120481928, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, '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': '5961423', 'n_tokens_mistral': 1867, 'n_tokens_neox': 1792, 'n_words': 671}