Exemple #1
0
 /**
  * Validate Owner
  *
  * Checks to see if file owner setting matches expected
  *
  * @param SplFileInfo $file     File to check
  * @param array       $badFiles current array of bad files to report
  *
  * @return array
  * @access public
  */
 public function validateSetting(SplFileInfo $file, array $badFiles)
 {
     if (!empty($this->_targetOwner)) {
         //  Account for name and/or gid
         if (filter_var($this->_targetOwner, FILTER_VALIDATE_INT)) {
             $actualOwner = $file->getOwner();
         } else {
             $owner = posix_getpwuid($file->getOwner());
             $actualOwner = $owner['name'];
         }
         if ($actualOwner != $this->_targetOwner) {
             $path = substr_replace($file->__toString(), '', 0, strlen(Mage::getBaseDir()) + 1);
             $badFiles[$path]['owner'] = $actualOwner;
         }
     }
     return parent::validateSetting($file, $badFiles);
 }
Exemple #2
0
 /**
  * Returns the details about Communicator (current) file
  * w/o any kind of verification of file existance
  *
  * @param string $fileGiven
  * @return array
  */
 protected function getFileDetailsRaw($fileGiven)
 {
     $info = new \SplFileInfo($fileGiven);
     $aFileBasicDetails = ['File Extension' => $info->getExtension(), 'File Group' => $info->getGroup(), 'File Inode' => $info->getInode(), 'File Link Target' => $info->isLink() ? $info->getLinkTarget() : '-', 'File Name' => $info->getBasename('.' . $info->getExtension()), 'File Name w. Extension' => $info->getFilename(), 'File Owner' => $info->getOwner(), 'File Path' => $info->getPath(), 'Name' => $info->getRealPath(), 'Type' => $info->getType()];
     $aDetails = array_merge($aFileBasicDetails, $this->getFileDetailsRawStatistic($info, $fileGiven));
     ksort($aDetails);
     return $aDetails;
 }
 /**
  * @return array
  */
 public function toArray()
 {
     $rows = [];
     $currentDir = getcwd() . DIRECTORY_SEPARATOR;
     /* @var $reflection ReflectionFile  */
     foreach ($this->getIterator() as $reflection) {
         $row = [];
         $file = new \SplFileInfo($reflection->getName());
         $row = array("Files" => str_replace($currentDir, "", $file->getPathName()), "Owner" => $file->getOwner(), "Group" => $file->getGroup(), "Permissions" => $file->getPerms(), "Created" => date("d.m.Y h:m:s", $file->getCTime()), "Modified" => date("d.m.Y h:m:s", $file->getMTime()));
         $rows[] = $row;
     }
     return $rows;
 }
Exemple #4
0
                 }
             }
         } else {
             //TODO not sure if this is needed!
             if ($key != 'files' && $key != 'dirs') {
                 $f2s = $key . '/' . $val;
                 if (substr($f2s, -3) == 'php') {
                     $output .= 'File: ' . $f2s . PHP_EOL;
                 }
             }
         }
     }
 } else {
     $info = new SplFileInfo($o2s);
     $perms = substr(sprintf('%o', $info->getPerms()), -4);
     $owner = $info->getOwner();
     $group = $info->getGroup();
     $type = $info->getType();
     $size = $info->getSize();
     $scanner = new Scanner($o2s, $eol, $htmlMode, $scannerOptions);
     $scanner->scanFile("all", $patternData, $stringData);
     if (count($scanner->found)) {
         foreach ($scanner->found as $l) {
             $found .= $l;
         }
     } else {
         $found = '';
     }
     //make human readable size
     $size = $scanner->size_readable($size);
 }
 public function testDecoratedMethods()
 {
     $decorated = $this->getMockBuilder('hanneskod\\classtools\\Tests\\MockSplFileInfo')->setConstructorArgs([''])->getMock();
     $decorated->expects($this->once())->method('getRelativePath');
     $decorated->expects($this->once())->method('getRelativePathname');
     $decorated->expects($this->once())->method('getContents');
     $decorated->expects($this->once())->method('getATime');
     $decorated->expects($this->once())->method('getBasename');
     $decorated->expects($this->once())->method('getCTime');
     $decorated->expects($this->once())->method('getExtension');
     $decorated->expects($this->once())->method('getFileInfo');
     $decorated->expects($this->once())->method('getFilename');
     $decorated->expects($this->once())->method('getGroup');
     $decorated->expects($this->once())->method('getInode');
     $decorated->expects($this->once())->method('getLinkTarget');
     $decorated->expects($this->once())->method('getMTime');
     $decorated->expects($this->once())->method('getOwner');
     $decorated->expects($this->once())->method('getPath');
     $decorated->expects($this->once())->method('getPathInfo');
     $decorated->expects($this->once())->method('getPathname');
     $decorated->expects($this->once())->method('getPerms');
     $decorated->expects($this->once())->method('getRealPath');
     $decorated->expects($this->once())->method('getSize');
     $decorated->expects($this->once())->method('getType');
     $decorated->expects($this->once())->method('isDir');
     $decorated->expects($this->once())->method('isExecutable');
     $decorated->expects($this->once())->method('isFile');
     $decorated->expects($this->once())->method('isLink');
     $decorated->expects($this->once())->method('isReadable');
     $decorated->expects($this->once())->method('isWritable');
     $decorated->expects($this->once())->method('openFile');
     $decorated->expects($this->once())->method('setFileClass');
     $decorated->expects($this->once())->method('setInfoClass');
     $decorated->expects($this->once())->method('__toString')->will($this->returnValue(''));
     $fileInfo = new SplFileInfo($decorated);
     $fileInfo->getRelativePath();
     $fileInfo->getRelativePathname();
     $fileInfo->getContents();
     $fileInfo->getATime();
     $fileInfo->getBasename();
     $fileInfo->getCTime();
     $fileInfo->getExtension();
     $fileInfo->getFileInfo();
     $fileInfo->getFilename();
     $fileInfo->getGroup();
     $fileInfo->getInode();
     $fileInfo->getLinkTarget();
     $fileInfo->getMTime();
     $fileInfo->getOwner();
     $fileInfo->getPath();
     $fileInfo->getPathInfo();
     $fileInfo->getPathname();
     $fileInfo->getPerms();
     $fileInfo->getRealPath();
     $fileInfo->getSize();
     $fileInfo->getType();
     $fileInfo->isDir();
     $fileInfo->isExecutable();
     $fileInfo->isFile();
     $fileInfo->isLink();
     $fileInfo->isReadable();
     $fileInfo->isWritable();
     $fileInfo->openFile();
     $fileInfo->setFileClass();
     $fileInfo->setInfoClass();
     (string) $fileInfo;
 }
