/** * Sets the object file name. * @param string $fileName Specifies the file name. * @return \Cms\Classes\CmsObject Returns the object instance. */ public function setFileName($fileName) { $fileName = trim($fileName); if (!strlen($fileName)) { throw new ValidationException(['fileName' => Lang::get('cms::lang.cms_object.file_name_required', ['allowed' => implode(', ', static::$allowedExtensions), 'invalid' => pathinfo($fileName, PATHINFO_EXTENSION)])]); } if (!FileHelper::validateExtension($fileName, static::$allowedExtensions)) { throw new ValidationException(['fileName' => Lang::get('cms::lang.cms_object.invalid_file_extension', ['allowed' => implode(', ', static::$allowedExtensions), 'invalid' => pathinfo($fileName, PATHINFO_EXTENSION)])]); } if (!FileHelper::validatePath($fileName, static::getMaxAllowedPathNesting())) { throw new ValidationException(['fileName' => Lang::get('cms::lang.cms_object.invalid_file', ['name' => $fileName])]); } if (!strlen(File::extension($fileName))) { $fileName .= '.htm'; } $this->fileName = $fileName; return $this; }
/** * Validate the supplied filename, extension and path. * @param string $fileName */ protected function validateFileName($fileName = null) { if ($fileName === null) { $fileName = $this->fileName; } $fileName = trim($fileName); if (!strlen($fileName)) { throw new ValidationException(['fileName' => Lang::get('cms::lang.cms_object.file_name_required', ['allowed' => implode(', ', $this->allowedExtensions), 'invalid' => pathinfo($fileName, PATHINFO_EXTENSION)])]); } if (!FileHelper::validateExtension($fileName, $this->allowedExtensions, false)) { throw new ValidationException(['fileName' => Lang::get('cms::lang.cms_object.invalid_file_extension', ['allowed' => implode(', ', $this->allowedExtensions), 'invalid' => pathinfo($fileName, PATHINFO_EXTENSION)])]); } }