<commit_before><?php namespace util;

use lang\ElementNotFoundException;

/**
 * Property-Manager
 * 
 * Usage:
 * <code>
 *   PropertyManager::getInstance()->configure('etc');
 *
 *   // ... later on ...
 *   $prop= PropertyManager::getInstance()->getProperties('database');
 *  
 *   // $prop is now a util.Property object with the properties
 *   // from etc/database.ini
 * </code>
 *
 * @test      xp://net.xp_framework.unittest.util.PropertyManagerTest
 */
class PropertyManager extends \lang\Object {
  protected static $instance= null;
  protected $provider= [];

  static function __static() {
    self::$instance= new self();
  }
  
  /**
   * Constructor
   */
  protected function __construct() {
  }
  
  /**
   * Retrieve this property manager's instance
   * 
   * @return  util.PropertyManager
   */
  public static function getInstance() {
    return self::$instance;
  }

  /**
   * Configure this property manager
   *
   * @param   string path search path to the property files
   */
  public function configure($path) {
    $this->appendSource(new FilesystemPropertySource($path));
  }

  /**
   * Check if given source is new source
   *
   * @param   util.PropertySource source
   * @return  bool
   */
  public function hasSource(PropertySource $source) {
    return isset($this->provider[$source->hashCode()]);
  }

  /**
   * Append path to paths to search
   *
   * @param   util.PropertySource source
   * @return  util.PropertySource the added path
   */
  public function appendSource(PropertySource $source) {
    $this->provider[$source->hashCode()]= $source;
    return $source;
  }

  /**
   * Set path to paths to search
   *
   * @param   util.PropertySource[] source
   */
  public function setSources(array $sources) {
    $provider= $this->provider;
    $this->provider= [];
    try {
      foreach ($sources as $source) {
        $this->appendSource($source);
      }
    } catch (\lang\IllegalArgumentException $e) {
      $this->provider= $provider;
      throw $e;
    } catch (\Throwable $e) {
      $this->provider= $provider;
      throw $e;
    }
  }

  /**
   * Prepend path to paths to search<commit_msg>Catch any PHP exception inside setSources()<commit_after><?php namespace util;

use lang\ElementNotFoundException;

/**
 * Property-Manager
 * 
 * Usage:
 * <code>
 *   PropertyManager::getInstance()->configure('etc');
 *
 *   // ... later on ...
 *   $prop= PropertyManager::getInstance()->getProperties('database');
 *  
 *   // $prop is now a util.Property object with the properties
 *   // from etc/database.ini
 * </code>
 *
 * @test      xp://net.xp_framework.unittest.util.PropertyManagerTest
 */
class PropertyManager extends \lang\Object {
  protected static $instance= null;
  protected $provider= [];

  static function __static() {
    self::$instance= new self();
  }
  
  /**
   * Constructor
   */
  protected function __construct() {
  }
  
  /**
   * Retrieve this property manager's instance
   * 
   * @return  util.PropertyManager
   */
  public static function getInstance() {
    return self::$instance;
  }

  /**
   * Configure this property manager
   *
   * @param   string path search path to the property files
   */
  public function configure($path) {
    $this->appendSource(new FilesystemPropertySource($path));
  }

  /**
   * Check if given source is new source
   *
   * @param   util.PropertySource source
   * @return  bool
   */
  public function hasSource(PropertySource $source) {
    return isset($this->provider[$source->hashCode()]);
  }

  /**
   * Append path to paths to search
   *
   * @param   util.PropertySource source
   * @return  util.PropertySource the added path
   */
  public function appendSource(PropertySource $source) {
    $this->provider[$source->hashCode()]= $source;
    return $source;
  }

  /**
   * Set path to paths to search
   *
   * @param   util.PropertySource[] source
   */
  public function setSources(array $sources) {
    $provider= $this->provider;
    $this->provider= [];
    try {
      foreach ($sources as $source) {
        $this->appendSource($source);
      }
    } catch (\Exception $e) {
      $this->provider= $provider;
      throw $e;
    } catch (\Throwable $e) {
      $this->provider= $provider;
      throw $e;
    }
  }

  /**
   * Prepend path to paths to search
{'fraction_non_alphanumeric': 0.13785912882298423, 'fraction_numerical': 0.0, 'mean_word_length': 2.7703056768558953, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 31, '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': '6429015', 'n_tokens_mistral': 1282, 'n_tokens_neox': 1268, 'n_words': 324}