/** * Checks if the provided file is allowed by this filter * @param zibo\library\filesystem\File $file File to check * @return boolean True if the file is allowed, false otherwise */ public function isAllowed(File $file) { $result = !$this->include; $extension = $file->getExtension(); if (in_array($extension, $this->extensions)) { $result = !$result; } return $result; }
/** * Creates an archive object for the provided file * @param zibo\library\filesystem\File $file File of the archive * @return Archive * @throws zibo\library\archive\exception\ArchiveException when the provided file is not a supported archive, based on extension */ public function getArchive(File $file) { $extension = $file->getExtension(); if (!isset($this->types[$extension])) { throw new ArchiveException('Unsupported archive: ' . $extension); } $className = $this->types[$extension]; $reflection = new ReflectionClass($className); $archive = $reflection->newInstance($file); return $archive; }
/** * Get the mime type of a file based on it's extension * @param File $file * @return string the mime type of the file */ public static function getMimeType(File $file) { $extension = $file->getExtension(); if (empty($extension)) { return self::MIME_UNKNOWN; } $mime = Zibo::getInstance()->getConfigValue(self::CONFIG_MIME . $extension); if (!$mime) { $mime = self::MIME_UNKNOWN; } return $mime; }
/** * Check whether the value has a valid extension * @param mixed $value * @return boolean true when the value has a valid extension, false otherwise */ public function isValid($value) { $isEmpty = empty($value); if (!$this->isRequired && $isEmpty) { return true; } elseif ($isEmpty) { $this->addValidationError(RequiredValidator::CODE, RequiredValidator::MESSAGE, array()); return false; } $file = new File($value); $extension = $file->getExtension(); if (!$extension || !empty($this->extensions) && !isset($this->extensions[$extension])) { $parameters = array('value' => $value, 'extensions' => implode(',', $this->extensions)); $this->addValidationError(self::CODE, self::MESSAGE, $parameters); return false; } return true; }
/** * Get the cache file for the image source * @param zibo\library\filesystem\File $source image source to get a cache file for * @return zibo\library\filesystem\File unique name for a source file, in the cache directory, with the thumbnailer, width and height encoded into */ private function getCacheFile(File $source) { $filename = md5($source->getPath() . '-thumbnailer=' . $this->thumbnailer . '-width=' . $this->thumbnailWidth . '-height=' . $this->thumbnailHeight); $filename .= '.' . $source->getExtension(); return new File(self::CACHE_PATH, $filename); }
/** * @dataProvider providerGetExtension */ public function testGetExtension($expected, $value) { $file = new File($value); $this->assertEquals($expected, $file->getExtension()); }
/** * Get the ImageIO for the given file. ImageIO choice is based on the extension of the file. * @param File file to get the ImageIO for */ private function getImageIO(File $file) { $extension = $file->getExtension(); if (!isset($this->io[$extension])) { throw new ImageException($extension . ' is not supported (' . $file->getPath() . ')'); } return $this->io[$extension]; }
/** * Copies a file into the modules directory * @param zibo\library\filesystem\File $file * @return zibo\library\filesystem\File the destination file */ private function copyFile(File $file) { if ($file->getExtension() == 'phar' && class_exists(self::CLASS_ARCHIVE_FACTORY)) { $module = new File(Zibo::DIRECTORY_MODULES, substr($file->getName(), 0, -5)); $archive = ArchiveFactory::getInstance()->getArchive($file); $archive->uncompress($module); } else { $module = new File(Zibo::DIRECTORY_MODULES, $file->getName()); if ($module->getAbsolutePath() != $file->getAbsolutePath()) { $file->copy($module); } } return $module; }
/** * Exports the database to a file * @param zibo\library\filesystem\File $file * @return null * @throws zibo\ZiboException when an error eoccured */ public function export(File $file) { $extension = $file->getExtension(); if ($extension != 'sql') { throw new MysqlException('Provided file needs to have an sql extension'); } $dsn = $this->getDsn(); $username = $dsn->getUsername(); $password = $dsn->getPassword(); $database = $dsn->getDatabase(); $command = 'mysqldump --user='******' --password='******' ' . $database; $command .= ' > ' . $file->getAbsolutePath(); System::execute($command); }