コード例 #1
0
 /**
  * Returns the source filename for where the comment block was located
  *
  * @return string
  */
 public function getFilename()
 {
     if ($this->file === null) {
         return '';
     }
     return $this->file->getFilename();
 }
コード例 #2
0
ファイル: FileHelper.php プロジェクト: oyoy8629/yii-core
 public static function find($fileArray)
 {
     $return = [];
     foreach ($fileArray as $file) {
         $file = new \SplFileObject($file);
         $return[] = substr($file->getFilename(), 0, strlen($file->getFilename()) - (strlen($file->getExtension()) + 1));
     }
     return $return;
 }
コード例 #3
0
 /**
  * @param ExportEventInterface $event
  * @throws CloseArchiveException
  * @throws OpenArchiveException
  * @throws UnavailableArchiveException
  */
 public function onCreateArchive(ExportEventInterface $event)
 {
     $archiveName = (string) Uuid::uuid1();
     $projectRootDir = realpath($this->projectRootDir);
     $archivePath = realpath($this->archiveDir) . '/' . $archiveName . '.zip';
     $archive = $this->openArchive($archivePath);
     foreach ($this->exportedCollection as $exportable) {
         if ($exportable instanceof ExportableInterface) {
             $exportPath = $projectRootDir . '/' . $exportable->getExportDestination();
             if (file_exists($exportPath)) {
                 $exportFile = new \SplFileObject($exportPath);
                 $archive->addFile($exportPath, $exportFile->getFilename());
             } else {
                 $this->logger->error(sprintf('Could not find export at "%s"', $exportPath));
                 // TODO Emit ErrorEvent to be handled later on for more robustness
                 continue;
             }
         }
     }
     $this->closeArchive($archive, $archivePath);
     if ($event instanceof JobAwareEventInterface) {
         if (!file_exists($archivePath)) {
             throw new UnavailableArchiveException(sprintf('Could not find archive at "%s"', $archivePath), UnavailableArchiveException::DEFAULT_CODE);
         }
         /** @var \WeavingTheWeb\Bundle\ApiBundle\Entity\Job $job */
         $job = $event->getJob();
         $archiveFile = new \SplFileObject($archivePath);
         $filename = str_replace('.zip', '', $archiveFile->getFilename());
         $router = $this->router;
         $getArchiveUrl = $this->router->generate('weaving_the_web_api_get_archive', ['filename' => $filename], $router::ABSOLUTE_PATH);
         $job->setOutput($getArchiveUrl);
     }
     $this->exportedCollection = [];
 }
コード例 #4
0
ファイル: ImageCommand.php プロジェクト: Eraac/TP-Blog
 /**
  * @param string $filename
  * @param string $name
  * @return string
  */
 private function getImage($filename, $name)
 {
     $path = $this->getContainer()->getParameter("upload_dir") . "images/post/";
     $file = new \SplFileObject($path . $name, "w");
     $file->fwrite(file_get_contents($filename));
     return $file->getFilename();
 }
コード例 #5
0
 public function __construct($filepath)
 {
     $file = new \SplFileObject($filepath);
     $this->path = $file->getFilename();
     while (!$file->eof()) {
         $this->content .= $file->fgets();
     }
 }
コード例 #6
0
ファイル: ImportBatch.php プロジェクト: vindi/vindi-php
 /**
  * @param \SplFileObject $file
  * @param array $options
  *
  * @return array
  */
 private function buildRequestParams(\SplFileObject $file, array $options)
 {
     $multipart = [['name' => 'batch', 'contents' => $file, 'filename' => $file->getFilename()]];
     foreach ($options as $key => $value) {
         $multipart[] = ['name' => $key, 'contents' => $value];
     }
     return compact('multipart');
 }
