Detects changes in the given list of files and emits signals if necessary.

@param array $pathAndFilenames A list of full path and filenames of files to check
@return array An array of changed files (key = path and filenmae) and their status (value)
19705
protected function detectChangedFiles(array $pathAndFilenames)
    {
        $changedFiles = [];
        foreach ($pathAndFilenames as $pathAndFilename) {
            $status = $this->changeDetectionStrategy->getFileStatus($pathAndFilename);
            if ($status !== ChangeDetectionStrategyInterface::STATUS_UNCHANGED) {
                $changedFiles[$pathAndFilename] = $status;
            }
        }
        return $changedFiles;
    }
144625
public static function getFilenames($pathname, $extension = null) {

        // Check if the directory exists.
        if (false === file_exists($pathname)) {
            throw new FileNotFoundException($pathname);
        }

        // Initialize the filenames.
        $filenames = [];

        // Open the directory.
        if (false !== ($directory = opendir($pathname))) {

            // Initialize the offset.
            $offset = strlen($extension);

            // Read the directory.
            while (($file = readdir($directory)) !== false) {

                // Determines if the file should be added.
                if (false === in_array($file, [".", ".."]) && ((null === $extension) || 0 === substr_compare($file, $extension, -$offset))) {
                    $filenames[] = $file;
                }
            }

            // Close the directory.
            closedir($directory);
        }

        // Return the filenames.
        return $filenames;
    }
896195
private function getFilesMaxAge($path, $names = array(), $default = 0)
    {
        $finder = new Finder();
        $finder->files()->in(realpath($path))->ignoreDotFiles(true);
        foreach ($names as $name) {
            $finder->name($name);
        }
        $ages = array();
        foreach ($finder as $file) {
            $ages[] = filemtime($file);
        }
        return max(array_merge($ages, array($default)));
    }
1313416
public static function files($path, $recursive = false, $toArray = false, $pathType = self::PATH_ABSOLUTE)
	{
		/**
		 * Files callback
		 *
		 * @param \SplFileInfo                $current  Current item's value
		 * @param string                      $key      Current item's key
		 * @param \RecursiveDirectoryIterator $iterator Iterator being filtered
		 *
		 * @return boolean   TRUE to accept the current item, FALSE otherwise
		 */
		$callback = function ($current, $key, $iterator) {
			return $current->isFile();
		};

		$files = static::findByCallback($path, $callback, $recursive);
		
		if ($toArray) {
		    $files = static::toArray($files, $pathType);
		}
		
		return $files;
	}
1320819
private function checkPaths($path, array $paths)
    {
        $reserved = [
            '?' => '\?',
            '.' => '\.',
            '*' => '.*',
            '+' => '\+',
            '(' => '\(',
            ')' => '\)',
            '[' => '\[',
            ']' => '\]',
        ];
        $errorHandler = new ErrorHandler();
        set_error_handler([$errorHandler, 'callback'], E_NOTICE | E_WARNING);
        foreach ($paths as $rule) {
            $escaped = str_replace(array_keys($reserved), array_values($reserved), $rule);
            if (preg_match('#^' . $escaped . '#', $path) === 1) {
                restore_error_handler();
                return mb_strlen($rule);
            }
        }
        restore_error_handler();
        return false;
    }
567176
private static function getPathFiles(array $path): array
    {
        // load external files
        $result = [];
        $pathFinder = Finder::findFiles('*')->in($path);
        foreach ($pathFinder as $file) {
            $result[$file->getRealPath()] = $file->getBaseName();
        }
        return $result;
    }
417711
protected function getHeaderFromFile(string $pathAndFilename): string
    {
        $header = '';
        $fileHandle = fopen($pathAndFilename, 'r');
        while ($line = fgets($fileHandle)) {
            if (preg_match('/^#/', $line)) {
                $header .= $line;
            } else {
                break;
            }
        }
        fclose($fileHandle);
        return $header;
    }
79164
public function updateOverrideFiles(): array
    {
        $filesUpdated = [];
        $fileSame     = [];
        foreach ($this->getOverridesIterator() as $pathToFileInOverrides) {
            $relativePathToFileInProject = $this->getRelativePathInProjectFromOverridePath($pathToFileInOverrides);
            if ($this->projectFileIsSameAsOverride($pathToFileInOverrides)) {
                $fileSame[] = $relativePathToFileInProject;
                continue;
            }
            $pathToFileInProject = $this->pathToProjectRoot . $relativePathToFileInProject;
            if (false === is_file($pathToFileInProject)) {
                throw new \RuntimeException('path ' . $pathToFileInProject . ' is not a file');
            }
            copy($pathToFileInProject, $pathToFileInOverrides);
            $filesUpdated[] = $relativePathToFileInProject;
        }

        return [$this->sortFiles($filesUpdated), $this->sortFiles($fileSame)];
    }
