本文整理汇总了PHP中SplFileObject::getExtension方法的典型用法代码示例。如果您正苦于以下问题:PHP SplFileObject::getExtension方法的具体用法?PHP SplFileObject::getExtension怎么用?PHP SplFileObject::getExtension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SplFileObject
的用法示例。
在下文中一共展示了SplFileObject::getExtension方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getOptions
public static function getOptions($file, $profile = null, $localFile = null)
{
if (file_exists($file)) {
$f = new \SplFileObject($file);
switch ($f->getExtension()) {
case "php":
$standardOptions = (include $file);
if (file_exists($localFile)) {
$localOptions = (include $localFile);
}
break;
case "yaml":
case "yml":
$parser = new \Symfony\Component\Yaml\Parser();
$standardOptions = $parser->parse(file_get_contents($file));
if (file_exists($localFile)) {
$localOptions = $parser->parse(file_get_contents($localFile));
}
break;
case "json":
$standardOptions = json_decode(file_get_contents($file), true);
if (file_exists($localFile)) {
$localOptions = json_decode(file_get_contents($localFile), true);
}
break;
default:
throw new \InvalidArgumentException("File type " . $f->getExtension() . " not supported");
}
if (is_array($localOptions) && count($localOptions)) {
$options = array_replace_recursive($standardOptions, $localOptions);
} else {
$options = $standardOptions;
}
if (!is_array($options)) {
throw new \RuntimeException("Found no usable data in {$file}");
} else {
if ($profile) {
return self::resolveInheritance($options, $profile);
}
return $options;
}
} else {
throw new \InvalidArgumentException("{$file} does not exist or could not be read");
}
}
示例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: assertFile
/**
* Validate code examples in $file
*
* @param \SplFileObject $file
* @param string $formatIdentifier
* @return void
*/
public function assertFile(\SplFileObject $file, $formatIdentifier = '')
{
$format = $this->formatFactory->createFormat($formatIdentifier ?: $file->getExtension());
$result = $this->testCase->getTestResultObject();
foreach ($this->tester->test($file, $format) as $example => $returnObj) {
$this->testCase->addToAssertionCount(1);
if ($returnObj->isFailure()) {
$result->addFailure($this->testCase, new \PHPUnit_Framework_AssertionFailedError("Example {$example}: {$returnObj->getMessage()}"), 0.0);
}
}
}
示例4: loadAction
/**
* @Route("/download/{filename}/{file}", name="app_download")
* @Route("/load/{filename}/{file}", name="app_load")
* @ParamConverter("file", converter="file_converter")
* @Method("GET")
* @param string $filename
* @param \SplFileObject $file
* @return Response
*/
public function loadAction($filename, \SplFileObject $file)
{
$response = new Response($file->fpassthru());
$response->headers->set('Content-Type', 'octet/stream');
$response->headers->set('Content-disposition', 'attachment; filename="' . $filename . '.' . $file->getExtension() . '";"');
$response->headers->set('Content-Length', $file->getSize());
$response->headers->set('Cache-Control', 'max-age=31536000, public');
// 1 year
$response->sendHeaders();
return $response->send();
}
示例5: __construct
/**
* Constructor
*
* @param \SplFileObject $post Post source file
*/
public function __construct(\SplFileObject $post)
{
$this->source = $post;
if (!preg_match('/[\\d]{4}\\/[\\d]{2}\\/(.+)$/', $post->getPathname())) {
throw new \Exception(sprintf('%s is not a valid post', $post->getPathname()));
}
$paths = explode(DIRECTORY_SEPARATOR, $post->getPath());
$this->month = $paths[count($paths) - 1];
$this->year = $paths[count($paths) - 2];
$this->slug = $post->getBasename('.' . $post->getExtension());
}
示例6: getFile
/**
* Renvoie le fichier dont le chemin est passé en paramètre.
*
* @param string $filename Chemin du fichier.
* @return SplFileObject
* @throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException En cas d'erreur d'accès au fichier.
* @throws \Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException Si le type de fichier n'est pas celui attendu.
*/
protected function getFile($filename)
{
if (!file_exists($filename)) {
throw new \Symfony\Component\HttpKernel\Exception\BadRequestHttpException("Le fichier {$filename} n'existe pas.");
}
$splFile = new \SplFileObject($filename);
$fileExtension = $splFile->getExtension();
// Handlers disponibles
if ($fileExtension !== $this->handlers[$this->handlerIdentifier]['extension']) {
throw new \Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException("Le handler [{$this->handlerIdentifier}] ne supporte pas le type de fichier [{$fileExtension}].");
}
return $splFile;
}
示例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: SplFileObject
<?php
$file = new SplFileObject('spl_file_object.php');
print 'Nome: ' . $file->getFileName() . '<br>' . PHP_EOL;
print 'Extensão: ' . $file->getExtension() . '<br>' . PHP_EOL;
$file2 = new SplFileObject('novo.txt', 'w');
$bytes = $file2->fwrite('Olá Mundo PHP' . PHP_EOL);
print 'Bytes escritos ' . $bytes . PHP_EOL;
示例9: support
protected function support(SplFileObject $file)
{
return $file->getExtension() === 'xml';
}
示例10: __construct
public function __construct($movieFile)
{
$this->movieFile = new \SplFileObject($movieFile);
$this->fileExtension = $this->movieFile->getExtension();
}
示例11: importDunes
/**
* Reads an dune import file containing dune data and returns a site object.
*
* @param string $filePath The file path location for the
* @param bool $errorOnBadData If true and exception will be thrown due to a line of bad data. If false the
* line is skipped silently.
*
* @return Site A Site object populated with dunes.
* @throws InvalidOperationException If database credentials have not been set (required for dune creation)
* @throws MyInvalidArgumentException If the import path is invalid.
*/
public final function importDunes($filePath, $errorOnBadData = TRUE)
{
if (is_null(self::$databaseCredentials)) {
throw new InvalidOperationException('Database credentials must be set at the class level to allow this action to take place.');
}
Dune::setDatabaseCredentials(self::$databaseCredentials);
$fileHandle = new SplFileObject($filePath);
if (!$fileHandle->isFile() && !$fileHandle->isReadable() && $fileHandle->getExtension() != 'txt') {
throw new MyInvalidArgumentException('The specified import file path does not point to a valid readable text (.txt) file.');
}
while (!$fileHandle->eof()) {
$duneData = $fileHandle->fgetcsv(' ');
if ($duneData[0] == NULL || substr($duneData[0], 0, 1) == '%') {
continue;
// Skip the line
}
if (count($duneData) != 6) {
if ($errorOnBadData) {
$line = $fileHandle->key() + 1;
throw new MyInvalidArgumentException('Import failed. Line ' . $line . ' does not contain sufficient data or is
improperly formatted.');
} else {
continue;
}
}
try {
$dune = new Dune(new LatLng($duneData[3], $duneData[2]), $this->siteName, $duneData[5], $duneData[4]);
$this->dunes[] = $dune;
} catch (Exception $e) {
if ($errorOnBadData) {
$line = $fileHandle->key() + 1;
throw new MyInvalidArgumentException('Import failed. Line ' . $line . ' contains invalid data.', $e);
} else {
continue;
}
}
}
}
示例12: _extractImageProperties
/**
* Extracts the properties of the image
*
* @param Image $image Image object
*
* @return Image
*/
private function _extractImageProperties(Image $image)
{
/** @var Local $localAdapter */
$localAdapter = $this->getFileSystem()->getAdapter();
$path = $localAdapter->getPathPrefix();
$imageName = $image->getImageName();
// This is the original file name
$imageFile = new \SplFileObject("{$path}{$imageName}");
$image->setSourceName($imageName);
$image->setMime($this->getFileSystem()->getMimetype($imageName));
$image->setExtension($imageFile->getExtension());
$image->setFullPath($path);
// override the default quality if the jpgOutputQuality is set
if ($this->_jpgOutputQuality) {
$image->setJpgQuality($this->_jpgOutputQuality);
}
return $image;
}