Converts a file name to a namespaced class name.

@param string $file
@return string
486163
private static function convertFileToClass(string $file)
    {
        $fh = fopen($file, 'r');

        $namespace = '';

        while(($line = fgets($fh, 5000)) !== false) {

            if (str_contains($line, 'namespace')) {
                $namespace = trim(str_replace(['namespace', ';'], '', $line));
                break;
            }
        }

        fclose($fh);

        $class = basename(str_replace('.php', '', $file));

        return $namespace.'\\'.$class;
    }
1288609
public static function getClassesFromFile($file)
    {
        $php = \File::get($file);
        $classes = array();
        $tokens = token_get_all($php);
        $count = count($tokens);
        for ($i = 2; $i < $count; $i++) {
            if ($tokens[$i - 2][0] == T_CLASS
                && $tokens[$i - 1][0] == T_WHITESPACE
                && $tokens[$i][0] == T_STRING
            ) {
                $class_name = $tokens[$i][1];
                $namespace = self::getNamespace($tokens);
                $classes[] = $namespace . "\\" . $class_name;
            }
        }
        return $classes;
    }
201815
protected function get_folder_name( $class ) {
		if ( $class ) {
			$class = str_replace( $this->namespace, '', $class );
			$file  = explode( '\\', $class );
			$file  = end( $file );
			$class = str_replace( $file, '', $class );
			$class = strtolower( str_replace( '\\', '/', $class ) );

			return array(
				$class,
				str_replace( '_', '-', $class ),
				strtolower( $file ),
				str_replace( '-', '_', $class ),
			);
		}
		return false;
	}
162319
protected function getNamespace($file)
    {
        $basename = $this->packageInfo->get('basename');

        if ($this->packageInfo->get('type') == 'module') {
            $namespace = str_replace($this->packagesPath .DS .$basename, '', $file);
        } else {
            $namespace = str_replace($this->packagesPath .DS .$basename .DS .'src', '', $file);
        }

        $find = basename($namespace);

        $namespace = strrev(preg_replace(strrev("/$find/"), '', strrev($namespace), 1));

        $namespace = $this->packageInfo->get('namespace') .'\\' .trim($namespace, '\\/');

        return str_replace('/', '\\', $namespace);
    }
492186
private function fileNameToNamespaceParts(string $name)
    {
        $name = preg_replace('/(.*)(\.[\w\d]+)$/', '$1', $name);
        return array_map(function ($e) {
            $e = ucfirst($e);
            $e = implode("", array_map('ucfirst', explode(".", $e)));
            $e = implode("", array_map('ucfirst', explode("-", $e)));
            return $e;
        }, explode('/', $name));
    }
933462
public static function pathInfo($file)
    {
        $result = self::_pathInfo($file);
        return self::i()->dump($result, '! pathInfo (' . $file . ') !');
    }
1175475
public function convertToClassName ($table, $namespace = 'Sonic\\Model\\')
	{
		
		$arr		= explode ('_', $table);
		
		foreach ($arr as &$val)
		{
			$val = ucfirst (strtolower ($val));
		}
		
		return $namespace . implode ('\\', $arr);
		
	}
292912
private function _getExtension($file = null)
	{
		if (!is_null($file))
		{
			$dot = strrpos($file, '.') + 1;

			return strtolower(substr($file, $dot));
		}

		return '##INVALID_FILE##';
	}
26861
private function getClassFromFileAndBundle($file, BundleInterface $bundle)
    {
        $root = $bundle->getPath();

        if (0 !== strpos($file, $root)) {
            return;
        }

        $file = substr($file, strlen($root), -4);

        return sprintf('%s%s', $bundle->getNamespace(), str_replace(DIRECTORY_SEPARATOR, '\\', $file));
    }
295850
public function sanitizeFileName(string $file)
    {
        $file = preg_replace('/(\\\|\/)+/', DIRECTORY_SEPARATOR, $file);
        $file = ltrim($file, DIRECTORY_SEPARATOR);
        if (substr($file, -6) !== $this->extension) {
            $file .= $this->extension;
        }
        return $file;
    }
1179926
public function transformFileToFilePath($file)
    {
        //confirm we have a file
        $filePath = null;
        if (is_string($file)) {
            $filePath = $file;
        } elseif (is_object($file) && $file->is_a("File")) {
            $filePath = $file->Filename;
        }

        if (!$filePath) {
            throw new FileNotFoundException();
        }

        return $filePath;
    }
33439
private function getExamplePathFromSource(string $file): string
    {
        return sprintf(
            '%s%s%s',
            trim($this->getSourceDirectory(), '\\/'),
            DIRECTORY_SEPARATOR,
            trim($file, '"')
        );
    }
547642
protected function prepareSeedClass($file)
    {
        $extension = $file->getExtension();
        if ($extension !== 'php') {
            return null;
        }
        return '\\' . str_replace('.' . $extension, '', $file->getFilename());
    }
898978
public function getFilename($file)
    {
        // 获取文件的后缀名，因图片从剪贴板里黏贴时后缀名为空，所以此处确保后缀一直存在
        $this->extension = strtolower($file->getClientOriginalExtension()) ?: 'png';

        $randomName = str_random($this->randomLength);

        if ($this->filename) {
            return $this->filename . $this->extension;
        }

        if ($this->filePrefix) {
            return $this->filePrefix . '_' . $randomName . '.' . $this->extension;
        }

        return $randomName . '.' . $this->extension;
    }
497023
public static function getExtension($file){

		$file = trim($file);
		$extension = strtolower(substr(strrchr($file, '.'), 1));

		if($extension == $file){

			return '';
		}
		else{

			return $extension;
		}
	}
785102
public function createFileName($file)
    {
        if ( ! is_null($this->elfinderFilePath) ) {
            return $this->getFileName();
        }
        if ( is_string($file) ) {
            return substr( strrchr( $file, '/' ), 1 );
        }

        $filename = $file->getClientOriginalName();
        $mime = $file->getClientOriginalExtension();
        $parts = explode('.',$filename);
        array_pop($parts);
        return str_slug( implode(' ', $parts), '-' ) . '_' . time() .  '.' . $mime;
    }
936775
protected function get_file_name( $class ) {
		if ( $class ) {
			$file   = explode( '\\', $class );
			$file   = strtolower( end( $file ) );
			$file__ = str_replace( '_', '-', $file );
			$files  = array(
				$file . '.php', // File Name With _.
				$file__ . '.php', // File Name With - which is replaced by _.
				'class-' . $file__ . '.php', // File name With Class Prefixed.
				'class_' . $file__ . '.php', // File Name With - which is replaced by _.
			);
			return $files;
		}
		return false;
	}