コード例 #7
0
ファイル: Generator.php プロジェクト: oyoy8629/yii-core
 public function getModelClassHelperData()
 {
     $paths = $this->modelsPath;
     $paths = array_unique($paths);
     $return = [];
     foreach ($paths as $path) {
         $namespace = str_replace(["@", "/"], ["\\", "\\"], $path);
         $realPath = Yii::getAlias($path);
         $files = \app\core\helpers\FileHelper::findFiles($realPath, ['only' => ['*.php'], 'except' => ['*Search.php', '*Query.php', '*Form.php']]);
         foreach ($files as $file) {
             $file = new \SplFileObject($file);
             $className = substr($file->getFilename(), 0, strlen($file->getFilename()) - (strlen($file->getExtension()) + 1));
             $class = new \ReflectionClass($namespace . '\\' . $className);
             $return[ltrim($namespace, '\\')][$class->getShortName() . "|" . Inflector::camel2id($class->getShortName())] = $class->getName();
         }
     }
     return $return;
 }
コード例 #8
0
ファイル: SimpleWalker.php プロジェクト: Babacooll/TextFile
 /**
  * {@inheritdoc}
  */
 public function countLines(\SplFileObject $file)
 {
     // Refresh file size
     clearstatcache($file->getFilename());
     $previous = $file->key();
     $file->seek($file->getSize());
     $count = $file->key();
     $file->seek($previous);
     return $count;
 }
コード例 #9
0
ファイル: PathResolver.php プロジェクト: WeavingTheWeb/devobs
 /**
  * Returns the relative path of a file or a symlink in a seamless way (relatively to the project root dir)
  *
  * @param $filePath
  * @return string
  */
 public function getRelativePath($filePath)
 {
     if (!file_exists($filePath)) {
         $this->raiseFileNotExistException($filePath);
     }
     $parentDirName = basename(dirname($filePath));
     $parentDir = dirname(dirname($filePath));
     $fileObject = new \SplFileObject($filePath);
     $filename = $fileObject->getFilename();
     $relativeGrandParentDir = strtr(realpath($parentDir), [realpath($this->projectRootDir) . '/' => '', realpath($this->logsDir . '/../..') . '/' => '']);
     $relativePath = $relativeGrandParentDir . '/' . $parentDirName . '/' . $filename;
     $this->logger->info(sprintf('Returning "%s" as relative path for "%s"', $relativePath, $filePath));
     return $relativePath;
 }
コード例 #10
0
 /**
  * {@inheritdoc}
  */
 public function write(\SplFileObject $file, $text, $newLineAtEnd = false)
 {
     $originalSeek = $file->ftell();
     // Refresh file size
     clearstatcache($file->getFilename());
     if ($file->getSize() - $file->ftell() > 0) {
         $contentAfter = $file->fread($file->getSize() - $file->ftell());
     } else {
         $contentAfter = '';
     }
     $file->fseek($originalSeek);
     $file->fwrite($text . ($newLineAtEnd ? PHP_EOL : ''));
     $file->fwrite($contentAfter);
     return $file;
 }
