Generates new file and return cachefile name
@param $classFile

@return string
180507
protected function updateAndGetCacheFileName($classFile)
    {
        $className = $this->className($classFile);

        if($this->hasChanged($classFile)){
            $content = $this->processClass($classFile);
            $this->writeCache($className, $content);
            $this->setDateFromClassFile($classFile);
        }

        return $this->cacheFile($className);
    }
329516
public function createFile()
    {
        $cacheDependencyFileName = $this->getDependencyFileName();
        if ( ! file_exists(dirname($cacheDependencyFileName)) ) {
            FileHelper::createDirectory(dirname($cacheDependencyFileName));
        }
        file_put_contents($cacheDependencyFileName, uniqid());
        return $cacheDependencyFileName;
    }
506491
public function createProxy($class, &$proxyFile = null)
    {
        $proxyClass = $this->getProxyClass($class);
        $class      = '\\'.rtrim($class, '\\');
        $proxyFile  = $this->proxyDirectory.'/'.$proxyClass.'.php';

        if (class_exists($proxyClass)) {
            return $proxyClass;
        }

        if (file_exists($proxyFile)) {
            require $proxyFile;

            return $proxyClass;
        }

        $content = file_get_contents(dirname(__DIR__).'/Resources/proxy/template.php');
        $content = str_replace('__TPL_CLASS__', $proxyClass, $content);
        $content = str_replace('__TPL_EXTENDS__', $class, $content);

        $this->checkProxyDirectory();
        file_put_contents($proxyFile, $content);
        require $proxyFile;

        return $proxyClass;
    }
451373
public function needsRebuild($cacheFile)
    {
        $needsRebuild = true;

        if ($this->serializeCache->exists($cacheFile)) {
            try {
                $needsRebuild = time() - $this->ttl >= $this->serializeCache->mtime($cacheFile);
            } catch (\RuntimeException $e) {
            }
        }

        return $needsRebuild;
    }
1062704
public function getData($paths, $cacheFile = false)
    {
        $data = null;

        if (is_string($paths)) {
            $paths = array(
                'corePath' => $paths,
            );
        }

        if ($cacheFile && file_exists($cacheFile) && $this->getConfig()->get('useCache')) {
            $data = $this->getFileManager()->getPhpContents($cacheFile);
        } else {
            $data = $this->getClassNameHash($paths['corePath']);

            if (isset($paths['modulePath'])) {
                foreach ($this->getMetadata()->getModuleList() as $moduleName) {
                    $path = str_replace('{*}', $moduleName, $paths['modulePath']);

                    $data = array_merge($data, $this->getClassNameHash($path));
                }
            }

            if (isset($paths['customPath'])) {
                $data = array_merge($data, $this->getClassNameHash($paths['customPath']));
            }

            if ($cacheFile && $this->getConfig()->get('useCache')) {
                $result = $this->getFileManager()->putPhpContents($cacheFile, $data);
                if ($result == false) {
                    throw new \Espo\Core\Exceptions\Error();
                }
            }
        }

        return $data;
    }
353195
public static function getCacheLocation($imageFile, $width) {
    // get file name and cache directory
    $baseName = FileUtil::basename($imageFile);
    $directory = self::getCacheDir($imageFile);
    return self::makeRelative($directory.(strlen($width) > 0 ? $width.'-' : '').$baseName);
  }
66278
protected function getMethodFileAddedName(File $phpCsFile): string
    {
        return $this->getModule($phpCsFile) . $this->getLayer($phpCsFile) . 'Factory';
    }
1286168
private function prepareStoragePathForClass($className)
    {
        $filePath = $this->buildStoragePath($className);
        if (!file_exists($filePath)) {
            mkdir($filePath, $this->fileModeBits, true);
        }
        return $filePath;
    }
968679
public function findFile($class)
    {
        if (false !== $pos = strrpos($class, '\\')) {
            // namespaced class name
            $classPath = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, 0, $pos)).DIRECTORY_SEPARATOR;
            $className = substr($class, $pos + 1);
        } else {
            // PEAR-like class name
            $classPath = null;
            $className = $class;
        }

        $classPath .= str_replace('_', DIRECTORY_SEPARATOR, $className).'.php';

        foreach ($this->prefixes as $prefix => $dirs) {
            if (0 === strpos($class, $prefix)) {
                foreach ($dirs as $dir) {
                    if (file_exists($dir.DIRECTORY_SEPARATOR.$classPath)) {
                        return $dir.DIRECTORY_SEPARATOR.$classPath;
                    }
                }
            }
        }

        foreach ($this->fallbackDirs as $dir) {
            if (file_exists($dir.DIRECTORY_SEPARATOR.$classPath)) {
                return $dir.DIRECTORY_SEPARATOR.$classPath;
            }
        }

        if ($this->useIncludePath && $file = stream_resolve_include_path($classPath)) {
            return $file;
        }
    }
