Пример #1
0
 /**
  * Current.
  * Please, see \FileSystemIterator::current() method.
  *
  * @return  mixed
  */
 public function current()
 {
     $out = parent::current();
     if (null !== $this->_splFileInfoClass && $out instanceof \SplFileInfo) {
         $out->setInfoClass($this->_splFileInfoClass);
         $out = $out->getFileInfo();
     }
     return $out;
 }
Пример #2
0
 /**
  * Get pathname and create a DataFile object
  *
  * @return \CastlePointAnime\Brancher\Twig\DataFile
  */
 public function current()
 {
     $pathname = parent::current();
     $relPathname = rtrim($this->filesystem->makePathRelative($pathname, $this->root), '/');
     if (is_dir($pathname)) {
         return new self($this->filesystem, $this->parser, $this->root, "{$relPathname}/");
     } else {
         return new DataFile($this->parser, $pathname, $relPathname);
     }
 }
Пример #3
0
 /**
  * Overwrites \FilesystemIterator::current() to return an instance of 
  * \Phig\MigrationStep
  * @return \Phig\MigrationStep
  */
 public function current()
 {
     return new MigrationStep(parent::current()->getPathname());
 }
 /**
  * Overwriting the default `current()` method to return a `WebFileInfo` object if so
  *
  * If the flag `CURRENT_AS_WEBFILEINFO` is active, this will return a `WebFileInfo` object.
  *
  * @return mixed The value of the current iteration, as a `WebFileInfo` object if requested or as the default result of the parent's method
  */
 public function current()
 {
     if ($this->getFlags() & WebFilesystemIterator::CURRENT_AS_WEBFILEINFO) {
         /*
                     if ($this->isLink()) {
                         return new WebFileInfo($this->getPathname());
                     } else {
                         $realpath = $this->getRealPath();
                         $path = $this->getPathname();
                         return new WebFileInfo($path, str_replace($path, '', $realpath));
                     }
         */
         return new WebFileInfo(DirectoryHelper::slashDirname($this->original_path) . $this->getFilename());
     }
     return parent::current();
 }
