Piwik\Filesystem::isValidFilename PHP Метод

isValidFilename() публичный статический Метод

File names beginning with anything but a-Z or 0-9 will be rejected (including .htaccess for example). File names containing anything other than above mentioned will also be rejected (file names with spaces won't be accepted).
public static isValidFilename ( string $filename ) : boolean
$filename string
Результат boolean
    public static function isValidFilename($filename)
    {
        return 0 !== preg_match('/(^[a-zA-Z0-9]+([a-zA-Z_0-9.-]*))$/D', $filename);
    }

Usage Example

Пример #1
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return array
  * @throws \RunTimeException
  */
 protected function getPluginName(InputInterface $input, OutputInterface $output)
 {
     $self = $this;
     $validate = function ($pluginName) use($self) {
         if (empty($pluginName)) {
             throw new \RunTimeException('You have to enter a plugin name');
         }
         if (!Filesystem::isValidFilename($pluginName)) {
             throw new \RunTimeException(sprintf('The plugin name %s is not valid', $pluginName));
         }
         $pluginPath = $self->getPluginPath($pluginName);
         if (file_exists($pluginPath)) {
             throw new \RunTimeException('A plugin with this name already exists');
         }
         return $pluginName;
     };
     $pluginName = $input->getOption('name');
     if (empty($pluginName)) {
         $dialog = $this->getHelperSet()->get('dialog');
         $pluginName = $dialog->askAndValidate($output, 'Enter a plugin name: ', $validate);
     } else {
         $validate($pluginName);
     }
     $pluginName = ucfirst($pluginName);
     return $pluginName;
 }
All Usage Examples Of Piwik\Filesystem::isValidFilename