<commit_before><?php
/*
 * Limb PHP Framework
 *
 * @link http://limb-project.com
 * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
 * @license    LGPL http://www.gnu.org/copyleft/lesser.html
 */
lmb_require('limb/core/src/lmbSetInterface.interface.php');
lmb_require('limb/core/src/exception/lmbNoSuchMethodException.class.php');
lmb_require('limb/core/src/exception/lmbNoSuchPropertyException.class.php');
/**
 * Generic container for data with magic accessors.
 *
 * NOTE: All properties are stored as attributes of an object. If you need to
 * make certain properties 'guarded', you should prefix these properties
 * with "_" symbol.
 *
 * <b>Basic usage</b>
 * <code>
 * //filling object
 * $obj = new lmbObject(array('foo' => 'bar'));
 * //the getter calls below are equal
 * $obj->get('foo');
 * $obj->getFoo();
 * $obj['foo'];
 * $obj->foo;
 * //the setter calls below are equal
 * $obj->set('foo', 'hey');
 * $obj->setFoo('hey');
 * $obj['foo'] = 'hey';
 * $obj->foo = 'hey';
 * </code>
 *
 * <b>Mapping generic getters to fine-grained methods</b>
 * <code>
 * class Foo extends lmbObject
 * {
 *    function getBar()
 *    {
 *      return 'bar';
 *    }
 * }
 * $foo = new Foo();
 * //the call below will be magically mapped to getBar() method
 * //this can be very useful for WACT templates, e.g. {$bar} in
 * //template will trigger the same method getBar() as well
 * $foo->get('bar');
 * </code>
 *
 * <b>Mapping generic setters to fine-grained methods</b>
 * <code>
 * class Foo extends lmbObject
 * {
 *    function setBar($value)
 *    {
 *      $this->_setRaw('bar', (int)$value);
 *    }
 * }
 * $foo = new Foo();
 * //the call below will be magically mapped to setBar($value) method
 * //this can be useful if some property processing is required
 * $foo->set('bar', '10.0');
 * </code>
 *
 * @version $Id: lmbObject.class.php 5567 2007-04-06 14:37:24Z serega $
 * @package core
 */
class lmbObject implements lmbSetInterface
{
  /**
   * Constructor.
   * Fills internals properties if any
   * @param array properties array
   */
  function __construct($attributes = array())
  {
    if($attributes)
      $this->import($attributes);
  }
  /**
   * Returns class name using PHP built in get_class
   * @see get_class
   * @return string
   */
  final function getClass()
  {
    return get_class($this);
  }
  /**
   * Returns object's hash in md5 form
   * @see md5
   * @return string
   */
  function getHash()
  {
    return md5(serialize($this));
  }
  /**
   * Merges existing properties with new ones
   * @param array
   */
  function import($values)
  {
    if(!is_array($values))
      return;

    foreach($values as $name => $value)
    {
      if(!$this->_isGuarded($name))
        $this->_setRaw($name, $value);
    }
  }
  /**
   * Exports all object properties as an array
   * @return array
   */
  function export()
  {
    $exported = array();
    foreach(get_object_vars($this) as $name => $var)
    {
      if(!$this->_isGuarded($name))
        $exported[$name] = $var;
    }
    return $exported;
  }

  /**
   * Checks if such property exists
   * Can be overriden in child classes like lmbActiveRecord
   * @return bool returns true even if attribute is null
   */
  function has($name)
  {
    return $this->_hasAttribute($name) || $this->_mapPropertyToMethod($name);
  }

  protected function _hasAttribute($name)
  {
    return property_exists($this, $name);
  }

  function getAttributesNames()
  {
    return array_keys($this->export());
  }

  /**
   * Removes specified property
   * @param string
   */
  function remove($name)
  {
    if($this->_hasAttribute($name) && !$this->_isGuarded($name))
      unset($this->$name);
  }

  /**
   * Removes all object properties
   */
  function reset()
  {
    foreach($this->getAttributesNames() as $name)
      unset($this->$name);
  }

