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

Source for file FileMeta.php

Documentation is available at FileMeta.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_Scan
  18.  * @copyright   Copyright (c) 2009 Sven Strittmatter
  19.  */
  20.  
  21. /**
  22.   * @todo Write apidoc.
  23.   *
  24.   * @category   MediaSearch
  25.   * @package    MediaSearch_Scan
  26.   * @copyright  Copyright (c) 2009 Sven Strittmatter
  27.   */
  28.     const TRACE_LEVEL 49;
  29.  
  30.     protected $fileType;
  31.     protected $fileName;
  32.     protected $filePath;
  33.     protected $fileSize;
  34.     protected $modificationDate;
  35.     protected $creationDate;
  36.     protected $keyWords;
  37.     protected $keyWordsFilterChain;
  38.  
  39.     public function __construct(SplFileInfo $fileInfo null$fileType MediaSearch_File_File::TYPE_UNKNOW{
  40.         $this->keyWordsFilterChain = new MediaSearch_Filter_KeyWords_Chain();
  41.  
  42.         if (null !== $fileInfo{
  43.             MediaSearch_Log::trace('Constructing Scan_FileMeta from file info.'self::TRACE_LEVEL);
  44.             $this->keyWordsFilterChain->addFilter(MediaSearch_Filter_KeyWords_PathRemover::get());
  45.             $this->keyWordsFilterChain->addFilter(MediaSearch_Filter_KeyWords_Trim::get());
  46.             $this->keyWordsFilterChain->addFilter(MediaSearch_Filter_KeyWords_RemoveNumbers::get());
  47.             $this->keyWordsFilterChain->addFilter(MediaSearch_Filter_KeyWords_RemoveShortStrings::get());
  48.             $this->keyWordsFilterChain->addFilter(MediaSearch_Filter_KeyWords_ToLowerCase::get());
  49.             $this->keyWordsFilterChain->addFilter(MediaSearch_Filter_KeyWords_RemoveDuplicates::get());
  50.             $this->fileType = $fileType;
  51.             $this->fileName = $fileInfo->getFilename();
  52.             $this->filePath = $fileInfo->getPath();
  53.             $this->fileSize = $fileInfo->getSize();
  54.             $this->modificationDate = $fileInfo->getMTime();
  55.             $this->creationDate     = $fileInfo->getCTime();
  56.             $this->keyWords         = array();
  57.             $this->generateKeyWords($fileInfo->getPathname());
  58.         }
  59.     }
  60.  
  61.     private function generateKeyWords($filePath{
  62.         $pattern '/[\s,._\-\/\(\)\'\"]+/';
  63.         $keywords preg_split($pattern,
  64.             MediaSearch_File_Util::stripExtension($filePath),
  65.             -1,
  66.             PREG_SPLIT_NO_EMPTY);
  67.         $this->keyWords = $this->keyWordsFilterChain->process($keywords);
  68.         sort($this->keyWordsSORT_STRING);
  69.     }
  70.  
  71.     public function __toString({
  72.         $return  $this->filePath . '/' $this->fileName;
  73.         $return .= ' (type: '$this->fileType . ' size: ' $this->fileSize . ')';
  74.         $return .= "\n";
  75.         $return .= 'created: ' $this->creationDate;
  76.         $return .= "\n";
  77.         $return .= 'modified: ' $this->modificationDate;
  78.         $return .= "\n";
  79.         $return .= 'keywords: ' implode(', '$this->keyWords);
  80.  
  81.         return $return;
  82.     }
  83.  
  84.     public function fromObject(MediaSearch_Model_FileMeta $data{
  85.        $this->fileType = $data->getFileType();
  86.        $this->fileName = $data->getFileName();
  87.        $this->filePath = $data->getFilePath();
  88.        $this->fileSize =  $data->getFileSize();
  89.        $this->keyWords = explode(','$data->getKeyWords());
  90.        $this->modificationDate = $data->getModificationDate();
  91.        $this->creationDate     =  $data->getModificationDate();
  92.     }
  93.  
  94.     public function toArray($implodeKeyWords true{
  95.         return array(
  96.             'fileType' => $this->fileType,
  97.             'fileName' => $this->fileName,
  98.             'filePath' => $this->filePath,
  99.             'fileSize' => $this->fileSize,
  100.             'modificationDate' => $this->modificationDate,
  101.             'creationDate' => $this->creationDate,
  102.             'keyWords' => ($implodeKeyWords implode(','$this->keyWords$this->keyWords)
  103.         );
  104.     }
  105. }

Documentation generated on Mon, 17 Aug 2009 14:52:42 +0200 by phpDocumentor 1.4.2