Example #1
0
 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;
 }
Example #2
0
 /**
  */
 public function isExecutable()
 {
     if (null === $this->x) {
         $this->x = parent::isExecutable();
     }
     return $this->x;
 }
Example #3
0
 /**
  * executes the synfony consile application
  */
 public function main()
 {
     $this->prepareCommand();
     $this->log("executing {$this->commandLine}");
     $composerFile = new SplFileInfo($this->getComposer());
     if (false === $composerFile->isExecutable() || false === $composerFile->isFile()) {
         throw new BuildException(sprintf('Composer binary not found, path is "%s"', $composerFile));
     }
     $return = 0;
     passthru($this->commandLine, $return);
     if ($return > 0) {
         throw new BuildException("Composer execution failed");
     }
 }
 protected function _checkPerms($path, $value)
 {
     if (!$path instanceof SplFileInfo) {
         try {
             $path = new SplFileInfo($path);
         } catch (Exception $e) {
             return false;
         }
     }
     // Get perms
     $perms = 0;
     if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN' || $path->isExecutable()) {
         $perms |= 0x1;
     }
     if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
         $value |= 0x1;
     }
     if ($path->isWritable()) {
         $perms |= 0x2;
     }
     if ($path->isReadable()) {
         $perms |= 0x4;
     }
     // Apply file umask to requested permission
     if ($path->isFile()) {
         $value &= ~$this->_fileUmask;
     }
     // Check
     if (($perms & $value) != $value) {
         return false;
     }
     // Recurse if necessary, and is directory
     if ($this->_recursive && $path->isDir()) {
         try {
             $it = new DirectoryIterator($path->getPathname());
         } catch (Exception $e) {
             // AFAIK this is caused by not having enough permissions
             return false;
         }
         foreach ($it as $fileinfo) {
             $flname = $fileinfo->getFilename();
             if ($fileinfo->isDot() || $flname[0] == '.' || $flname == 'CVS') {
                 continue;
             }
             if ($this->_ignoreFiles && $fileinfo->isFile()) {
                 continue;
             }
             if (!$this->_checkPerms($fileinfo, $value)) {
                 return false;
             }
         }
     }
     return true;
 }
Example #5
0
<?php

$info = new SplFileInfo('SplFileInfo.php');
printf("Extension: %s\n", $info->getExtension());
printf("Filename: %s\n", $info->getFilename());
printf("Path: %s\n", $info->getPathname());
printf("RealPath: %s\n", $info->getRealPath());
printf("Type: %s\n", $info->getType());
printf("Size: %s\n", $info->getSize());
printf("Dir: %b, Exec: %b, File: %b, Link: %b, R: %b, W: %b\n", $info->isDir(), $info->isExecutable(), $info->isFile(), $info->isLink(), $info->isReadable(), $info->isWritable());
$file = $info->openFile('r');
foreach ($file as $line) {
    printf("%s", $line);
}
Example #6
0
 /**
  * @depends     testExist
  * @return      void
  */
 public function testIsExecutable()
 {
     $filePath = __DIR__ . '/example.txt';
     $fileObject = new File($filePath);
     $result = $fileObject->isExecutable();
     $fileObject = new \SplFileInfo($filePath);
     $this->assertEquals($result, $fileObject->isExecutable());
 }
Example #7
0
 protected function getFileDetailsRawStatistic(\SplFileInfo $info, $fileGiven)
 {
     return ['File is Dir' => $info->isDir(), 'File is Executable' => $info->isExecutable(), 'File is File' => $info->isFile(), 'File is Link' => $info->isLink(), 'File is Readable' => $info->isReadable(), 'File is Writable' => $info->isWritable(), 'File Permissions' => $this->explainPerms($info->getPerms()), 'Size' => $info->getSize(), 'Sha1' => sha1_file($fileGiven), 'Timestamp Accessed' => $this->getFileTimes($info->getATime()), 'Timestamp Changed' => $this->getFileTimes($info->getCTime()), 'Timestamp Modified' => $this->getFileTimes($info->getMTime())];
 }