  /**
   * Returns property value if it exists and not guarded.
   * Magically maps getter to fine-grained method if it exists, e.g. get('foo') => getFoo()
   * @param string property name
   * @return mixed|null
   */
  function get($name, $default = LIMB_UNDEFINED)
  {
    if($method = $this->_mapPropertyToMethod($name))
      return $this->$method();

    if($this->_hasAttribute($name) && !$this->_isGuarded($name))
      return $this->_getRaw($name);

    if(LIMB_UNDEFINED !== $default) {
      return $default;
    }
    
    throw new lmbNoSuchPropertyException("No such property '$name' in " . get_class($this));<commit_msg>[svn r6884] -- minor style changes<commit_after><?php
/*
 * Limb PHP Framework
 *
 * @link http://limb-project.com
 * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
 * @license    LGPL http://www.gnu.org/copyleft/lesser.html
 */
lmb_require('limb/core/src/lmbSetInterface.interface.php');
lmb_require('limb/core/src/exception/lmbNoSuchMethodException.class.php');
lmb_require('limb/core/src/exception/lmbNoSuchPropertyException.class.php');
/**
 * Generic container for data with magic accessors.
 *
 * NOTE: All properties are stored as attributes of an object. If you need to
 * make certain properties 'guarded', you should prefix these properties
 * with "_" symbol.
 *
 * <b>Basic usage</b>
 * <code>
 * //filling object
 * $obj = new lmbObject(array('foo' => 'bar'));
 * //the getter calls below are equal
 * $obj->get('foo');
 * $obj->getFoo();
 * $obj['foo'];
 * $obj->foo;
 * //the setter calls below are equal
 * $obj->set('foo', 'hey');
 * $obj->setFoo('hey');
 * $obj['foo'] = 'hey';
 * $obj->foo = 'hey';
 * </code>
 *
 * <b>Mapping generic getters to fine-grained methods</b>
 * <code>
 * class Foo extends lmbObject
 * {
 *    function getBar()
 *    {
 *      return 'bar';
 *    }
 * }
 * $foo = new Foo();
 * //the call below will be magically mapped to getBar() method
 * //this can be very useful for WACT templates, e.g. {$bar} in
 * //template will trigger the same method getBar() as well
 * $foo->get('bar');
 * </code>
 *
 * <b>Mapping generic setters to fine-grained methods</b>
 * <code>
 * class Foo extends lmbObject
 * {
 *    function setBar($value)
 *    {
 *      $this->_setRaw('bar', (int)$value);
 *    }
 * }
 * $foo = new Foo();
 * //the call below will be magically mapped to setBar($value) method
 * //this can be useful if some property processing is required
 * $foo->set('bar', '10.0');
 * </code>
 *
 * @version $Id: lmbObject.class.php 5567 2007-04-06 14:37:24Z serega $
 * @package core
 */
class lmbObject implements lmbSetInterface
{
  /**
   * Constructor.
   * Fills internals properties if any
   * @param array properties array
   */
  function __construct($attributes = array())
  {
    if($attributes)
      $this->import($attributes);
  }
  /**
   * Returns class name using PHP built in get_class
   * @see get_class
   * @return string
   */
  final function getClass()
  {
    return get_class($this);
  }
  /**
   * Returns object's hash in md5 form
   * @see md5
   * @return string
   */
  function getHash()
  {
    return md5(serialize($this));
  }
  /**
   * Merges existing properties with new ones
   * @param array
   */
  function import($values)
  {
    if(!is_array($values))
      return;

    foreach($values as $name => $value)
    {
      if(!$this->_isGuarded($name))
        $this->_setRaw($name, $value);
    }
  }
  /**
   * Exports all object properties as an array
   * @return array
   */
  function export()
  {
    $exported = array();
    foreach(get_object_vars($this) as $name => $var)
    {
      if(!$this->_isGuarded($name))
        $exported[$name] = $var;
    }
    return $exported;
  }

  /**
   * Checks if such property exists
   * Can be overriden in child classes like lmbActiveRecord
   * @return bool returns true even if attribute is null
   */
  function has($name)
  {
    return $this->_hasAttribute($name) || $this->_mapPropertyToMethod($name);
  }

  protected function _hasAttribute($name)
  {
    return property_exists($this, $name);
  }

  function getAttributesNames()
  {
    return array_keys($this->export());
  }

  /**
   * Removes specified property
   * @param string
   */
  function remove($name)
  {
    if($this->_hasAttribute($name) && !$this->_isGuarded($name))
      unset($this->$name);
  }

  /**
   * Removes all object properties
   */
  function reset()
  {
    foreach($this->getAttributesNames() as $name)
      unset($this->$name);
  }

  /**
   * Returns property value if it exists and not guarded.
   * Magically maps getter to fine-grained method if it exists, e.g. get('foo') => getFoo()
   * @param string property name
   * @return mixed|null
   */
  function get($name, $default = LIMB_UNDEFINED)
  {
    if($method = $this->_mapPropertyToMethod($name))
      return $this->$method();

    if($this->_hasAttribute($name) && !$this->_isGuarded($name))
      return $this->_getRaw($name);

    if(LIMB_UNDEFINED !== $default)
      return $default;
    
    throw new lmbNoSuchPropertyException("No such property '$name' in " . get_class($this));
{'fraction_non_alphanumeric': 0.1587195731910637, 'fraction_numerical': 0.007558074913860176, 'mean_word_length': 3.0568079350766455, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 87, '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': '2210884', 'n_tokens_mistral': 3025, 'n_tokens_neox': 2929, 'n_words': 765}