Changeset View
Changeset View
Standalone View
Standalone View
core/kernel/utility/ClassDiscovery/ClassMapBuilder.php
Show First 20 Lines • Show All 167 Lines • ▼ Show 20 Line(s) | |||||
$this->load(self::CACHE_FILE_STRUCTURE, false); | $this->load(self::CACHE_FILE_STRUCTURE, false); | ||||
return array($this->classToFileMap, $this->classInfo); | return array($this->classToFileMap, $this->classInfo); | ||||
} | } | ||||
/** | /** | ||||
* Builds class map. | * Builds class map. | ||||
* | * | ||||
* @return void | * @return array | ||||
* @throws \RuntimeException When PHP parser not found. | * @throws \RuntimeException When PHP parser not found. | ||||
*/ | */ | ||||
public function build() | public function build() | ||||
{ | { | ||||
if ( !class_exists('PhpParser\Parser') ) { | if ( !class_exists('PhpParser\Parser') ) { | ||||
$error_msg = 'PHP Parser not found. Make sure, that Composer dependencies were '; | $error_msg = 'PHP Parser not found. Make sure, that Composer dependencies were '; | ||||
$error_msg .= 'installed using "php composer.phar install --dev" command.'; | $error_msg .= 'installed using "php composer.phar install --dev" command.'; | ||||
throw new \RuntimeException($error_msg); | throw new \RuntimeException($error_msg); | ||||
} | } | ||||
$table_output = array(); | |||||
$scan_path = preg_replace('/^' . preg_quote(FULL_PATH, '/') . '/', '...', $this->scanPath, 1); | $scan_path = preg_replace('/^' . preg_quote(FULL_PATH, '/') . '/', '...', $this->scanPath, 1); | ||||
echo $this->strPad('path "' . $scan_path . '"', 40); | $table_output[] = $scan_path; // The "Path" column. | ||||
$this->load(self::CACHE_FILE_STRUCTURE, true); | $this->load(self::CACHE_FILE_STRUCTURE, true); | ||||
$this->load(self::CACHE_FILE_HASHES, true); | $this->load(self::CACHE_FILE_HASHES, true); | ||||
$start = microtime(true); | $start = microtime(true); | ||||
$files = $this->scan(); | $files = $this->scan(); | ||||
echo $this->strPad('scanned in ' . sprintf('%.4f', microtime(true) - $start) . 's', 25); | $table_output[] = sprintf('%.4f', microtime(true) - $start) . 's'; // The "Scanned in" column. | ||||
$start = microtime(true); | $start = microtime(true); | ||||
$this->createParser(); | $this->createParser(); | ||||
foreach ( $files as $file ) { | foreach ( $files as $file ) { | ||||
$this->parseFile($file); | $this->parseFile($file); | ||||
} | } | ||||
echo $this->strPad('parsed in ' . sprintf('%.4f', microtime(true) - $start) . 's', 25); | $table_output[] = sprintf('%.4f', microtime(true) - $start) . 's'; // The "Parsed in" column. | ||||
echo PHP_EOL; | |||||
ksort($this->classToFileMap); | ksort($this->classToFileMap); | ||||
ksort($this->fileHashes); | ksort($this->fileHashes); | ||||
ksort($this->classInfo); | ksort($this->classInfo); | ||||
$this->store(self::CACHE_FILE_STRUCTURE); | $this->store(self::CACHE_FILE_STRUCTURE); | ||||
$this->store(self::CACHE_FILE_HASHES); | $this->store(self::CACHE_FILE_HASHES); | ||||
} | |||||
/** | return $table_output; | ||||
* Pads text with spaces from right side. | |||||
* | |||||
* @param string $text Text. | |||||
* @param integer $length Pad length. | |||||
* | |||||
* @return string | |||||
*/ | |||||
protected function strPad($text, $length) | |||||
{ | |||||
return str_pad($text, $length, ' ', STR_PAD_RIGHT); | |||||
} | } | ||||
/** | /** | ||||
* Loads cache from disk. | * Loads cache from disk. | ||||
* | * | ||||
* @param string $filename Filename. | * @param string $filename Filename. | ||||
* @param boolean $for_writing Load cache for writing or reading. | * @param boolean $for_writing Load cache for writing or reading. | ||||
* | * | ||||
▲ Show 20 Lines • Show All 144 Lines • ▼ Show 20 Line(s) | |||||
$cache = $this->prettyVarExport($cache); | $cache = $this->prettyVarExport($cache); | ||||
$at = '@'; | $at = '@'; | ||||
$file_content = <<<EOPHP | $file_content = <<<EOPHP | ||||
<?php | <?php | ||||
// {$at}codingStandardsIgnoreFile | // {$at}codingStandardsIgnoreFile | ||||
/** | /** | ||||
* This file is automatically {$at}generated. Use 'php tools/build_class_map.php' to rebuild it. | * This file is automatically {$at}generated. Please use 'in-portal classmap:rebuild' command to rebuild it. | ||||
*/ | */ | ||||
return {$cache}; | return {$cache}; | ||||
EOPHP; | EOPHP; | ||||
$file_path = $this->getCacheFilename($filename); | $file_path = $this->getCacheFilename($filename); | ||||
// Don't bother saving, because file wasn't even changed. | // Don't bother saving, because file wasn't even changed. | ||||
▲ Show 20 Lines • Show All 52 Lines • Show Last 20 Lines |