PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/addon/Zend/sfLuceneDirectoryStorage.class.php

https://bitbucket.org/anycode/sfluceneplugin
PHP | 80 lines | 36 code | 12 blank | 32 comment | 3 complexity | 33852da7ab0887debcbecc268972e262 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /*
  3. * This file is part of the sfLucenePlugin package
  4. * (c) 2007 - 2008 Carl Vondrick <carl@carlsoft.net>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. sfLuceneToolkit::loadZend();
  10. /**
  11. * symfony adapter for Zend_Search_Lucene_Storage_Directory_Filesystem to keep file
  12. * permissions sanes.
  13. * @package sfLucenePlugin
  14. * @subpackage Addon
  15. * @version SVN: $Id: sfLuceneDirectoryStorage.class.php 7108 2008-01-20 07:44:42Z Carl.Vondrick $
  16. */
  17. class sfLuceneDirectoryStorage extends Zend_Search_Lucene_Storage_Directory_Filesystem
  18. {
  19. public function __construct($path)
  20. {
  21. parent::__construct($path);
  22. sfLuceneStorageFilesystem::chmod($path, 0777);
  23. }
  24. /**
  25. * Creates a new, empty file in the directory with the given $filename.
  26. *
  27. * @param string $filename
  28. * @return Zend_Search_Lucene_Storage_File
  29. */
  30. public function createFile($filename)
  31. {
  32. if (isset($this->_fileHandlers[$filename])) {
  33. $this->_fileHandlers[$filename]->close();
  34. }
  35. unset($this->_fileHandlers[$filename]);
  36. $this->_fileHandlers[$filename] = new sfLuceneFileStorage($this->_dirPath . '/' . $filename, 'w+b');
  37. global $php_errormsg;
  38. $trackErrors = ini_get('track_errors'); ini_set('track_errors', '1');
  39. sfLuceneStorageFilesystem::chmod($this->_dirPath, 0777);
  40. ini_set('track_errors', $trackErrors);
  41. return $this->_fileHandlers[$filename];
  42. }
  43. /**
  44. * Returns a Zend_Search_Lucene_Storage_File object for a given $filename in the directory.
  45. *
  46. * If $shareHandler option is true, then file handler can be shared between File Object
  47. * requests. It speed-ups performance, but makes problems with file position.
  48. * Shared handler are good for short atomic requests.
  49. * Non-shared handlers are useful for stream file reading (especial for compound files).
  50. *
  51. * @param string $filename
  52. * @param boolean $shareHandler
  53. * @return Zend_Search_Lucene_Storage_File
  54. */
  55. public function getFileObject($filename, $shareHandler = true)
  56. {
  57. $fullFilename = $this->_dirPath . '/' . $filename;
  58. if (!$shareHandler) {
  59. return new sfLuceneFileStorage($fullFilename);
  60. }
  61. if (isset( $this->_fileHandlers[$filename] )) {
  62. $this->_fileHandlers[$filename]->seek(0);
  63. return $this->_fileHandlers[$filename];
  64. }
  65. $this->_fileHandlers[$filename] = new sfLuceneFileStorage($fullFilename);
  66. return $this->_fileHandlers[$filename];
  67. }
  68. }