Transform the class name to a filename

@param  string $class
@param  string $directory
@return string
348470
protected function transformClassNameToFilename($class, $directory)
    {
        // $class may contain a namespace portion, in  which case we need
        // to preserve any underscores in that portion.
        $matches = array();
        preg_match('/(?P<namespace>.+\\\)?(?P<class>[^\\\]+$)/', $class, $matches);

        $class     = (isset($matches['class'])) ? $matches['class'] : '';
        $namespace = (isset($matches['namespace'])) ? $matches['namespace'] : '';

        return $directory
             . str_replace(self::NS_SEPARATOR, '/', $namespace)
             . str_replace(self::PREFIX_SEPARATOR, '/', $class)
             . '.php';
    }
1051948
public static function _autoLoad($class)
    {
        $path="";
        foreach (self::$m_classMap as $namespace=>$dir){
            if(!empty($namespace) && strpos($class, $namespace)===0){
                $namespace=rtrim($namespace,"\\");
                $class=substr($class, strlen($namespace));
                $path = rtrim($dir,"/").str_replace("\\", "/", $class) . ".php";
                break;
            }
        }
        if(file_exists($path)){
            require_once $path;
        }
    }
232059
protected function className($classFile)
    {
        $classFile = str_replace($this->rootDir, "", $classFile);
        $className = str_replace(array(".php", "/"), array("", "_"), $classFile);

        return $className;
    }
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;
	}
1263919
static public function toClassShortName($class, $type='\\')
	{
	    if ($type !== '\\') {
	        $type = ucfirst(strtolower($type)) . '\\';
	    }
	    $class = str_replace('/', '\\', trim($class, '\\'));
	    $parts = explode($type, $class);
	    $item = array_pop($parts);
	    
	    $type = str_replace('\\', '', $type);
	    if ( $type && ($pos = strrpos($item, $type)) && ((strlen($item) - $pos) == strlen($type)) ) {
	        $item = substr($item, 0, $pos);
	    }
	    
	    return str_replace('\\', '/', $item);
	}
143347
public function copyDirectory($directory, $destination)
    {
        $files = $this->fileSystem->allFiles($directory);
        $fileDeployed = false;
        $this->fileSystem->copyDirectory($directory, $destination);

        foreach ($files as $file) {
            $fileContents = $this->fileSystem->get($file);
            $fileDeployed = $this->fileSystem->put($destination.'/'.$file->getRelativePathname(), $fileContents);
        }

        return $fileDeployed;
    }
95825
public function save($directory)
    {
        $parts = explode('_', $this->getClass());
        array_unshift($parts, $directory);
        $path = join(DIRECTORY_SEPARATOR, $parts) . '.php';
        self::saveToFile($path, $this->getSrc());
    }
585005
public String toClassName(final String filename) {
        return filename.substring(0, filename.lastIndexOf(".class"))
                .replace('/', '.').replace('\\', '.');
    }
743702
def generate_from_directory(cls, directory):
        
        files = [os.path.join(directory, f) for f in os.listdir(directory)
                 if os.path.isfile(os.path.join(directory, f))]
        return cls(files)
669259
public static function directory($directory = '.', $namespaceRoot = '')
    {
        spl_autoload_register(function ($className) use ($directory, $namespaceRoot) {
            $directory = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $directory);
            $directory = rtrim($directory, '/\\');
            $namespaceRoot = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $namespaceRoot);
            $namespaceRoot = trim($namespaceRoot, '/\\');
            $className = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $className);
            $className = trim($className, '/\\');
            if (substr($className, 0, strlen($namespaceRoot)) == $namespaceRoot) {
                $className = substr($className, strlen($namespaceRoot));
                $className = ltrim($className, '/\\');
            }
            $extensionList = array('php', 'class.php');
            foreach ($extensionList as $extension) {
                $file = $directory . DIRECTORY_SEPARATOR . $className . '.' . $extension;
                if (is_file($file) && is_readable($file)) {
                    require_once($file);
                }
            }
        });
    }
336695
public static function getClassShortName(
        string $class,
        string $suffix = ''
    ): string {
        $baseName = static::getClassBaseName($class);

        return preg_replace(sprintf('/%s$/', $suffix), '', $baseName);
    }
949964
public static function rootPath($directory) {
        $num = count(explode("/", $directory));
        $path = "";
        for ($i = 0; $i < $num; $i++)
            $path = self::join("..", $path);
        return $path;
    }
386345
public static function autoload($class)
    {
        if ($class === 'Cpdf') {
            require_once __DIR__ . "/../lib/Cpdf.php";
            return;
        }

        $prefixLength = strlen(self::PREFIX);
        if (0 === strncmp(self::PREFIX, $class, $prefixLength)) {
            $file = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, $prefixLength));
            $file = realpath(__DIR__ . (empty($file) ? '' : DIRECTORY_SEPARATOR) . $file . '.php');
            if (file_exists($file)) {
                require_once $file;
            }
        }
    }
352438
protected function rewriteClassMapWithLowerCaseClassNames($targetDir)
    {
        $classMapContents = file_get_contents($targetDir . '/autoload_classmap.php');
        $classMapContents = preg_replace_callback('/    \'[^\']*\' => /', function ($match) {
            return strtolower($match[0]);
        }, $classMapContents);
        file_put_contents($targetDir . '/autoload_classmap.php', $classMapContents);
    }
182955
private function saveClassToFile(PhpClass $class)
    {
        if ($this->isValidClass($class)) {
            $file = new PhpFile($class->getIdentifier());

            $namespace = $this->config->get('namespaceName');
            if (!empty($namespace)) {
                $file->addNamespace($namespace);
            }

            $file->addClass($class);
            $file->save($this->dir);
        }
    }
302743
public function getAliasForClassname(Classname $class)
    {
        foreach ($this->classnames as $c) {
            if ($c['classname']->equals($class)) {
                return str_replace('\\', '_', ltrim($class->classname, '\\'));
            }
        }

        return str_replace('\\', '_', ltrim($class->classname, '\\'));
    }
369529
private static function getFilename($name, $directory)
    {
        $filename = rtrim($directory, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
        $filename .= str_replace('.phar', '', $name) . '.phar';

        return $filename;
    }