Remove subfolders and blank entries then return array
@param string|array $secureFolders
@return array
764502
protected static function _processFolders($secureFolders)
    {
        $secureFolders = array_filter(is_array($secureFolders) ? $secureFolders : explode(',', $secureFolders), 'trim');
        foreach ($secureFolders as $k => $folder) {
            $secureFolders[$k] = '/' . trim($folder, '/');
        }
        if (in_array('/', $secureFolders)) {
            return ['/']; // all uploads are secure
        }
        foreach ($secureFolders as $k => $folder) {
            foreach ($secureFolders as $folderCheck) {
                if (strpos($folder, $folderCheck . '/') === 0) {
                    unset($secureFolders[$k]);
                }
            }
        }
        return $secureFolders;
    }
781603
public function urlWithParams($path = null, $qs = [], $secure = null)
    {
        $url = app('url')->to($path, $secure);
        if (count($qs)){
            foreach($qs as $key => $value){
                $qs[$key] = sprintf('%s=%s',$key, urlencode($value));
            }
            $url = sprintf('%s?%s', $url, implode('&', $qs));
        }
        return $url;
    }
1345616
protected function deletingFilesNamesList($files) : array
	{
		return $files->flatMap(function($item) {
			$path_parts = pathinfo($item);
			$result[] = $path_parts['filename'];

			return $result;
		})->filter(function($item) {
			return trim($item) != '';
		})->all();
	}
1169272
public static function root($secure = null)
    {
        $framework = '/public/index.php';
        $server = request('PHP_SELF', '', 'server');
        $scheme = (is_null($secure) ? request('REQUEST_SCHEME', '', 'server') : ($secure ? 'https' : 'http')).'://';
        $serverName = request('SERVER_NAME', '', 'server');

        $parts = explode($framework, $server);

        $root = $parts[0].'/';

        return $scheme.$serverName.$root;
    }
414832
public function load(array $fixturesFiles, array $parameters = [], array $objects = [], PurgeMode $purgeMode = null): array
    {
        if (null === $purgeMode) {
            $purgeMode = $this->defaultPurgeMode;
        }

        if ($purgeMode != PurgeMode::createNoPurgeMode()) {
            $this->logger->info(
                sprintf(
                    'Purging database with purge mode "%s".',
                    (string) $purgeMode
                )
            );

            $purger = $this->purgerFactory->create($purgeMode);
            $purger->purge();
        }

        return $this->loader->load($fixturesFiles, $parameters, $objects, $purgeMode);
    }
1132560
public function getRecursiveFolders($folders)
    {
        if (! is_array($folders)) {
            $folders = [$folders];
        }

        $paths = [];

        foreach ($folders as $folder) {
            $iter = new Iterator(
                new DirectoryIterator($folder, DirectoryIterator::SKIP_DOTS),
                Iterator::SELF_FIRST,
                Iterator::CATCH_GET_CHILD // Ignore "Permission denied"
            );

            $subPaths = [$folder];
            foreach ($iter as $path => $dir) {
                if ($dir->isDir()) {
                    $subPaths[] = $path;
                }
            }

            $paths = array_merge($paths, $subPaths);
        }

        return $paths;
    }
728577
protected function filterHeaders($rawHeaders)
    {
        // do not trust any of the [[secureHeaders]] by default
        $trustedHeaders = [];

        // check if the client is a trusted host
        if (!empty($this->trustedHosts)) {
            $validator = $this->getIpValidator();
            $ip = $this->getRemoteIP();
            foreach ($this->trustedHosts as $cidr => $headers) {
                if (!is_array($headers)) {
                    $cidr = $headers;
                    $headers = $this->secureHeaders;
                }
                $validator->setRanges($cidr);
                if ($validator->validate($ip)) {
                    $trustedHeaders = $headers;
                    break;
                }
            }
        }

        $rawHeaders = array_change_key_case($rawHeaders, CASE_LOWER);

        // filter all secure headers unless they are trusted
        foreach ($this->secureHeaders as $secureHeader) {
            if (!in_array($secureHeader, $trustedHeaders)) {
                unset($rawHeaders[strtolower($secureHeader)]);
            }
        }

        return $rawHeaders;
    }
981796
protected function removeInvalidOrHiddenLinks(array $links): array
    {
        foreach ($links as $i => &$link) {
            if (!isset($link['target_page_id']) && !isset($link['url'])) {
                unset($links[$i]);

                continue;
            }

            $target = empty($link['target_page_id']) ? $link['url'] : $link['target_page_id'];

            $link = Link::factory($target, $link);

            if (!$link->isValid() || (!$this->editable && !$link->isVisible())) {
                unset($links[$i]);
            }
        }

        return array_values($links);
    }