1080973
protected function getCache(): PhpFileCache
    {
        if ($this->_cache === null)
            $this->_cache = new PhpFileCache($this->getCacheDir());

        return $this->_cache;
    }
525593
protected function loadClassFromFile(string $annotationFile): string
    {
        $tokens = \token_get_all(\file_get_contents($annotationFile));
        $hasClass = false;
        $class = null;
        $hasNamespace = false;
        $namespace = '';

        for ($i = 0, $length = \count($tokens); $i < $length; $i++) {
            $token = $tokens[$i];

            if (!\is_array($token)) {
                continue;
            }

            if ($hasClass && $token[0] === T_STRING) {
                $class = $namespace . '\\' . $token[1];

                break;
            }

            if ($hasNamespace && $token[0] === T_STRING) {
                $namespace = '';

                do {
                    $namespace .= $token[1];

                    $token = $tokens[++$i];
                } while ($i < $length && \is_array($token) && \in_array($token[0], [T_NS_SEPARATOR, T_STRING], true));

                $hasNamespace = false;
            }

            if ($token[0] === T_CLASS) {
                $hasClass = true;
            }
            if ($token[0] === T_NAMESPACE) {
                $hasNamespace = true;
            }
        }

        return $class ?: '';
    }
536706
public function findFile($class) {
		if ('\\' === $class[0]) {
			$class = substr($class, 1);
		}

		if (isset($this->classMap[$class])) {
			return $this->classMap[$class];
		}
		elseif ($this->classMapAuthoratative) {
			return false;
		}

		$classPath = $this->getClassPath($class);

		foreach ($this->prefixes as $prefix => $dirs) {
			if (0 === strpos($class, $prefix)) {
				foreach ($dirs as $dir) {
					if (file_exists($dir.DIRECTORY_SEPARATOR.$classPath)) {
						return $dir.DIRECTORY_SEPARATOR.$classPath;
					}
				}
			}
		}

		foreach ($this->fallbackDirs as $dir) {
			if (file_exists($dir.DIRECTORY_SEPARATOR.$classPath)) {
				return $dir.DIRECTORY_SEPARATOR.$classPath;
			}
		}

		if ($this->useIncludePath && $file = self::resolveIncludePath($classPath)) {
			return $file;
		}

		return $this->classMap[$class] = false;
	}
1336501
protected function doGenerate($className, $file)
    {
        $resourceDataForGenerator = $this->loadResourceGeneratorData($file);

        try {
            $visitors = $this->prepareVisitors($file);

            return $this->getGenerator()->generate($className, $resourceDataForGenerator, $visitors);
        } catch (SyntaxException $e) {
            $message = $e->getMessage() . "\n" . $this->dumpSource($e->getSource());
            $message .= str_repeat("\n", 2) . 'Filename: ' . $file;

            throw new \RuntimeException($message, 0, $e);
        }
    }
807505
protected function setDateFromClassFile($classFile)
    {
        $className = $this->className($classFile);
        $cacheFile = $this->cacheFile($className);
        $fileDate  = filemtime($classFile);
        touch($cacheFile, $fileDate);
    }
339814
private function createFileCache():File
    {
        /** @var IConfig $config */
        $config = $this->di->getShared('config');
        /** @var IApp $app */
        $app = $this->di->getShared('app');
        $lifetime = (int)$config->get($this->getName() . '.lifetime', 3600);
        $cacheDir = $app->getCacheDir();
        $frontCache = new FrontData([
            "lifetime" => $lifetime
        ]);
        return new File($frontCache, ['cacheDir' => $cacheDir]);

    }
631170
protected function getModule(File $phpCsFile): string
    {
        $className = $this->getClassName($phpCsFile);
        $classNameParts = explode('\\', $className);

        if (count($classNameParts) < 3) {
            return '';
        }

        return $classNameParts[2];
    }
747762
public function findFile($class)
    {
        $findFile = $this->_findFile;
        $file = static::originalInstance()->{$findFile}($class);
        if ($file !== false) {
            $file = realpath($file);
        }
        return $this->_patchers->findFile($this, $class, $file);
    }