コード例 #11
0
ファイル: vmanipulate.php プロジェクト: Ibrahim1/aec
$stddirs[] = $path;
$stddirs = vTranslate::getFolders($path, $stddirs);
// Convert EVERYTHINGWOOOOOT
foreach ($stddirs as $sourcedir) {
    vTranslate::log("Processing: " . $sourcedir . "\n", $log);
    $targetpath = str_replace($path, $temppath, $sourcedir);
    if (!is_dir($targetpath)) {
        mkdir($targetpath);
    }
    $files = vTranslate::getFiles($sourcedir);
    foreach ($files as $f) {
        $file = new SplFileObject($sourcedir . '/' . $f);
        $targetfile = new SplFileObject($targetpath . '/' . $f, 'w');
        while (!$file->eof()) {
            $line = $file->fgets();
            if (strpos($file->getFilename(), '.ini')) {
                if (strpos($line, '_') === 0) {
                    $line = substr($line, 1);
                }
            } elseif (strpos($file->getFilename(), '.php')) {
                $line = str_replace("JText::_('_", "JText::_('", $line);
            }
            $targetfile->fwrite($line);
        }
    }
}
// et voilà
vTranslate::log("All done." . "\n\n", $log);
class vTranslate
{
    public function getFolders($path, $list = array(), $other = false)
コード例 #12
0
 /**
  * Returns the current file name
  *
  * @return string
  */
 public function getFileName()
 {
     return $this->file->getFilename();
 }
コード例 #13
0
 /**
  * {@inheritdoc}
  */
 public function getFilename()
 {
     return $this->file ? $this->file->getFilename() : null;
 }
コード例 #14
0
ファイル: Cheryl.php プロジェクト: pinoaffe/cheryl
 private function _getFile($download = false)
 {
     if (!$this->authed && !$this->config->readonly) {
         echo json_encode(array('status' => false, 'message' => 'not authenticated'));
         exit;
     }
     if (!$this->requestDir || !is_file($this->requestDir)) {
         header('Status: 404 Not Found');
         header('HTTP/1.0 404 Not Found');
         exit;
     }
     $file = new SplFileObject($this->requestDir);
     // not really sure if this range shit works. stole it from an old script i wrote
     if (isset($_SERVER['HTTP_RANGE'])) {
         list($size_unit, $range_orig) = explode('=', $_SERVER['HTTP_RANGE'], 2);
         if ($size_unit == 'bytes') {
             list($range, $extra_ranges) = explode(',', $range_orig, 2);
         } else {
             $range = '';
         }
         if ($range) {
             list($seek_start, $seek_end) = explode('-', $range, 2);
         }
         $seek_end = empty($seek_end) ? $size - 1 : min(abs(intval($seek_end)), $size - 1);
         $seek_start = empty($seek_start) || $seek_end < abs(intval($seek_start)) ? 0 : max(abs(intval($seek_start)), 0);
         if ($seek_start > 0 || $seek_end < $size - 1) {
             header('HTTP/1.1 206 Partial Content');
         } else {
             header('HTTP/1.1 200 OK');
         }
         header('Accept-Ranges: bytes');
         header('Content-Range: bytes ' . $seek_start . '-' . $seek_end . '/' . $size);
         $contentLength = $seek_end - $seek_start + 1;
     } else {
         header('HTTP/1.1 200 OK');
         header('Accept-Ranges: bytes');
         $contentLength = $file->getSize();
     }
     header('Pragma: public');
     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
     header('Date: ' . date('r'));
     header('Last-Modified: ' . date('r', $file->getMTime()));
     header('Content-Length: ' . $contentLength);
     header('Content-Transfer-Encoding: binary');
     if ($download) {
         header('Content-Disposition: attachment; filename="' . $file->getFilename() . '"');
         header('Content-Type: application/force-download');
     } else {
         header('Content-Type: ' . mime_content_type($file->getPathname()));
     }
     // i wrote this freading a really long time ago but it seems to be more robust than SPL. someone correct me if im wrong
     $fp = fopen($file->getPathname(), 'rb');
     fseek($fp, $seek_start);
     while (!feof($fp)) {
         set_time_limit(0);
         print fread($fp, 1024 * 8);
         flush();
         ob_flush();
     }
     fclose($fp);
     exit;
 }
コード例 #15
0
ファイル: fileobject_004.php プロジェクト: badlamer/hhvm
<?php

set_include_path('tests');
chdir(dirname(dirname(__FILE__)));
// ext/spl
$fo = new SplFileObject('fileobject_004.phpt', 'r', true);
var_dump($fo->getPath());
var_dump($fo->getFilename());
var_dump($fo->getRealPath());
?>
==DONE==
コード例 #16
0
ファイル: Perspective.php プロジェクト: WeavingTheWeb/devobs
 /**
  * @return string
  * @throws \Exception
  */
 public function getJsonFilename()
 {
     if ($this->type === self::TYPE_JSON && $this->status === self::STATUS_IMPORTABLE) {
         $fileObject = new \SplFileObject($this->getValue());
         return $fileObject->getFilename();
     } else {
         throw new \Exception('No JSON filename available for this perspective');
     }
 }