本文整理汇总了PHP中SplFileObject::getFilename方法的典型用法代码示例。如果您正苦于以下问题:PHP SplFileObject::getFilename方法的具体用法?PHP SplFileObject::getFilename怎么用?PHP SplFileObject::getFilename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SplFileObject
的用法示例。
在下文中一共展示了SplFileObject::getFilename方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getFilename
/**
* 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: find
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: onCreateArchive
/**
* @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: getImage
/**
* @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: __construct
public function __construct($filepath)
{
$file = new \SplFileObject($filepath);
$this->path = $file->getFilename();
while (!$file->eof()) {
$this->content .= $file->fgets();
}
}
示例6: buildRequestParams
/**
* @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: getModelClassHelperData
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: countLines
/**
* {@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: getRelativePath
/**
* 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: write
/**
* {@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: getFolders
$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: getFileName
/**
* Returns the current file name
*
* @return string
*/
public function getFileName()
{
return $this->file->getFilename();
}
示例13: getFilename
/**
* {@inheritdoc}
*/
public function getFilename()
{
return $this->file ? $this->file->getFilename() : null;
}
示例14: _getFile
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: SplFileObject
<?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==