419846
public static function segment_replace($url, $secure = null)
	{
		// get the path from the url
		$parts = parse_url($url);

		// explode it in it's segments
		$segments = explode('/', trim($parts['path'], '/'));

		// fetch any segments needed
		$wildcards = 0;
		foreach ($segments as $index => &$segment)
		{
			if (strpos($segment, '*') !== false)
			{
				$wildcards++;
				if (($new = static::segment($index+1)) === null)
				{
					throw new \OutofBoundsException('Segment replace on "'.$url.'" failed. No segment exists for wildcard '.$wildcards.'.');
				}
				$segment = str_replace('*', $new, $segment);
			}
		}

		// re-assemble the path
		$parts['path'] = '/'.implode('/', $segments);

		// do we need to force a scheme?
		if (is_bool($secure))
		{
			$parts['scheme'] = $secure ? 'https' : 'http';
		}

		// and rebuild the url with the new path
		if (empty($parts['host']))
		{
			// if a relative url was given, fake a host so we can remove it after building
			$url = substr(http_build_url('http://__removethis__/', $parts), 22);
		}
		else
		{
			// a hostname was present, just rebuild it
			$url = http_build_url('', $parts);
		}

		// return the newly constructed url
		return $url;
	}
1283269
public function deleteOldWebtreesFiles(Filesystem $filesystem): array
    {
        $paths_to_delete = [];

        foreach (self::OLD_PATHS as $path) {
            if (!$this->deleteFileOrFolder($filesystem, $path)) {
                $paths_to_delete[] = $path;
            }
        }

        return $paths_to_delete;
    }
681482
private function mapFolders(SS_List $folders, $searchQuery=null) {
        $result=array();
        
        foreach($folders as $folder) {
            if(!empty($searchQuery) && $searchQuery!==false) {
                $searchEngine=Config::inst()->get('CodeBank', 'snippet_search_engine');
                if($searchEngine && class_exists($searchEngine) && in_array('ICodeBankSearchEngine', class_implements($searchEngine))) {
                    $searchEngine=new $searchEngine();
                }else {
                    //Class is missing or invalid so fallback to the default
                    $searchEngine=new DefaultCodeBankSearchEngine();
                }
                
                $snippets=$searchEngine->doSnippetSearch($searchQuery, false, $folder->ID);
            }else {
                $snippets=$folder->Snippets();
            }
            
            $snippets=$this->overviewList($snippets, 'Title', 'ID', 'LanguageID');
            
            if(!empty($searchQuery) && $searchQuery!==false && count($snippets)==0) {
                continue;
            }
            
            $result[]=array(
                            'id'=>$folder->ID,
                            'name'=>$folder->Name,
                            'languageID'=>$folder->LanguageID,
                            'folders'=>$this->mapFolders($folder->Folders(), $searchQuery),
                            'snippets'=>$snippets
                        );
        }
        
        return $result;
    }
1163958
def remove_excludes
      return self if config[:excludes].nil?
      config[:excludes].map { |e| Dir["#{directory}/#{e}"] }.flatten.each do |e|
        FileUtils.remove_entry_secure e
      end
      self
    end
1101222
private function removeImplicitDirectoriesForPush(array $filesToPush): array
    {
        $implicitDirectories = [];
        foreach ($filesToPush as $file) {
            if (false === strpos($file['relative_path'], '/')) {
                continue;
            }

            $directories = explode('/', $file['relative_path']);
            do {
                array_pop($directories);
                if ($directories) {
                    $implicitDirectory = implode('/', $directories);
                    if (isset($implicitDirectories[$implicitDirectory])) {
                        break;
                    }
                    $implicitDirectories[$implicitDirectory] = true;
                }
            } while ($directories);
        }

        foreach ($filesToPush as $key => $file) {
            // If this file is an implicit directory, there is no need to push it
            if ('dir' == $file['type'] && isset($implicitDirectories[$file['relative_path']])) {
                unset($filesToPush[$key]);
                continue;
            }
        }
        return $filesToPush;
    }
541157
private function scanVendorFolders(&$folders)
    {
        $basedir = realpath(NABU_PROVIDERS_PATH);
        if (is_dir($basedir) && ($h = opendir($basedir))) {
            while (($folder = readdir($h))) {
                if ($folder !== '.' && $folder !== '..') {
                    $this->scanModuleFolders($basedir . DIRECTORY_SEPARATOR . $folder, $folders);
                }
            }
            closedir($h);
        }
    }
1010497
protected static function clearEmptySections(array $sections): array
    {
        array_walk($sections, function ($templates, $index) use (&$sections) {
            if (count($templates) == 0) {
                unset($sections[$index]);
            }
        });

        return $sections;
    }
347993
protected function removeDots(array $settings): array
    {
        $conf = [];
        foreach ($settings as $key => $value) {
            $conf[$this->removeDotAtTheEnd($key)] = \is_array($value) ? $this->removeDots($value) : $value;
        }
        return $conf;
    }
1078112
private function deleteSubfolder($path, $params)
    {
        // Use a key that adds a trailing slash if needed.
        $prefix = rtrim($params['Key'], '/') . '/';
        $result = $this->getClient()->listObjects([
            'Bucket'  => $params['Bucket'],
            'Prefix'  => $prefix,
            'MaxKeys' => 1
        ]);

        // Check if the bucket contains keys other than the placeholder
        if ($contents = $result['Contents']) {
            return (count($contents) > 1 || $contents[0]['Key'] != $prefix)
                ? $this->triggerError('Subfolder is not empty')
                : $this->unlink(rtrim($path, '/') . '/');
        }

        return $result['CommonPrefixes']
            ? $this->triggerError('Subfolder contains nested folders')
            : true;
    }