MediaSearch_Filter_KeyWords
[ class tree: MediaSearch_Filter_KeyWords ] [ index: MediaSearch_Filter_KeyWords ] [ all elements ]

Source for file BlackList.php

Documentation is available at BlackList.php

  1. <?php
  2. /**
  3.  * MediaSearch
  4.  *
  5.  * LICENSE
  6.  *
  7.  * "THE BEER-WARE LICENSE" (Revision 42):
  8.  * "Sven Strittmatter" <ausserirdisch@sven-space.de> wrote this file.
  9.  * As long as you retain this notice you can do whatever you want with
  10.  * this stuff. If we meet some day, and you think this stuff is worth it,
  11.  * you can buy me a beer in return.
  12.  *
  13.  * $Author$
  14.  * $Revision$
  15.  *
  16.  * @category    MediaSearch
  17.  * @package     MediaSearch_Filter_KeyWords
  18.  * @copyright   Copyright (c) 2009 Sven Strittmatter
  19.  */
  20.  
  21. /**
  22.  * @see MediaSearch_Filter_KeyWords_Interface
  23.  */
  24. require_once('MediaSearch/Filter/KeyWords/Interface.php');
  25. /**
  26.  * @see MediaSearch_ConfigLoader
  27.  */
  28. require_once('MediaSearch/ConfigLoader.php');
  29. /**
  30.  * @see MediaSearch_Config_ParseOptions_SplitTextByLineBreak
  31.  */
  32. require_once('MediaSearch/Config/ParseOptions/SplitTextByLineBreak.php');
  33.  
  34. /**
  35.  * Removes black listed key words loaded from a config.
  36.  *
  37.  * @category   MediaSearch
  38.  * @package    MediaSearch_Filter_KeyWords
  39.  * @copyright  Copyright (c) 2009 Sven Strittmatter
  40.  */
  41.     implements MediaSearch_Filter_KeyWords_Interface {
  42.  
  43.     const TRACE_LELVEL 31;
  44.  
  45.     /**
  46.      * Instance for singleton.
  47.      *
  48.      * @static
  49.      * @access private
  50.      * @var MediaSearch_Filter_KeyWords_BlackList 
  51.      */
  52.     private static $instance;
  53.     /**
  54.      * Holds the config with the black listed key words.
  55.      *
  56.      * @access private
  57.      * @var MediaSearch_Config_Text 
  58.      */
  59.     private $config;
  60.  
  61.     /**
  62.      * Loads the blcklist config.
  63.      *
  64.      * @access public
  65.      */
  66.     private function __construct({
  67.         $this->config MediaSearch_ConfigLoader::get('keywordfilter',
  68.             array(new MediaSearch_Config_ParseOptions_SplitTextByLineBreak()));
  69.     }
  70.  
  71.     /**
  72.      * Returns th einstance of this class.
  73.      *
  74.      * @static
  75.      * @access public
  76.      * @return MediaSearch_Filter_KeyWords_BlackList 
  77.      */
  78.     public static function get({
  79.         if (null === self::$instance{
  80.             self::$instance new MediaSearch_Filter_KeyWords_BlackList();
  81.         }
  82.  
  83.         return self::$instance;
  84.     }
  85.  
  86.     /**
  87.      * Removes all blacklisted key words (from the loaded config)
  88.      * from the passed input array.
  89.      *
  90.      * @access public
  91.      * @param array $input 
  92.      * @return array 
  93.      */
  94.     public function process(array $input{
  95.         $filtered  array();
  96.         $blackList $this->config->get();
  97.  
  98.         foreach ($input as $keyword{
  99.             if (in_array($keyword$blackList)) {
  100.                 continue;
  101.             }
  102.  
  103.             $filtered[$keyword;
  104.         }
  105.  
  106.         return $filtered;
  107.     }
  108. }

Documentation generated on Mon, 17 Aug 2009 14:51:40 +0200 by phpDocumentor 1.4.2