<commit_before><?php

# Generic object, to share methods between all misago's classes.
abstract class Object
{
  # A collection of attributes that must be accessible read-only (they must be protected).
  protected $attr_read = array();
  
  private   $__mapped_attributes = array();
  private   $__mapped_methods    = array();
  
  function __get($attr)
  {
    if (in_array($attr, $this->attr_read)) {
      return $this->$attr;
    }
    elseif (isset($this->__mapped_attributes[$attr])) {
      return $this->__mapped_attributes[$attr]['object']->{$this->__mapped_attributes[$attr]['attribute']};
    }
    elseif (method_exists($this, $attr)) {
      return $this->$attr();
    }
    return null;
  }
  
  function __set($attr, $value)
  {<commit_msg>Added documentation for Object.<commit_after><?php

# Generic object, to share methods between all misago's classes.
# 
# Example class:
# 
#   class MyClass extends Object
#   {
#     protected $id;
#     protected $table_name = 'classes';
#     protected $attr_read = array('table_name');
#     
#     function id($id=null)
#     {
#       if ($id !== null) {
#         $this->id = $id;
#       }
#       return $this->id;
#     }
#   }
#   
# =Read-only attributes.
# 
# You may define a list of `protected` attributes that may be accessible on get.
# 
#   $o = new MyClass();
#   $o->table_name          => returns 'classes'
#   $o->table_name = 'aaa'  => error: protected attribute
# 
# =Get/set methods as attributes
# 
# +Object+ permits to use get/set methods like standard attributes.
# 
#   $o = new MyClass();
#   $o->id = 4  # sets attribute throught the id() method.
#   $o->id      # gets attribute throught the id() method (thus returns 4).
# 
abstract class Object
{
  # A collection of attributes that must be accessible read-only (they must be protected).
  protected $attr_read = array();
  
  private   $__mapped_attributes = array();
  private   $__mapped_methods    = array();
  
  function __get($attr)
  {
    if (in_array($attr, $this->attr_read)) {
      return $this->$attr;
    }
    elseif (isset($this->__mapped_attributes[$attr])) {
      return $this->__mapped_attributes[$attr]['object']->{$this->__mapped_attributes[$attr]['attribute']};
    }
    elseif (method_exists($this, $attr)) {
      return $this->$attr();
    }
    return null;
  }
  
  function __set($attr, $value)
  {
{'fraction_non_alphanumeric': 0.1489451476793249, 'fraction_numerical': 0.0008438818565400844, 'mean_word_length': 3.1091854419410745, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5166148', 'n_tokens_mistral': 764, 'n_tokens_neox': 762, 'n_words': 199}