Removes version string (if any) from file paths.

@param array $files
@param string $version

@return array
178622
private function sanitizeFilenames(array $files, $version)
    {
        $filesWithoutVersion = array_map(function ($file) use ($version) {
            if (preg_match('/\?' . preg_quote($version, '/') . '$/', $file)) {
                return substr($file, 0, -(strlen($version) + 1));
            }

            return $file;
        }, $files);

        return $filesWithoutVersion;
    }
730215
public function format(Version $version)
    {
        if (preg_match('/^(\d+)-g([a-fA-F0-9]{7,40})(-dirty)?$/', $version->getPreRelease(), $matches)) {
            if ((int) $matches[1] != 0) {
                // we are not on TAG commit, add "dev" and git commit hash as pre release part
                $version = $version->withPreRelease(array('dev', $matches[2]));
            } else {
                $version = $version->withPreRelease(array());
            }
        }

        if (preg_match('/^(.*)-(\d+)-g([a-fA-F0-9]{7,40})(-dirty)?$/', $version->getPreRelease(), $matches)) {
            if ((int) $matches[2] != 0) {
                // we are not on TAG commit, add "dev" and git commit hash as pre release part
                if (empty($matches[1])) {
                    $version = $version->withPreRelease(array('dev', $matches[3]));
                } else {
                    $version = $version->withPreRelease(array_merge(explode('.', trim($matches[1], '-')), array('dev', $matches[3])));
                }
            } else {
                if (empty($matches[1])) {
                    $version = $version->withPreRelease(array());
                } else {
                    $version = $version->withPreRelease(trim($matches[1], '-'));
                }
            }
        }

        return $version;
    }
1055999
protected function filterFiles($files)
    {
        if (! $files) {
            return;
        }

        foreach ($files as $key => $file) {
            if (is_array($file)) {
                $files[$key] = $this->filterFiles($files[$key]);
            }

            if (empty($files[$key])) {
                unset($files[$key]);
            }
        }

        return $files;
    }
451551
public function isPartOf(Version $version)
    {
        if (is_null($version->getOperator()))
        {
            if ($this->major == $version->getMajor()  && $this->minor == $version->getMinor() && $this->path == $version->getPath())
                return true;
            return false;
        }

        switch ($version->getOperator())
        {
            case self::GREATER:
                return $this->mustGreaterThan($version);
                break;

            case self::GREATER_EQUAL:
                return $this->mustGreaterEqualThan($version);
                break;
            case self::TILDE:
                return $this->mustTilde($version);
                break;
        }
    }
1337045
protected function filterFiles($files)
    {
        foreach ($files as $key => $file) {
            if ($file instanceof UploadedFile) {
                continue;
            }

            if (is_array($file)) {
                if (! isset($file['name'])) {
                    $files[$key] = $this->filterFiles($files[$key]);
                } elseif (isset($files[$key]['error']) && $files[$key]['error'] !== 0) {
                    unset($files[$key]);
                }

                continue;
            }

            unset($files[$key]);
        }

        return $files;
    }
35172
function remove( $removeAttributes = false, $version = eZContentClass::VERSION_STATUS_DEFINED )
    {
        // If we are not allowed to remove just return false
        if ( $this->Version == eZContentClass::VERSION_STATUS_DEFINED && !$this->isRemovable() )
            return false;

        if ( is_array( $removeAttributes ) or $removeAttributes )
            $this->removeAttributes( $removeAttributes );

        $this->NameList->remove( $this );
        parent::remove();
    }
133827
public function deleteFiles($paths)
    {
        $fullPaths = [];
        foreach ($paths as $path) {
            $path = self::validatePath($path);
            $fullPaths[] = $this->getMediaPath($path);
        }

        return $this->getStorageDisk()->delete($fullPaths);
    }
412352
protected function filterProtocolVersion($version)
    {
        if (!is_string($version) || !in_array($version, $this->protocols)) {
            throw new \InvalidArgumentException('The specified protocol is invalid.');
        }

        return $version;
    }
394348
public static function sort(array $versions) : array
    {
        usort(
            $versions,
            function (Version $a, Version $b) {
                return VersionComparator::compare($a, $b);
            }
        );

        return $versions;
    }
1370628
public function remove($files)
    {
        if ($files instanceof \Traversable) {
            $files = iterator_to_array($files, false);
        } elseif (!is_array($files)) {
            $files = array($files);
        }
        $files = array_reverse($files);
        foreach ($files as $file) {
            if (is_link($file)) {
                // See https://bugs.php.net/52176
                if (!@(unlink($file) || '\\' !== DIRECTORY_SEPARATOR || rmdir($file)) && file_exists($file)) {
                    $error = error_get_last();
                    throw new IOException(sprintf('Failed to remove symlink "%s": %s.', $file, $error['message']));
                }
            } elseif (is_dir($file)) {
                $this->remove(new \FilesystemIterator($file, \FilesystemIterator::CURRENT_AS_PATHNAME | \FilesystemIterator::SKIP_DOTS));

                if (!@rmdir($file) && file_exists($file)) {
                    $error = error_get_last();
                    throw new IOException(sprintf('Failed to remove directory "%s": %s.', $file, $error['message']));
                }
            } elseif (!@unlink($file) && file_exists($file)) {
                $error = error_get_last();
                throw new IOException(sprintf('Failed to remove file "%s": %s.', $file, $error['message']));
            }
        }
    }
