當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。