当前位置: 首页>>代码示例>>PHP>>正文


PHP SplFileInfo类代码示例

本文整理汇总了PHP中SplFileInfo的典型用法代码示例。如果您正苦于以下问题:PHP SplFileInfo类的具体用法?PHP SplFileInfo怎么用?PHP SplFileInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了SplFileInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的SplFileInfo类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。