Пример #1
0
 /**
  * Checks whether a file resides within a real storage in local file system.
  * If no match is found, uid 0 is returned which is a fallback storage pointing to PATH_site.
  *
  * The file identifier is adapted accordingly to match the new storage's base path.
  *
  * @param string $localPath
  *
  * @return integer
  */
 protected function findBestMatchingStorageByLocalPath(&$localPath)
 {
     if ($this->localDriverStorageCache === NULL) {
         $this->initializeLocalStorageCache();
     }
     $bestMatchStorageUid = 0;
     $bestMatchLength = 0;
     foreach ($this->localDriverStorageCache as $storageUid => $basePath) {
         $matchLength = strlen(PathUtility::getCommonPrefix(array($basePath, $localPath)));
         $basePathLength = strlen($basePath);
         if ($matchLength >= $basePathLength && $matchLength > $bestMatchLength) {
             $bestMatchStorageUid = (int) $storageUid;
             $bestMatchLength = $matchLength;
         }
     }
     if ($bestMatchStorageUid !== 0) {
         $localPath = substr($localPath, $bestMatchLength);
     }
     return $bestMatchStorageUid;
 }
Пример #2
0
 /**
  * @param array $paths
  * @param string $expected
  * @dataProvider isCommonPrefixResolvedCorrectlyDataProvider
  * @test
  */
 public function isCommonPrefixResolvedCorrectly(array $paths, $expected)
 {
     $commonPrefix = \TYPO3\CMS\Core\Utility\PathUtility::getCommonPrefix($paths);
     $this->assertEquals($expected, $commonPrefix);
 }
Пример #3
0
 /**
  * Creates the log file with correct permissions
  * and parent directories, if needed
  *
  * @return void
  */
 protected function createLogFile()
 {
     if (file_exists($this->logFile)) {
         return;
     }
     $logFileDirectory = dirname($this->logFile);
     if (!@is_dir($logFileDirectory)) {
         GeneralUtility::mkdir_deep($logFileDirectory);
         // create .htaccess file if log file is within the site path
         if (PathUtility::getCommonPrefix([PATH_site, $logFileDirectory]) === PATH_site) {
             // only create .htaccess, if we created the directory on our own
             $this->createHtaccessFile($logFileDirectory . '/.htaccess');
         }
     }
     // create the log file
     GeneralUtility::writeFile($this->logFile, '');
 }