<?php

//file
$fileInfo = new SplFileInfo('not_existing');
var_dump($fileInfo->getOwner());
?>

Exemple #7
0
<?php

include __DIR__ . '/../../../test/sample_dir/fix_mtimes.inc';
$info = new SplFileInfo(__DIR__ . '/../../sample_dir');
if (!$info->isFile()) {
    echo $info->getRealPath();
}
$info = new SplFileInfo(__DIR__ . '/../../sample_dir/file');
var_dump($info->getbaseName());
var_dump($info->getbaseName('.cpp'));
$info->getCTime();
$info->getGroup();
$info->getInode();
$info->getMTime();
$info->getOwner();
$info->getPerms();
$info->getSize();
$info->getType();
$info->isDir();
$info->isFile();
$info->isLink();
$info->isReadable();
$info->isWritable();
 /**
  * @param SplFileInfo $file
  *
  * @return array
  */
 private function createFileResult(SplFileInfo $file)
 {
     $fileResult = array('path' => $this->replaceWindowsPath($this->getRelativePath($file->getRealPath(), ABSPATH)), 'pathEncoded' => false, 'isLink' => false, 'exists' => false, 'isDirectory' => false, 'owner' => 0, 'group' => 0, 'permissions' => 0);
     if (!seems_utf8($fileResult['path'])) {
         $fileResult['path'] = $this->pathEncode($fileResult['path']);
         $fileResult['pathEncoded'] = true;
     }
     try {
         $fileResult['link'] = $file->isLink();
         // need to be first
         $fileResult['size'] = $file->getSize();
         $fileResult['isDirectory'] = $file->isDir();
         $fileResult['owner'] = $file->getOwner();
         $fileResult['group'] = $file->getGroup();
         $fileResult['permissions'] = $file->getPerms();
         $fileResult['exists'] = true;
         if ($file->isLink()) {
             $fileResult['linkTarget'] = $file->getLinkTarget();
         }
     } catch (RuntimeException $e) {
     }
     return $fileResult;
 }
<?php

$filename = __DIR__ . "/SplFileInfo_getOwner_basic";
touch($filename);
$fileInfo = new SplFileInfo($filename);
$expected = fileowner($filename);
$actual = $fileInfo->getOwner();
var_dump($expected == $actual);
error_reporting(0);
$filename = __DIR__ . "/SplFileInfo_getOwner_basic";
unlink($filename);
Exemple #10
0
 /**
  * @depends     testExist
  * @return      void
  */
 public function testOwner()
 {
     $filePath = __DIR__ . '/example.txt';
     $fileObject = new File($filePath);
     $this->assertGreaterThanOrEqual(0, $fileObject->getOwner());
     $this->assertGreaterThan(0, strlen($fileObject->getOwnerName()));
     $fileObject = new \SplFileInfo($filePath);
     $this->assertGreaterThanOrEqual(0, $fileObject->getOwner());
 }