/**
  * Tests normal operation
  *
  * @requires PHP 5.3
  */
 public function testIteratingOverFilesFilteringIncactive()
 {
     $path = dirname(__FILE__) . '/test_files/fake_elgg/';
     require_once $path . 'engine/start.php';
     \code_review::initConfig(array('path' => $path, 'engine_path' => $path . 'engine/', 'pluginspath' => $path . 'mod/', 'plugins_getter' => array($this, 'mocked_plugins_getter')));
     $paths = array(array(dirname(__FILE__) . '/test_files/fake_elgg/', true), array(dirname(__FILE__) . '/test_files/fake_elgg' . DIRECTORY_SEPARATOR, true), array(dirname(__FILE__) . '/test_files/fake_elgg', true));
     foreach ($paths as $row) {
         list($path, $skipInactive) = $row;
         $config = new \CodeReview\Config(array('includeDisabledPlugins' => !$skipInactive));
         $baseFileInfo = new \SplFileInfo($path);
         $i = new \RecursiveDirectoryIterator($path);
         $i = new \RecursiveIteratorIterator($i, \RecursiveIteratorIterator::LEAVES_ONLY);
         $i = new \CodeReview\FileFilterIterator($i, $path, $config);
         $filesFound = array();
         /** @var $file \SplFileInfo */
         foreach ($i as $file) {
             $this->assertInstanceOf('\\SplFileInfo', $file);
             $this->assertNotEquals('.dummy_config', $file->getBasename());
             $entry = substr($file->getRealPath(), strlen($path));
             if ($entry) {
                 $entry = trim(str_replace('\\', '/', $entry), '/');
                 $filesFound[] = $entry;
             } else {
                 //we allow only root dir as exception
                 $this->assertEquals($baseFileInfo->getInode(), $file->getInode());
             }
         }
         $expected = array('engine/lib/deprecated-1.2.php', 'not_filtered_file', 'mod/ugly_plugin/start.php', 'mod/ugly_plugin/pages/page17.php', 'mod/ugly_plugin/manifest.xml');
         $missingFiles = array_diff($expected, $filesFound);
         $this->assertEquals($missingFiles, array(), "Missing expected files: " . print_r($missingFiles, true));
         $unexpected = array('.dummy_config', 'mod/inactive_plugin/start.php', 'mod/inactive_plugin/manifest.xml', 'vendor/unwanted_file', 'vendors/unwanted_file');
         $unwantedFiles = array_intersect($unexpected, $filesFound);
         $this->assertEquals($unwantedFiles, array(), "Got some unwanted files: " . print_r($unwantedFiles, true));
     }
 }
Example #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;
 }
<?php

//file
touch('SplFileInfo_getInode_basic.txt');
$fileInfo = new SplFileInfo('SplFileInfo_getInode_basic.txt');
$result = shell_exec('ls -i SplFileInfo_getInode_basic.txt');
var_dump($fileInfo->getInode() == $result);
unlink('SplFileInfo_getInode_basic.txt');
Example #4
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 #5
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();
<?php

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

Example #7
0
 /**
  * Implements module logic for given hook
  *
  * @param \AppserverIo\Psr\HttpMessage\RequestInterface          $request        A request object
  * @param \AppserverIo\Psr\HttpMessage\ResponseInterface         $response       A response object
  * @param \AppserverIo\Server\Interfaces\RequestContextInterface $requestContext A requests context instance
  * @param int                                                    $hook           The current hook to process logic for
  *
  * @return bool
  * @throws \AppserverIo\Server\Exceptions\ModuleException
  */
 public function process(RequestInterface $request, ResponseInterface $response, RequestContextInterface $requestContext, $hook)
 {
     // In php an interface is, by definition, a fixed contract. It is immutable.
     // So we have to declare the right ones afterwards...
     /**
      * @var $request \AppserverIo\Psr\HttpMessage\RequestInterface
      */
     /**
      * @var $response \AppserverIo\Psr\HttpMessage\ResponseInterface
      */
     // if false hook is coming do nothing
     if (ModuleHooks::REQUEST_POST !== $hook) {
         return;
     }
     // check if core module should still handle this request
     // maybe later on this can be overwritten by another core module for some reasons
     if ($requestContext->getServerVar(ServerVars::SERVER_HANDLER) !== self::MODULE_NAME) {
         // stop processing
         return;
     }
     // populates request context for possible script calling based on file handler configurations
     $this->populateRequestContext($requestContext);
     // check if file handler is not core module anymore
     if ($requestContext->getServerVar(ServerVars::SERVER_HANDLER) !== self::MODULE_NAME) {
         // stop processing
         return;
     }
     // if existing file should be served
     if ($requestContext->hasServerVar(ServerVars::SCRIPT_FILENAME)) {
         $scriptFilename = $requestContext->getServerVar(ServerVars::SCRIPT_FILENAME);
         // get file info
         $fileInfo = new \SplFileInfo($scriptFilename);
         // build etag
         $eTag = sprintf('"%x-%x-%x"', $fileInfo->getInode(), $fileInfo->getSize(), (double) str_pad($fileInfo->getMTime(), 16, '0'));
         // set last modified header
         $response->addHeader(Protocol::HEADER_LAST_MODIFIED, gmdate(DATE_RFC822, $fileInfo->getMTime()));
         // set etag header
         $response->addHeader(Protocol::HEADER_ETAG, $eTag);
         // set correct mimetype header
         $response->addHeader(Protocol::HEADER_CONTENT_TYPE, MimeTypes::getMimeTypeByExtension($fileInfo->getExtension()));
         // caching checks
         if ($request->hasHeader(Protocol::HEADER_IF_NONE_MATCH) && $request->getHeader(Protocol::HEADER_IF_NONE_MATCH) === $eTag) {
             // set not modified status without content
             $response->setStatusCode(304);
         } else {
             // serve file by set body stream to file descriptor stream
             $response->setBodyStream(fopen($scriptFilename, "r"));
         }
         // set response state to be dispatched after this without calling other modules process
         $response->setState(HttpResponseStates::DISPATCH);
         // if we got here its maybe a directory index surfing request if $validDir is same as uri
         // todo: implement directory index view and surfing
     } else {
         // for now we will throw a 404 as well here for non existing index files in directory
         throw new ModuleException(sprintf("The requested URL %s was not found on this server.", parse_url($requestContext->getServerVar(ServerVars::X_REQUEST_URI), PHP_URL_PATH)), 404);
     }
 }