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

Source for file Visitor.php

Documentation is available at Visitor.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_File
  18.  * @copyright   Copyright (c) 2009 Sven Strittmatter
  19.  */
  20.  
  21. /**
  22.  * @see MediaSearch_Interface_Visitor
  23.  */
  24. require_once('MediaSearch/Interface/Visitor.php');
  25. /**
  26.  * @see MediaSearch_Scan_List
  27.  */
  28. require_once('MediaSearch/Scan/List.php');
  29. /**
  30.  * @see MediaSearch_Scan_FileMeta
  31.  */
  32. require_once('MediaSearch/Scan/FileMeta.php');
  33.  
  34. /**
  35.  * Visits a file tree (an object of type MediaSearch_File_Abstract)
  36.  * and colletcts informations into the MediaSearch_Scan_List object.
  37.  *
  38.  * This class is part of a visitor pattern implementation (see GoF).
  39.  *
  40.  * @category   MediaSearch
  41.  * @package    MediaSearch_File
  42.  * @copyright  Copyright (c) 2009 Sven Strittmatter
  43.  */
  44. class MediaSearch_File_Visitor implements MediaSearch_Interface_Visitor {
  45.     const TRACE_LELVEL 27;
  46.  
  47.     /**
  48.      * Holds the information collected by this visitor
  49.      * from a file tree.
  50.      *
  51.      * @access priate
  52.      * @var MediaSearch_Scan_List 
  53.      */
  54.     private $fileList;
  55.  
  56.     /**
  57.      * Generates the MediaSearch_Scan_List object we use to hold
  58.      * the collected informations from the file tree.
  59.      *
  60.      * @access public
  61.      */
  62.     public function __construct({
  63.         $this->fileList new MediaSearch_Scan_List();
  64.     }
  65.  
  66.     /**
  67.      * This method is called from the visited subjects to join the visiting.
  68.      *
  69.      * @access public
  70.      * @param MediaSearch_Interface_Visitable $visitingSubject 
  71.      */
  72.     public function visit(MediaSearch_Interface_Visitable $visitingSubject{
  73.         if (!$visitingSubject instanceof MediaSearch_File_Abstract{
  74.             $message 'This visitor can only visits objects of type File_Abstract';
  75.             throw new InvalidArgumentException($messgae);
  76.         }
  77.  
  78.         $visitingSubject->acceptVisitor($this);
  79.     }
  80.  
  81.     /**
  82.      * Adds a MediaSearch_Scan_FileMeta object to the scanned files list object.
  83.      * This is performed by the vissited subject while visiting it.
  84.      * 
  85.      * @access public
  86.      * @param SplFileInfo $fileInfo 
  87.      * @param int $type 
  88.      */
  89.     public function addScannedFile(SplFileInfo $fileInfo$type{
  90.         $this->fileList->add(new MediaSearch_Scan_FileMeta($fileInfo$type));
  91.     }
  92.  
  93.     /**
  94.      * Returns the scanned file list object with all
  95.      * collected data.
  96.      *
  97.      * @access public
  98.      * @return MediaSearch_Scan_List 
  99.      */
  100.     public function getFileList({
  101.         return $this->fileList;
  102.     }
  103. }

Documentation generated on Mon, 17 Aug 2009 14:54:27 +0200 by phpDocumentor 1.4.2