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

Source for file PathRemover.php

Documentation is available at PathRemover.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. /**
  27.  * Removes file name parts from the key word list.
  28.  *
  29.  * @category   MediaSearch
  30.  * @package    MediaSearch_Filter_KeyWords
  31.  * @copyright  Copyright (c) 2009 Sven Strittmatter
  32.  */
  33.       implements MediaSearch_Filter_KeyWords_Interface {
  34.  
  35.     const TRACE_LELVEL 33;
  36.  
  37.     /**
  38.      * The base path. Keywords generated by this path part
  39.      * will be removed.
  40.      *
  41.      * @static
  42.      * @access public
  43.      * @var string 
  44.      */
  45.     public static $basePath;
  46.     /**
  47.      * Instance for singleton.
  48.      *
  49.      * @static
  50.      * @access private
  51.      * @var MediaSearch_Filter_KeyWords_BlackList 
  52.      */
  53.     private static $instance;
  54.     /**
  55.      * The directory names extracted from $basePath.
  56.      *
  57.      * @access private
  58.      * @var array 
  59.      */
  60.     private $partsToRemove;
  61.  
  62.     /**
  63.      * Singleton inplementation (see GoF).
  64.      * Checks if the base pat hproperty was set before constructing.
  65.      * 
  66.      * @access private
  67.      */
  68.     private function __construct({
  69.         if (null === self::$basePath || empty(self::$basePath)) {
  70.             $message  'Please set MediaSearch_Filter_KeyWords_PathRemover::$basePath ';
  71.             $message .= 'to the directory path where you are scanning BEFORE ';
  72.             $message .= 'the first time use of this filter!';
  73.             throw new InvalidArgumentException($message);
  74.         }
  75.  
  76.         $this->partsToRemove explode(DIRECTORY_SEPARATORself::$basePath);
  77.     }
  78.  
  79.     /**
  80.      * Returns th einstance of this class.
  81.      *
  82.      * @static
  83.      * @access public
  84.      * @return MediaSearch_Filter_KeyWords_PathRemover 
  85.      */
  86.     public static function get({
  87.         if (null === self::$instance{
  88.             self::$instance new MediaSearch_Filter_KeyWords_PathRemover();
  89.         }
  90.  
  91.         return self::$instance;
  92.     }
  93.  
  94.     /**
  95.      * Removes all direcotry names occuring in $basePath from the keyword list.
  96.      *
  97.      * @access public
  98.      * @param array $input 
  99.      * @return array 
  100.      */
  101.     public function process(array $input{
  102.         $filtered array();
  103.  
  104.         foreach ($input as $keyword{
  105.             if (in_array($keyword$this->partsToRemove)) {
  106.                 continue;
  107.             }
  108.  
  109.             $filtered[$keyword;
  110.         }
  111.  
  112.         return $filtered;
  113.     }
  114. }

Documentation generated on Mon, 17 Aug 2009 14:53:41 +0200 by phpDocumentor 1.4.2