本文整理汇总了PHP中SplFileInfo类的典型用法代码示例。如果您正苦于以下问题:PHP SplFileInfo类的具体用法?PHP SplFileInfo怎么用?PHP SplFileInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SplFileInfo类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: isEmpty
/**
* Test is files or directories passed as arguments are empty.
* Only valid for regular files and directories.
*
* @param mixed $files String or array of strings of path to files and directories.
*
* @return boolean True if all arguments are empty. (Size 0 for files and no children for directories).
*/
public function isEmpty($files)
{
if (!$files instanceof \Traversable) {
$files = new \ArrayObject(is_array($files) ? $files : array($files));
}
foreach ($files as $file) {
if (!$this->exists($file)) {
throw new FileNotFoundException(null, 0, null, $file);
}
if (is_file($file)) {
$file_info = new \SplFileInfo($file);
if ($file_info->getSize() !== 0) {
return false;
}
} elseif (is_dir($file)) {
$finder = new Finder();
$finder->in($file);
$it = $finder->getIterator();
$it->rewind();
if ($it->valid()) {
return false;
}
} else {
throw new IOException(sprintf('File "%s" is not a directory or a regular file.', $file), 0, null, $file);
}
}
return true;
}
开发者ID:inetprocess,项目名称:libsugarcrm,代码行数:36,代码来源:Filesystem.php
示例2: setUp
/**
* {@inheritdoc}
*/
public function setUp()
{
parent::setUp();
$this->factory = new ProcessFactory('pwd');
$this->directory = \Mockery::mock(\SplFileInfo::class);
$this->directory->shouldReceive('__toString')->andReturn('/tmp');
}
开发者ID:epfremmer,项目名称:process-queue,代码行数:10,代码来源:ProcessManagerTest.php
示例3: fromProperty
/**
* @param \SplFileInfo $basePath
* @param Property $property
* @return self
*/
public static function fromProperty(\SplFileInfo $basePath, Property $property)
{
$filePath = sprintf(self::FILE_PATH_FORMAT, $basePath->getPathname(), $property);
$fileInfo = new \SplFileInfo($filePath);
$file = new PHPFile($fileInfo);
return new self($file, $property);
}
开发者ID:nick-jones,项目名称:php-ucd,代码行数:12,代码来源:PHPPropertyFile.php
示例4: generateSourceCode
protected function generateSourceCode(ParsedType $type, SourceBuffer $buffer, \SplFileInfo $file)
{
$extends = array_map(function ($t) {
return '\\' . ltrim($t, '\\');
}, $type->getExtends());
$extends = empty($extends) ? '' : implode(', ', $extends);
$implements = ['\\' . MergedSourceInterface::class];
// Double inclusion safeguard:
if ($type->isClass()) {
$safe1 = sprintf(' if(!class_exists(%s, false)) { ', var_export($type->getName(), true));
$safe2 = ' } ';
} elseif ($type->isInterface()) {
$safe1 = sprintf(' if(!interface_exists(%s, false)) { ', var_export($type->getName(), true));
$safe2 = ' } ';
} else {
$safe1 = sprintf(' if(!trait_exists(%s, false)) { ', var_export($type->getName(), true));
$safe2 = ' } ';
}
$generator = new SourceGenerator($buffer);
$generator->populateTypeMarker($type, ParsedType::MARKER_INTRODUCED_INTERFACES, implode(', ', $implements));
$generator->populateTypeMarker($type, ParsedType::MARKER_INTRODUCED_NAME, $type->getLocalName());
$generator->populateTypeMarker($type, ParsedType::MARKER_INTRODUCED_SUPERCLASS, $extends);
$generator->populateTypeMarker($type, ParsedType::MARKER_INTRODUCED_PREPENDED_CODE, $safe1);
$generator->populateTypeMarker($type, ParsedType::MARKER_INTRODUCED_EXTERNAL_CODE, $safe2);
$code = trim($generator->generateCode($file->getPathname(), dirname($file->getPathname())));
$code = preg_replace("'^<\\?(?:php)?'i", '', $code) . "\n";
return $code;
}
开发者ID:koolkode,项目名称:k2,代码行数:28,代码来源:IncludeCompiler.php
示例5: name
/**
* @param \SplFileInfo $file
*
* @return string
*/
public function name(\SplFileInfo $file)
{
if ($file instanceof UploadedFile) {
return $this->escape($file->getClientOriginalName());
}
return parent::name($file);
}
开发者ID:atom-azimov,项目名称:uploader-bundle,代码行数:12,代码来源:BasenameNamer.php
示例6: __construct
/**
* Stores the file object.
*
* @param \SplFileInfo $file The file object
*
* @throws \InvalidArgumentException If $file is not a file
*/
public function __construct(\SplFileInfo $file)
{
if (!$file->isFile()) {
throw new \InvalidArgumentException(sprintf('%s is not a file.', $file));
}
$this->file = $file;
}
开发者ID:bytehead,项目名称:core-bundle,代码行数:14,代码来源:HtaccessAnalyzer.php
示例7: createDirectory
/**
* Recursively create a directory if allowed.
*
* @param string $path The path to the directory which will be created.
* @param int $permissions The Unix permissions to set on the directory. Ignored
* on Windows machines.
*
* @return void
*
* @throws \LogicException if the directory already exists.
* @throws \UnexpectedValueException if the first existing parent directory in
* the $path argument is not readable or
* writable by the user running PHP.
* @throws \UnexpectedValueException when a recursive call to mkdir() with the
* given $path and $permissions arguments
* fails.
*/
function createDirectory($path, $permissions = 0755)
{
if (is_dir($path)) {
throw new \LogicException('De map "' . $path . '" bestaat al.', 2);
}
// Find the first parent directory and check its permissions.
$permission = false;
$parentPath = $path;
do {
$parentPath = explode(DIRECTORY_SEPARATOR, trim($parentPath, DIRECTORY_SEPARATOR));
$parentPathCount = count($parentPath);
unset($parentPath[--$parentPathCount]);
$parentPath = implode(DIRECTORY_SEPARATOR, $parentPath);
// Don't prepend the path with a directory separator on Windows.
// The drive letter, for example: "C:\", is enough.
if (PHP_OS !== 'Windows') {
$parentPath = DIRECTORY_SEPARATOR . $parentPath;
}
if (file_exists($parentPath)) {
$fileInfo = new \SplFileInfo($parentPath);
if ($fileInfo->isReadable() && $fileInfo->isWritable()) {
$permission = true;
break;
}
}
} while ($parentPathCount > 1);
if ($permission) {
if (!mkdir($path, $permissions, true)) {
throw new \UnexpectedValueException('De map "' . $path . '" kon niet aangemaakt worden.', 8);
}
} else {
throw new \UnexpectedValueException('De eerstvolgende bestaande map die boven "' . $path . '" ligt ' . 'is niet lees- of schrijfbaar.', 4);
}
}
开发者ID:BitmanNL,项目名称:traffictower-cms,代码行数:51,代码来源:createDirectory.php
示例8: supports
/**
* @param \SplFileInfo $data
* @return bool
*/
public function supports($data)
{
if (!$data instanceof \SplFileInfo) {
return false;
}
return strtolower($data->getExtension()) == "php";
}
开发者ID:sensiolabs-de,项目名称:astrunner,代码行数:11,代码来源:NikicPhpParser.php
示例9: load
/**
* Load all extension classes
*/
public function load()
{
$counter = 0;
foreach (glob(__DIR__ . '/Extension/*.php') as $filename) {
$file = new \SplFileInfo($filename);
$classname = $file->getBasename('.php');
$classpath = sprintf('%s\\Extension\\%s', __NAMESPACE__, $classname);
require_once $filename;
$extension = new \ReflectionClass($classpath);
$instance = $extension->newInstance($this->getParent());
foreach ($extension->getMethods() as $method) {
if (mb_substr($method->name, 0, 3) == 'FN_') {
$map = new \StdClass();
$map->class = $extension->getShortName();
$map->method = $method->name;
$map->instance = $instance;
$tag = sprintf('%s.%s', mb_strtolower($classname), mb_substr($method->name, 3));
$this->mapping[$tag] = $map;
}
}
$this->debug(__METHOD__, __LINE__, sprintf('Loaded extension: %s', $extension->getShortName()));
// save the instance
$this->instances[] = $instance;
$counter++;
}
return $counter;
}
开发者ID:g4z,项目名称:poop,代码行数:30,代码来源:ExtensionManager.php
示例10: __construct
function __construct(\SplFileInfo $file, $contentType, $filename = null, $fileExtension = null)
{
$this->file = $file;
$this->filename = $filename ?: $file->getBasename();
$this->contentType = $contentType;
$this->fileExtension = $fileExtension ?: $file->getExtension();
}
开发者ID:cwd,项目名称:TableBundle,代码行数:7,代码来源:Export.php
示例11: boot
/**
* The "booting" method of the model.
*
* @return void
*/
protected static function boot()
{
parent::boot();
static::saving(function (\Eloquent $model) {
// If a new download file is uploaded, could be create or edit...
$dirty = $model->getDirty();
if (array_key_exists('filename', $dirty)) {
$file = new \SplFileInfo($model->getAbsolutePath());
$model->filesize = $file->getSize();
$model->extension = strtoupper($file->getExtension());
// Now if editing only...
if ($model->exists) {
$oldFilename = self::where($model->getKeyName(), '=', $model->id)->first()->pluck('filename');
$newFilename = $dirty['filename'];
// Delete the old file if the filename is different to the new one, and it therefore hasn't been replaced
if ($oldFilename != $newFilename) {
$model->deleteFile($oldFilename);
}
}
}
// If a download is edited and the image is changed...
if (array_key_exists('image', $dirty) && $model->exists) {
$oldImageFilename = self::where($model->getKeyName(), '=', $model->id)->first()->pluck('image');
$model->deleteImageFiles($oldImageFilename);
}
});
static::deleted(function ($model) {
$model->deleteFile();
$model->deleteImageFiles();
});
}
开发者ID:fbf,项目名称:laravel-downloads,代码行数:36,代码来源:Download.php
示例12: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$filename = $input->getOption('filename');
if (!$filename) {
$resource = STDIN;
} else {
try {
$file = new \SplFileInfo($filename);
} catch (\Exception $e) {
throw new \InvalidArgumentException('Bad filename');
}
$resource = fopen($file->getRealPath(), 'rb');
}
$width = $input->getArgument('width');
$height = $input->getArgument('height');
$dim = $input->getArgument('dim');
if (!$width) {
$width = VisualizationEqualizer::WIDTH_DEFAULT;
}
if (!$height) {
$height = VisualizationEqualizer::HEIGHT_DEFAULT;
}
if (!$dim) {
$dim = VisualizationEqualizer::DIM_DEFAULT;
}
$render = new ConsoleRender($output);
$render->setDisplayColor(true);
$wavReader = new WavReader($resource, new Riff(), new Fmt(), new Data());
$visualizationEqualizer = new VisualizationEqualizer($resource, $dim, $wavReader, $render);
$visualizationEqualizer->run((int) $width, (int) $height);
}
开发者ID:Samovar,项目名称:fft-console,代码行数:34,代码来源:VisualizationEqualizerCommand.php
示例13: src
public function src($src, $ext = null)
{
if (!is_file($src)) {
throw new FileNotFoundException($src);
}
$this->src = $src;
if (!$ext) {
$info = new \SplFileInfo($src);
$this->ext = strtoupper($info->getExtension());
} else {
$this->ext = strtoupper($ext);
}
if (is_file($src) && ($this->ext == "JPG" or $this->ext == "JPEG")) {
$this->image = ImageCreateFromJPEG($src);
} else {
if (is_file($src) && $this->ext == "PNG") {
$this->image = ImageCreateFromPNG($src);
} else {
throw new FileNotFoundException($src);
}
}
$this->input_width = imagesx($this->image);
$this->input_height = imagesy($this->image);
return $this;
}
开发者ID:jilson-asis,项目名称:image-resize,代码行数:25,代码来源:ImageResizer.php
示例14: addFile
private function addFile(\Phar $phar, \SplFileInfo $file)
{
$path = str_replace(dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR, '', $file->getRealPath());
$content = file_get_contents($file);
$content = $this->stripWhitespace($content);
$phar->addFromString($path, $content);
}
开发者ID:bcncommerce,项目名称:magebuild,代码行数:7,代码来源:Compiler.php
示例15: fix
/**
* {@inheritdoc}
*/
public function fix(\SplFileInfo $file, Tokens $tokens)
{
$namespace = false;
$classyName = null;
$classyIndex = 0;
foreach ($tokens as $index => $token) {
if ($token->isGivenKind(T_NAMESPACE)) {
if (false !== $namespace) {
return;
}
$namespace = true;
} elseif ($token->isClassy()) {
if (null !== $classyName) {
return;
}
$classyIndex = $tokens->getNextMeaningfulToken($index);
$classyName = $tokens[$classyIndex]->getContent();
}
}
if (null === $classyName) {
return;
}
if (false !== $namespace) {
$filename = basename(str_replace('\\', '/', $file->getRealPath()), '.php');
if ($classyName !== $filename) {
$tokens[$classyIndex]->setContent($filename);
}
} else {
$normClass = str_replace('_', '/', $classyName);
$filename = substr(str_replace('\\', '/', $file->getRealPath()), -strlen($normClass) - 4, -4);
if ($normClass !== $filename && strtolower($normClass) === strtolower($filename)) {
$tokens[$classyIndex]->setContent(str_replace('/', '_', $filename));
}
}
}
开发者ID:friendsofphp,项目名称:php-cs-fixer,代码行数:38,代码来源:Psr4Fixer.php
示例16: make_writable
/**
* This function will make directory writable.
*
* @param string path
* @return void
* @throw Kohana_Exception
*/
public static function make_writable($path, $chmod = NULL)
{
try {
$dir = new SplFileInfo($path);
if ($dir->isFile()) {
throw new Kohana_Exception('Could not make :path writable directory because it is regular file', array(':path' => Debug::path($path)));
} elseif ($dir->isLink()) {
throw new Kohana_Exception('Could not make :path writable directory because it is link', array(':path' => Debug::path($path)));
} elseif (!$dir->isDir()) {
// Try create directory
Ku_Dir::make($path, $chmod);
clearstatcache(TRUE, $path);
}
if (!$dir->isWritable()) {
// Try make directory writable
chmod($dir->getRealPath(), $chmod === NULL ? Ku_Dir::$default_dir_chmod : $chmod);
clearstatcache(TRUE, $path);
// Check result
if (!$dir->isWritable()) {
throw new Exception('Make dir writable failed', 0);
}
}
} catch (Kohana_Exception $e) {
// Rethrow exception
throw $e;
} catch (Exception $e) {
throw new Kohana_Exception('Could not make :path directory writable', array(':path' => Debug::path($path)));
}
}
开发者ID:greor,项目名称:satin-spb,代码行数:36,代码来源:dir.php
示例17: it_does_not_change_not_updated_file
function it_does_not_change_not_updated_file()
{
$file = new \SplFileInfo(__FILE__);
$changes = ['data' => ['filePath' => $file->getPath()]];
$originals = ['data' => ['filePath' => $file->getPath()]];
$this->compare($changes, $originals)->shouldReturn(null);
}
开发者ID:CopeX,项目名称:pim-community-dev,代码行数:7,代码来源:MediaComparatorSpec.php
示例18: getFileRelativePathname
private function getFileRelativePathname(\SplFileInfo $file)
{
if ($file instanceof SymfonySplFileInfo) {
return $file->getRelativePathname();
}
return $file->getPathname();
}
开发者ID:thekabal,项目名称:tki,代码行数:7,代码来源:FileFilterIterator.php
示例19: it_cuts_the_filename_if_it_is_too_long
function it_cuts_the_filename_if_it_is_too_long(\SplFileInfo $file)
{
$file->getFilename()->willReturn('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.pdf');
$file->getExtension()->willReturn('pdf');
$pathInfo = $this->generate($file);
$pathInfo->shouldBeValidPathInfo('Lorem_ipsum_dolor_sit_amet__consectetur_adipiscing_elit__sed_do_eiusmod_tempor_incididunt_ut_la.pdf');
}
开发者ID:jacko972,项目名称:pim-community-dev,代码行数:7,代码来源:PathGeneratorSpec.php
示例20: __construct
public function __construct(SplFileInfo $file)
{
$this->file = $file;
$this->location = $file->getRealPath();
$this->name = preg_replace('/\\.' . preg_quote(General::getExtension($file)) . '$/', null, $file->getFilename());
$this->errors = array();
}
开发者ID:brendo,项目名称:bulkimporter,代码行数:7,代码来源:class.file.php
注:本文中的SplFileInfo类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论