305395
protected function modifyModifiedClasses(&$pathnameArray) {
        foreach ($pathnameArray as $pathname => $phpClass) {
            if (file_exists($phpClass->getFile()->getPathname()) && $phpClass->getLastModified()->getTimestamp() != $phpClass->getFile()->getMTime()) {
                $file = $phpClass->getFile();

                $phpClass->clear();

                $result = $this->phpClassParser->parse($phpClass, $file);
                if ($result === false) {
                    unset($pathnameArray[$pathname]);
                }
            }
        }
    }
246514
protected function retrieveAllFiles(array $paths)
    {
        $files = [];

        foreach ($paths as $path) {
            $newFiles = [];

            try {
                $newFiles = $this->retrieveFiles($path);
            } catch (FileSystemException $e) {
                continue;
            } finally {
                $files = array_merge($files, $newFiles);
            }
        }

        return $files;
    }
1043323
public function detectChanges()
    {
        if ($this->changedFiles === null || $this->changedPaths === null) {
            $this->loadDetectedDirectoriesAndFiles();
            $changesDetected = false;
            $this->changedPaths = $this->changedFiles = [];
            $this->changedFiles = $this->detectChangedFiles($this->monitoredFiles);

            foreach ($this->monitoredDirectories as $path => $filenamePattern) {
                $changesDetected = $this->detectChangesOnPath($path, $filenamePattern) ? true : $changesDetected;
            }

            if ($changesDetected) {
                $this->saveDetectedDirectoriesAndFiles();
            }
            $this->directoriesAndFiles = null;
        }

        $changedFileCount = count($this->changedFiles);
        $changedPathCount = count($this->changedPaths);

        if ($changedFileCount > 0) {
            $this->emitFilesHaveChanged($this->identifier, $this->changedFiles);
        }
        if ($changedPathCount > 0) {
            $this->emitDirectoriesHaveChanged($this->identifier, $this->changedPaths);
        }
        if ($changedFileCount > 0 || $changedPathCount) {
            $this->logger->info(sprintf('File Monitor "%s" detected %s changed files and %s changed directories.', $this->identifier, $changedFileCount, $changedPathCount), LogEnvironment::fromMethodName(__METHOD__));
        }
    }
388178
private function searchFor($name, $withExtension)
    {
        $found = false;
        $fileName = $name;

        foreach (self::$paths as $path) {
            $fileName = "{$path}/$withExtension";
            if (is_file($fileName)) {
                $found = true;
                break;
            }
        }

        return [$found, $fileName];
    }
244268
private function getFiles($path)
    {
        $files = [];

        if (false !== $pos = strpos($path, '*')) {
            list($before, $after) = explode('*', $path, 2);
            $input = $this->fileLocator->locate($before).'*'.$after;

            if (false !== $paths = glob($input)) {
                foreach ($paths as $path) {
                    $files[] = $path;
                }
            }
        } else {
            $files = [$this->fileLocator->locate($path)];
        }

        return $files;
    }
63100
public function didChangeWatchedFiles(array $changes)
    {
        foreach ($changes as $change) {
            if ($change->type === FileChangeType::DELETED) {
                $this->client->textDocument->publishDiagnostics($change->uri, []);
            }
        }
    }
409231
public function getFiles() : array
    {
        Filesystem::checkExists($this->path);
        Filesystem::checkReadable($this->path);
        $contents = [];

        $files = scandir($this->path);
        foreach ($files as $file) {
            if($file != '.' && $file != '..') {
                $contents[] = Filesystem::get("$this->path/$file");
            }
        }
        return $contents;
    }
850920
public function files(String $path, String $extension = NULL) : Array
    {
        $list = ftp_nlist($this->connect, $path);

        if( ! empty($list) ) foreach( $list as $file )
        {
            if( $file !== '.' && $file !== '..' )
            {
                if( ! empty($extension) && $extension !== 'dir' )
                {
                    if( Filesystem::getExtension($file) === $extension )
                    {
                        $files[] = $file;
                    }
                }
                else
                {
                    if( $extension === 'dir' )
                    {
                        $extens = Filesystem::getExtension($file);

                        if( empty($extens) )
                        {
                            $files[] = $file;
                        }
                    }
                    else
                    {
                        $files[] = $file;
                    }
                }
            }
        }

        if( ! empty($files) )
        {
            return $files;
        }
        else
        {
            return [];
        }
    }
441118
public function hasFiles($name = null)
    {
        $files = $this->getFiles($name);

        if ($name === null) {
            foreach ($files as $name => $file) {
                if (empty($file)) {
                    return false;
                }
            }

            return true;
        } else {
            return !ArrayUtils::hasAllArrayValues($files);
        }
    }