635063
public function update($version = '') : bool
    {
        $this->setPathToUpdate(base_path(), $this->config['exclude_folders']);

        if ($this->hasCorrectPermissionForUpdate()) {
            if (empty($version)) {
                $version = $this->getVersionAvailable();
            }
            $sourcePath = $this->config['download_path'].DIRECTORY_SEPARATOR.$this->prepend.$version.$this->append;

            // Move all directories first
            collect((new Finder())->in($sourcePath)->exclude($this->config['exclude_folders'])->directories()->sort(function ($a, $b) {
                return strlen($b->getRealpath()) - strlen($a->getRealpath());
            }))->each(function ($directory) { /** @var \SplFileInfo $directory */
                if (count(array_intersect(File::directories(
                        $directory->getRealPath()), $this->config['exclude_folders'])) == 0) {
                    File::copyDirectory(
                        $directory->getRealPath(),
                        base_path($directory->getRelativePath()).'/'.$directory->getBasename()
                    );
                }
                File::deleteDirectory($directory->getRealPath());
            });

            // Now move all the files left in the main directory
            collect(File::allFiles($sourcePath, true))->each(function ($file) { /* @var \SplFileInfo $file */
                File::copy($file->getRealPath(), base_path($file->getFilename()));
            });

            File::deleteDirectory($sourcePath);
            $this->deleteVersionFile();
            event(new UpdateSucceeded($version));

            return true;
        }

        event(new UpdateFailed($this));

        return false;
    }
773964
public static function isValidProtocolVersion($version)
    {
        if (!is_string($version) || empty($version)) {
            return false;
        }

        return (bool) preg_match('#^(1\.[01]|2)$#', $version);
    }
683777
protected function concatFiles($files = Array(), $version = '')
    {

        if ($files[0] == 'sb' && strstr(\sb\Gateway::$agent, 'MSIE')) {

            array_unshift($files, 'js1_5');
        }

        $root = $this->toolkit_root;

        $binary = preg_match("~\.(swf|gif|png)$~", $files[0], $match);

        if ($binary) {
            if ($match[1] == 'swf') {
                header("Content-type: application/x-shockwave-flash");
            } elseif ($match[1] == 'gif' || $match[1] == 'png') {
                header("Content-type: image/" . $match[1]);
            }
        } else {
            $this->addJavascriptHeaders();
            echo '//v ' . date('m/d/Y H:i:s') . "\n";
        }

        if ($this->cache_enable) {
            $cache = isset(\App::$cache) ? \App::$cache : new Cache_FileSystem();
            $key = '/toolkit/' . md5(implode(",", $files));

            $data = $cache->fetch($key);
            if ($data) {
                echo $data;
                return true;
            }
        }

        $surebert = $this->default_files;
        $this->loaded_files = Array();
        foreach ($files as $file) {
            if ($binary) {
                $surebert[] = $file;
            } else {

                $surebert[] = str_replace('.', '/', $file) . '.js';
            }
        }
        ob_start();

        foreach ($surebert as $file) {
            echo $this->grabFile($file, $root);
        }

        $js = ob_get_clean();

        if (isset($this->request->get['manifest'])) {
            $m = $this->request->get['manifest'];
            if ($m == 'js') {
                return json_encode($this->loaded_files);
            } else {
                return print_r($this->loaded_files, 1);
            }
        }
        if ($this->cache_enable) {
            $cache->store($key, $js);
        }

        return $js;
    }
155602
public static function formatVersion($version)
    {
        return sprintf('%s-%s-%s %s:%s:%s',
            substr($version, 0, 4),
            substr($version, 4, 2),
            substr($version, 6, 2),
            substr($version, 8, 2),
            substr($version, 10, 2),
            substr($version, 12, 2)
        );
    }
782002
protected function get_version_option_for_filter($version) {
        if ($version->status == policy_version::STATUS_ACTIVE) {
            $a = (object)[
                'name' => format_string($version->revision),
                'status' => get_string('status'.policy_version::STATUS_ACTIVE, 'tool_policy'),
            ];
            return get_string('filterrevisionstatus', 'tool_policy', $a);
        } else {
            return get_string('filterrevision', 'tool_policy', $version->revision);
        }
    }
1358817
public function ignoreFiles($files) {
		if (! is_array ( $files )) {
			$files = func_get_args ();
		}
		$this->begin ();
		$this->run ( 'git reset', NULL, [ "--" => $files ] );
		return $this->end ();
	}
365665
private function filterByLocalMajorVersion(array $versions)
    {
        list($localMajorVersion, ) = explode('.', $this->localVersion, 2);

        return array_filter($versions, function ($version) use ($localMajorVersion) {
            list($majorVersion, ) = explode('.', $version, 2);
            return $majorVersion === $localMajorVersion;
        });
    }