src/Watcher/Watcher.php
public function watchPath($path)
    {
        if (!$this->inotify) {
            $this->paths[] = $path;
            $this->addModifiedTimes($path);

            return;
        }

        $mask = IN_MODIFY | IN_ATTRIB | IN_CLOSE_WRITE | IN_MOVE | IN_CREATE |
                IN_DELETE | IN_DELETE_SELF | IN_MOVE_SELF;

        $directoryIterator = new \RecursiveDirectoryIterator(realpath($path));
        $subPaths = new \RecursiveIteratorIterator($directoryIterator);

        // Iterate over instances of \SplFileObject
        foreach ($subpaths as $subPath) {
            if ($subPath->isDir()) {
                $watchDescriptor = inotify_add_watch($this->inotify,
                    $subPath->getRealPath(), $mask);
                $this->paths[$watchDescriptor] = $subPath->getRealPath();
            }
        }
    }
public function watchPath($path)
    {
        if (!$this->inotify) {
            $this->paths[] = $path;
            $this->addModifiedTimes($path);

            return;
        }

        $mask = IN_MODIFY | IN_ATTRIB | IN_CLOSE_WRITE | IN_MOVE | IN_CREATE |
                IN_DELETE | IN_DELETE_SELF | IN_MOVE_SELF;

        $directoryIterator = new \RecursiveDirectoryIterator(realpath($path));
        $subPaths = new \RecursiveIteratorIterator($directoryIterator);

        // Iterate over instances of \SplFileObject
        foreach ($subpaths as $subPath) {
            if ($subPath->isDir()) {
                $watchDescriptor = inotify_add_watch($this->inotify,
                    $subPath->getRealPath(), $mask);
                $this->paths[$watchDescriptor] = $subPath->getRealPath();
            }
        }
    }
public function watchPath ( $ path ) { if ( ! $ this -> inotify ) { $ this -> paths [ ] = $ path ; $ this -> addModifiedTimes ( $ path ) ; return ; } $ mask = IN_MODIFY | IN_ATTRIB | IN_CLOSE_WRITE | IN_MOVE | IN_CREATE | IN_DELETE | IN_DELETE_SELF | IN_MOVE_SELF ; $ directoryIterator = new \ RecursiveDirectoryIterator ( realpath ( $ path ) ) ; $ subPaths = new \ RecursiveIteratorIterator ( $ directoryIterator ) ; // Iterate over instances of \SplFileObject foreach ( $ subpaths as $ subPath ) { if ( $ subPath -> isDir ( ) ) { $ watchDescriptor = inotify_add_watch ( $ this -> inotify , $ subPath -> getRealPath ( ) , $ mask ) ; $ this -> paths [ $ watchDescriptor ] = $ subPath -> getRealPath ( ) ; } } }
Adds the path to the list of files and folders to monitor for changes.
If the path is a file, its modification time is stored for comparison.
If a directory, the modification times for each sub-directory and file
are recursively stored.

@param string $path A valid path to a file or directory
Adds the path to the list of files and folders to monitor for changes . If the path is a file its modification time is stored for comparison . If a directory the modification times for each sub - directory and file are recursively stored .