function registerTypesIn(string $path, $ignoreSameLevelFiles = false) {
        $path = \realpath($path);
        if(!$path) {
            throw new \RuntimeException('Invalid path specified');
        }
        
        $files = \CharlotteDunois\Livia\Utils\FileHelpers::recursiveFileSearch($path, '*.php');
        foreach($files as $file) {
            if($ignoreSameLevelFiles === true) {
                $filepath = \ltrim(\str_replace(array($path, '\\'), array('', '/'), $file), '/');
                if(\mb_substr_count($filepath, '/') === 0) {
                    continue;
                }
            } elseif(!empty($ignoreSameLevelFiles)) {
                $filepath = \ltrim(\str_replace(array($path, '\\'), array('', '/'), $file), '/');
                if(\mb_stripos($filepath, $ignoreSameLevelFiles) === 0) {
                    continue;
                }
            }
            
            $code = \file_get_contents($file);
            
            preg_match('/namespace(.*?);/i', $code, $matches);
            if(empty($matches[1])) {
                throw new \RuntimeException($file.' is not a valid argument type file');
            }
            
            $namespace = \trim($matches[1]);
            
            preg_match('/class(.*){?/i', $code, $matches);
            if(empty($matches[1])) {
                throw new \RuntimeException($file.' is not a valid argument type file');
            }
            
            $name = \trim(\explode('implements', \explode('extends', $matches[1])[0])[0]);
            $fqn = '\\'.$namespace.'\\'.$name;
            
            $type = new $fqn($this->client);
            $this->types->set($type->id, $type);
            
            $this->client->emit('debug', 'Registered type '.$type->id);
            $this->client->emit('typeRegister', $type, $this);
        }
        
        return $this;
    }
function registerTypesIn(string $path, $ignoreSameLevelFiles = false) {
        $path = \realpath($path);
        if(!$path) {
            throw new \RuntimeException('Invalid path specified');
        }
        
        $files = \CharlotteDunois\Livia\Utils\FileHelpers::recursiveFileSearch($path, '*.php');
        foreach($files as $file) {
            if($ignoreSameLevelFiles === true) {
                $filepath = \ltrim(\str_replace(array($path, '\\'), array('', '/'), $file), '/');
                if(\mb_substr_count($filepath, '/') === 0) {
                    continue;
                }
            } elseif(!empty($ignoreSameLevelFiles)) {
                $filepath = \ltrim(\str_replace(array($path, '\\'), array('', '/'), $file), '/');
                if(\mb_stripos($filepath, $ignoreSameLevelFiles) === 0) {
                    continue;
                }
            }
            
            $code = \file_get_contents($file);
            
            preg_match('/namespace(.*?);/i', $code, $matches);
            if(empty($matches[1])) {
                throw new \RuntimeException($file.' is not a valid argument type file');
            }
            
            $namespace = \trim($matches[1]);
            
            preg_match('/class(.*){?/i', $code, $matches);
            if(empty($matches[1])) {
                throw new \RuntimeException($file.' is not a valid argument type file');
            }
            
            $name = \trim(\explode('implements', \explode('extends', $matches[1])[0])[0]);
            $fqn = '\\'.$namespace.'\\'.$name;
            
            $type = new $fqn($this->client);
            $this->types->set($type->id, $type);
            
            $this->client->emit('debug', 'Registered type '.$type->id);
            $this->client->emit('typeRegister', $type, $this);
        }
        
        return $this;
    }
function registerTypesIn ( string $ path , $ ignoreSameLevelFiles = false ) { $ path = \ realpath ( $ path ) ; if ( ! $ path ) { throw new \ RuntimeException ( 'Invalid path specified' ) ; } $ files = \ CharlotteDunois \ Livia \ Utils \ FileHelpers :: recursiveFileSearch ( $ path , '*.php' ) ; foreach ( $ files as $ file ) { if ( $ ignoreSameLevelFiles === true ) { $ filepath = \ ltrim ( \ str_replace ( array ( $ path , '\\' ) , array ( '' , '/' ) , $ file ) , '/' ) ; if ( \ mb_substr_count ( $ filepath , '/' ) === 0 ) { continue ; } } elseif ( ! empty ( $ ignoreSameLevelFiles ) ) { $ filepath = \ ltrim ( \ str_replace ( array ( $ path , '\\' ) , array ( '' , '/' ) , $ file ) , '/' ) ; if ( \ mb_stripos ( $ filepath , $ ignoreSameLevelFiles ) === 0 ) { continue ; } } $ code = \ file_get_contents ( $ file ) ; preg_match ( '/namespace(.*?);/i' , $ code , $ matches ) ; if ( empty ( $ matches [ 1 ] ) ) { throw new \ RuntimeException ( $ file . ' is not a valid argument type file' ) ; } $ namespace = \ trim ( $ matches [ 1 ] ) ; preg_match ( '/class(.*){?/i' , $ code , $ matches ) ; if ( empty ( $ matches [ 1 ] ) ) { throw new \ RuntimeException ( $ file . ' is not a valid argument type file' ) ; } $ name = \ trim ( \ explode ( 'implements' , \ explode ( 'extends' , $ matches [ 1 ] ) [ 0 ] ) [ 0 ] ) ; $ fqn = '\\' . $ namespace . '\\' . $ name ; $ type = new $ fqn ( $ this -> client ) ; $ this -> types -> set ( $ type -> id , $ type ) ; $ this -> client -> emit ( 'debug' , 'Registered type ' . $ type -> id ) ; $ this -> client -> emit ( 'typeRegister' , $ type , $ this ) ; } return $ this ; }
Registers all types in a directory. Emits a typeRegister event for each type.
@param string       $path
@param bool|string  $ignoreSameLevelFiles  Ignores files in the specified directory and only includes files in sub directories. As string it will ignore the file if the filename matches with the string.
@return $this
@throws \RuntimeException
Registers all types in a directory . Emits a typeRegister event for each type .