/** * Create sprite image data holder * @param string $path * @param SplFileInfo $fileInfo */ public function __construct($path, SplFileInfo $fileInfo) { $this->basePath = $path; $this->info = $fileInfo; // Assign fileinfo variables $this->path = $this->info->getPathname(); $this->size = $this->info->getSize(); // Assign image data $info = getimagesize($this->path); if (!is_array($info)) { throw new UnexpectedValueException("The image '{$this->path}' is not a correct image format."); } $this->hash = sha1(file_get_contents($this->getFullPath())); $this->width = (int) $info[0]; $this->height = (int) $info[1]; $this->mime = $info['mime']; $this->type = explode('/', $this->mime)[1]; // Assign css name $ext = $this->info->getExtension(); // Replace path parts with `-` $name = str_replace(['/', '\\', '_'], '-', $this->info->getRelativePathname()); // Remove leading `-` $name = preg_replace('~^-*~', '', $name); // Remove double dashes $name = preg_replace('~-+~', '-', $name); // Remove file extension $name = preg_replace("~\\.{$ext}\$~", '', $name); // Replace dots with - $name = preg_replace('~\\.~', '-', $name); $this->name = $name; }
/** * @param SplFileInfo $file * * @return string */ private function getFileContents(SplFileInfo $file) { $content = $file->getContents(); if ($file->getExtension() === 'js' && substr($content, -1) !== ';') { $content .= ';'; } return $content; }
/** * Generate directory path to be used for the file pretty name. * * @return string */ protected function getDirectoryPrettyName() { $fileBaseName = $this->getFileName(); $fileRelativePath = $this->normalizePath($this->file->getRelativePath()); if (in_array($this->file->getExtension(), ['php', 'md']) && $fileBaseName != 'index') { $fileRelativePath .= $fileRelativePath ? "/{$fileBaseName}" : $fileBaseName; } return ORCA_PUBLIC_DIR . ($fileRelativePath ? "/{$fileRelativePath}" : ''); }
public static function checkIfImage($path) { $file = new \SplFileInfo($path); $ex = $file->getExtension(); if ($ex === "png" || $ex === "gif" || $ex === 'bmp' || $ex === "jpeg" || $ex === "jpg") { return true; } return false; }
/** * Transform a taxonomy YAML into a TaxonomyFile object * * @param SplFileInfo $file * * @return \Skimpy\Contracts\Entity|TaxonomyFile */ public function transform(SplFileInfo $file) { $data = $this->parser->parse($file->getContents()); $missingFields = $this->getMissingFields($data); if (false === empty($missingFields)) { throw new TransformationFailure(sprintf('Missing required fields (%s) in taxonomy file: %s', implode(', ', $this->getMissingFields($data)), $file->getRealPath())); } $filename = $file->getFilename(); $ext = $file->getExtension(); $slug = explode('.' . $ext, $filename)[0]; return new TaxonomyFile($slug, $data['name'], $data['plural_name'], $data['terms']); }
private function isBinary(SplFileInfo $file) { $ext = $file->getExtension(); return false === in_array($ext, $this->params['text_extensions']); }
/** * Returns filename w/o extension * * @return string */ public function getFilename() { $exclude = '.' . $this->file->getExtension(); return $this->file->getBasename($exclude); }
/** * Gets the class name. * * @param \Symfony\Component\Finder\SplFileInfo $file * * @return string */ protected function getClassname(SplFileInfo $file) { if ($file->getExtension() === 'php') { return $file->getBasename('.php'); } if ($file->getFilename() === $this->composerFilename) { $composerData = $this->readComposerFile($file); if (isset($composerData['extra']['spress_class']) === true && is_string($composerData['extra']['spress_class'])) { return $composerData['extra']['spress_class']; } } return ''; }
/** * Determine the target path. * * @param SplFileInfo $file * @return string */ protected function setTarget(SplFileInfo $file) { // Page extension $ext = $file->getExtension(); // Twig templates are HTML if (!$this->has('template') || $this->get('template') === 'none') { $targetExt = $ext; } else { $targetExt = 'html'; } // Get clean source path $sourcePath = $this->getCleanPath($file->getRelativePathName()); // Replace source extension with that of the template $this->target = substr($sourcePath, 0, -strlen($ext)); $this->target .= $targetExt; }
/** * @param \Symfony\Component\Finder\SplFileInfo $file * * @return string */ private function getPath(SplFileInfo $file) { switch ($file->getExtension()) { case 'gz': $path = 'compress.zlib://' . $file->getPathname(); break; case 'bz2': $path = 'compress.bzip2://' . $file->getPathname(); break; default: $path = $file->getPathname(); break; } return $path; }
public function getExtension() { return $this->fileInfo->getExtension(); }
/** * Добавляет в загрузку один файл * * @param string $pathToFile путь к файлу из которого необходимо загрузить фикстуры * * @return $this * @throws \InvalidArgumentException */ public function fromFile($pathToFile) { if (empty($pathToFile)) { throw new \InvalidArgumentException("Был передан пустой путь к файлу с фикстурами"); } if (!is_string($pathToFile)) { throw new \InvalidArgumentException("Параметр pathToFile не является строкой"); } if (!file_exists($pathToFile)) { throw new \InvalidArgumentException("Был передан несуществующий путь к файлу '{$pathToFile}'"); } $fileInfo = new \SplFileInfo($pathToFile); if ($fileInfo->getExtension() !== self::DEFAULT_FILE_EXTENSION) { throw new \InvalidArgumentException("Переданный файл '{$pathToFile}' обладает неправильным расширением"); } $this->filePathsByKey[$fileInfo->getRealPath()] = true; return $this; }
/** * @param SplFileInfo $file * @return bool */ protected function shouldIgnore(SplFileInfo $file) { if ($file->getExtension() === 'php') { return true; } return false; }
/** * Extract all strings from a given file. * * @param SplFileInfo $file * * @return string[] */ protected function extractStringTokens(SplFileInfo $file) { // Fetch tokens from cache if available $hash = 'janitor.tokens.' . md5($file->getPathname()) . '-' . $file->getMTime(); return $this->cache->rememberForever($hash, function () use($file) { $contents = $file->getContents(); // See if we have an available Tokenizer // and use it to extract the contents switch ($file->getExtension()) { case 'php': $tokenizer = strpos($file->getBasename(), 'blade.php') !== false ? new BladeTokenizer() : new PhpTokenizer(); break; case 'twig': $tokenizer = new TwigTokenizer(); break; case 'json': $tokenizer = new JsonTokenizer(); break; case 'yml': case 'yaml': $tokenizer = new YamlTokenizer(); break; case 'xml': $tokenizer = new XmlTokenizer(); break; default: $tokenizer = new DefaultTokenizer(); break; } return $tokenizer->tokenize($contents); }); }
/** * Check skip files. * * @param SplFileInfo $file * @return bool */ protected function _isSkip(SplFileInfo $file) { $name = $file->getFilename(); $ext = $file->getExtension(); return Arr::in($ext, $this->_skipFileExt) || Arr::in($name, $this->_skipFileNames); }
/** * Renombra un archivo * @param string $nameold * @param string $namenew * @param string $path * @return void */ public function rename($nameold, $namenew, $path) { if ($this->validNameFile($nameold, false) && $this->validNameFile($namenew, false)) { $fullpath = $this->getFullPath() . $path; $nameold = $this->clearNameFile($nameold); $namenew = $this->clearNameFile($namenew); $file = new Filesystem(); if ($file->exists($fullpath . $nameold)) { if ($this->config['debug']) { $this->_log('$fullpath.$nameold - ' . $fullpath . $nameold); } if (is_dir($fullpath . $nameold)) { $namenew = $this->sanitizeNameFolder($namenew); if ($file->exists($fullpath . $namenew) == false) { $file->rename($fullpath . $nameold, $fullpath . $namenew); $result = array("query" => "BE_RENAME_MODIFIED", "params" => array()); $this->setInfo(array("msg" => $result, "data" => array("namefile" => $namenew))); } else { $result = array("query" => "BE_RENAME_EXISTED", "params" => array()); $this->setInfo(array("msg" => $result, "status" => 0)); } } elseif (is_file($fullpath . $nameold)) { if ($this->validExt($nameold)) { $extold = $this->getExtension($nameold); $namenew = $namenew . '.' . $extold; if ($file->exists($fullpath . $namenew) == false) { $file2 = new \SplFileInfo($fullpath . $nameold); if ($file2->getExtension() == 'jpg' || $file2->getExtension() == 'jpeg' || $file2->getExtension() == 'png' || $file2->getExtension() == 'gif') { $filename = $file2->getFilename(); $filename_old = $this->removeExtension($filename) . '-' . $this->config['images']['resize']['thumbWidth'] . 'x' . $this->config['images']['resize']['thumbHeight'] . '.' . $file2->getExtension(); $fullpaththumb_name = $this->getFullPath() . '/_thumbs' . $path . $filename_old; $file->remove($fullpaththumb_name); } $file->rename($fullpath . $nameold, $fullpath . $namenew); $file3 = new \SplFileInfo($fullpath . $namenew); $this->createThumb($file3, $path); $result = array("query" => "BE_RENAME_MODIFIED", "params" => array()); $this->setInfo(array("msg" => $result, "data" => array("namefile" => $namenew))); } else { $result = array("query" => "BE_RENAME_EXISTED", "params" => array()); $this->setInfo(array("msg" => $result, "status" => 0)); } } else { $result = array("query" => "BE_RENAME_FILENAME_NOT_VALID", "params" => array()); $this->setInfo(array("msg" => $result, "status" => 0)); } } } else { $result = array("query" => "BE_RENAME_NOT_EXISTS", "params" => array()); $this->setInfo(array("msg" => $result, "status" => 0)); } } else { $result = array("query" => "BE_RENAME_FILENAME_NOT_VALID", "params" => array()); $this->setInfo(array("msg" => $result, "status" => 0)); } }
public function getBuildPath($buildDir, Mixer $mixer, SplFileInfo $file) { $ext = $mixer->getOutputExtension(); if (!$ext) { $ext = $file->getExtension(); } $path = $file->getRelativePath(); $filename = $file->getBasename("." . $file->getExtension()); $build = $buildDir . "/" . $path; if (!$this->files->exists($build)) { $this->files->makeDirectory($build, 0755, true); } return "{$build}/{$filename}.{$ext}"; }