src/objects/install/NamespaceResolver.php
public function getNamespace($file, $defaultToPath = false)
    {
        // massage file path into a format compatible with PSR-4 entries
        $file = str_replace('\\', '/', $file);
        $base = str_replace('\\', '/', base_path()) . '/';
        $file = str_replace($base, '', $file);

        // compare file path against existing entries
        foreach($this->namespaces as $ns => $path)
        {
            // convert paths to all use forward slashes
            $path = str_replace('\\', '/', $path);

            // if the file starts with the namespace path
            if(strpos($file, $path) === 0)
            {
                $file   = substr($file, strlen($path));
                $file   = preg_replace('%/[^/]+$%', '', $file);
                $file   = str_replace('/', '\\', $file);

                // defensive trim, in case any double slashes
                return trim($ns . $file, '\\');
            }
        }

        // namespace could not be resolved
        $info = pathinfo($file);

        return $defaultToPath
            ? str_replace('/', '\\', $info['dirname'])
            : null;

    }
public function getNamespace($file, $defaultToPath = false)
    {
        // massage file path into a format compatible with PSR-4 entries
        $file = str_replace('\\', '/', $file);
        $base = str_replace('\\', '/', base_path()) . '/';
        $file = str_replace($base, '', $file);

        // compare file path against existing entries
        foreach($this->namespaces as $ns => $path)
        {
            // convert paths to all use forward slashes
            $path = str_replace('\\', '/', $path);

            // if the file starts with the namespace path
            if(strpos($file, $path) === 0)
            {
                $file   = substr($file, strlen($path));
                $file   = preg_replace('%/[^/]+$%', '', $file);
                $file   = str_replace('/', '\\', $file);

                // defensive trim, in case any double slashes
                return trim($ns . $file, '\\');
            }
        }

        // namespace could not be resolved
        $info = pathinfo($file);

        return $defaultToPath
            ? str_replace('/', '\\', $info['dirname'])
            : null;

    }
public function getNamespace ( $ file , $ defaultToPath = false ) { // massage file path into a format compatible with PSR-4 entries $ file = str_replace ( '\\' , '/' , $ file ) ; $ base = str_replace ( '\\' , '/' , base_path ( ) ) . '/' ; $ file = str_replace ( $ base , '' , $ file ) ; // compare file path against existing entries foreach ( $ this -> namespaces as $ ns => $ path ) { // convert paths to all use forward slashes $ path = str_replace ( '\\' , '/' , $ path ) ; // if the file starts with the namespace path if ( strpos ( $ file , $ path ) === 0 ) { $ file = substr ( $ file , strlen ( $ path ) ) ; $ file = preg_replace ( '%/[^/]+$%' , '' , $ file ) ; $ file = str_replace ( '/' , '\\' , $ file ) ; // defensive trim, in case any double slashes return trim ( $ ns . $ file , '\\' ) ; } } // namespace could not be resolved $ info = pathinfo ( $ file ) ; return $ defaultToPath ? str_replace ( '/' , '\\' , $ info [ 'dirname' ] ) : null ; }
Attempts to get the namespace for a file

@param   string      $file               base-relative file path
@param   bool        $defaultToPath      flag to use file path as namespace if namespace cannot be matched
@return  null|string
Attempts to get the namespace for a file