Пример #5
0
    $fi = new FilesystemIterator("/var/spool/asterisk/outgoing_done/", FilesystemIterator::SKIP_DOTS);
    //printf("There were %d Files", iterator_count($fi));
    return iterator_count($fi);
}
while (true) {
    $i++;
    $iterator = new \FilesystemIterator($dir);
    $isDirEmpty = !$iterator->valid();
    $filesToProcess = array();
    $filesProcessed = array();
    if (!$isDirEmpty) {
        //echo "$i. Dir is not empty!\n";
        //fputs($log,"Dir is not empty");
        $currentFileIdx = 0;
        foreach ($iterator as $fileinfo) {
            echo $iterator->current() . "\n";
            $filesToProcess[] = $iterator->current();
            $currentFileIdx++;
            $asterCurrentCallFiles = countAsteriskOutgoing();
            $parsedParams = explode("_", $iterator);
            $memberID = $parsedParams[1];
            $jobTemplateID = $parsedParams[2];
            $deviceID = $parsedParams[3];
            $cmdID = $parsedParams[4];
            $cmdTimestamp = $parsedParams[5];
            if (countAsteriskOutgoing() < $chanLimit) {
                fputs($log, "Trying to move " . $iterator->current() . " to /var/spool/asterisk/outgoing/\n");
                //echo "Trying to move ".$iterator->current()." to /var/spool/asterisk/outgoing/\n";
                exec('mv ' . $iterator->current() . ' /var/spool/asterisk/outgoing/');
                $sql = "UPDATE sshManagerQueue\n\t\t    \t\tSET cmdOutput ='Asterisk: calling...',\n\t\t    \t\t    cmdTimestamp = UNIX_TIMESTAMP()\n\t\t\t\tWHERE memberID = '" . $memberID . "' AND\n\t\t\t\t      deviceID = '" . $deviceID . "' AND\n\t\t\t\t      jobTemplateID = '" . $jobTemplateID . "' AND\n\t\t\t\t      cmdID = '" . $cmdID . "'\n\t\t    \t\t";
                if ($jobTemplateID == "0") {
Пример #6
0
 /**
  * Extracts the compressed file and copies the files from the root directory
  * only if the compressed file contains a single directory.
  * @param string                 $file   Compressed file.
  * @param string                 $path   Destination path.
  * @param Format\FormatInterface $format Format.
  *
  * @throws Exception\IO\Input\FileEmptyException
  * @throws Exception\IO\Input\FileFormatNotSupportedException
  * @throws Exception\IO\Input\FileNotFoundException
  * @throws Exception\IO\Input\FileNotReadableException
  * @throws Exception\IO\Output\NotSingleDirectoryException
  * @throws Exception\IO\Output\TargetDirectoryNotWritableException
  *
  * @return bool
  */
 public function extractWithoutRootDirectory($file, $path, FormatInterface $format = null)
 {
     $this->initializeIfNotInitialized();
     // extract to a temporary place
     $tempDirectory = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid(time()) . DIRECTORY_SEPARATOR;
     $this->extract($file, $tempDirectory, $format);
     // move directory
     $iterator = new \FilesystemIterator($tempDirectory, \FilesystemIterator::SKIP_DOTS);
     $hasSingleRootDirectory = true;
     $singleRootDirectoryName = null;
     $numberDirectories = 0;
     while ($iterator->valid() && $hasSingleRootDirectory) {
         $uncompressedResource = $iterator->current();
         if (false === $uncompressedResource->isDir()) {
             $hasSingleRootDirectory = false;
         }
         $singleRootDirectoryName = $uncompressedResource->getRealPath();
         $numberDirectories++;
         if ($numberDirectories > 1) {
             $hasSingleRootDirectory = false;
         }
         $iterator->next();
     }
     if (false === $hasSingleRootDirectory) {
         // it is not a compressed file with a single directory
         $this->filesystem->remove($tempDirectory);
         throw new Exception\IO\Output\NotSingleDirectoryException($file);
     }
     $workingDirectory = getcwd();
     if ($workingDirectory === realpath($path)) {
         if (dirname($workingDirectory) === $workingDirectory) {
             // root directory
             throw new TargetDirectoryNotWritableException($workingDirectory);
         }
         chdir(dirname($workingDirectory));
         $sfFilesystem = new SfFilesystem();
         $filesRemove = new \FilesystemIterator($workingDirectory, \FilesystemIterator::SKIP_DOTS);
         $sfFilesystem->remove($filesRemove);
         $sfFilesystem->mirror($singleRootDirectoryName, $workingDirectory);
         chdir($workingDirectory);
     } else {
         $this->filesystem->remove($path);
         $this->filesystem->rename($singleRootDirectoryName, $path);
     }
     return true;
 }
Пример #7
0
<?php

$sample_dir = __DIR__ . '/../../sample_dir';
$iterator = new FilesystemIterator($sample_dir, FilesystemIterator::CURRENT_AS_PATHNAME);
$ret = array();
foreach ($iterator as $fileinfo) {
    $ret[] = $iterator->current();
}
asort($ret);
var_dump(array_values($ret));
Пример #8
0
 /**
  * {@inheritdoc}
  */
 public function extract($source, $target, FormatChainInterface $chainFormat)
 {
     $chainFormats = $chainFormat->getChainFormats();
     foreach ($chainFormats as $format) {
         if (false === $this->supportChecker->isFormatSupported($format)) {
             throw new FileFormatNotSupportedException($source, $format);
         }
     }
     $success = true;
     $lastFile = $source;
     $tempDirectories = [];
     for ($i = 0, $formatsCount = count($chainFormats); $i < $formatsCount && true === $success; $i++) {
         if ($i + 1 === $formatsCount) {
             // last
             $success = $this->extractFormat($lastFile, $target, $chainFormats[$i]);
         } else {
             $tempDirectory = $target . DIRECTORY_SEPARATOR . 'step_' . $i;
             $tempDirectories[] = $tempDirectory;
             $success = $this->extractFormat($lastFile, $tempDirectory, $chainFormats[$i]);
             // look for the uncompressed file
             $iterator = new \FilesystemIterator($tempDirectory, \FilesystemIterator::SKIP_DOTS);
             $extractedFile = null;
             while ($iterator->valid()) {
                 $extractedFile = $iterator->current();
                 $iterator->next();
             }
             if (null === $extractedFile) {
                 throw new FileCorruptedException($lastFile);
             }
             $lastFile = $extractedFile->getRealPath();
         }
     }
     // clean temp directories
     foreach ($tempDirectories as $directory) {
         $this->filesystem->remove($directory);
     }
     return $success;
 }