Example #1
0
 /**
  * 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;
 }
 /**
  * Checks the supplied file name for validity.
  * @param string  $fileName
  * @return string
  */
 protected function validateFileName($fileName)
 {
     if (!FileHelper::validatePath($fileName, $this->maxNesting)) {
         throw new ApplicationException(Lang::get('cms::lang.cms_object.invalid_file', ['name' => $fileName]));
     }
     if (!strlen(File::extension($fileName))) {
         $fileName .= '.' . $this->defaultExtension;
     }
     return $fileName;
 }