<commit_before><?php
/* This class is part of the XP framework
 *
 * $Id$ 
 */

  uses('XpProtocolHandler');

  /**
   * Handler factory implementation
   *
   * @see      xp://XpProtocolHandler
   * @purpose  Factory
   */
  class HandlerFactory extends Object {
  
    /**
     * Retrieve a handler for a given scheme
     *
     * @model   static
     * @access  public
     * @param   string scheme
     * @return  &ProtocolHandler
     */
    function &handlerFor($scheme) {
      sscanf($scheme, '%[^+]+%s', $type, $option);
      switch ($type) {
        case 'xp': return new XpProtocolHandler($option);
        default: return xp::null();
      }
    }
  }
?><commit_msg>- Add an api to register protocol handlers<commit_after><?php
/* This class is part of the XP framework
 *
 * $Id$ 
 */

  uses('XpProtocolHandler');

  /**
   * Handler factory implementation
   *
   * @see      xp://XpProtocolHandler
   * @purpose  Factory
   */
  class HandlerFactory extends Object {
  
    /**
     * Static initializer. Registers the default protocol "xp" with this
     * factory.
     *
     * @model   static
     * @access  public
     */
    function __static() {
      HandlerFactory::protocol('xp', XPClass::forName('XpProtocolHandler'));
    }
    
    /**
     * Register or retrieve protocol handlers for/by a specified type
     *
     * @access  public
     * @param   string type
     * @param   &XPClass handler a class representing a ProtocolHandler
     * @return  &ProtocolHandler
     */
    function &protocol($type, &$handler) {
      static $handlers= array();
      
      if (NULL !== $handler) $handlers[$type]= &$handler;
      if (!isset($handlers[$type])) return xp::null();
      return $handlers[$type];
    }
  
    /**
     * Retrieve a handler for a given scheme
     *
     * @model   static
     * @access  public
     * @param   string scheme
     * @return  &ProtocolHandler
     */
    function &handlerFor($scheme) {
      sscanf($scheme, '%[^+]+%s', $type, $option);
      
      $handler= &HandlerFactory::protocol($type, $handler= NULL);
      return $handler->newInstance($option);
    }
  }
?>
{'fraction_non_alphanumeric': 0.1351098644226274, 'fraction_numerical': 0.0, 'mean_word_length': 2.3126934984520124, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, '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': '5390176', 'n_tokens_mistral': 652, 'n_tokens_neox': 628, 'n_words': 170}