/** * Entry point of routine work * * @static * @param string $workingDir * @param array $config * @param array $blackList * @return null */ public static function run($workingDir, $config, $blackList) { // various display parameters $workingDir = realpath($workingDir); self::$_workingDirLen = strlen($workingDir); self::$_errorsCount = 0; self::$_updatedCount = 0; self::$_skippedCount = 0; // set black list self::$skipFiles = array(); self::$skipDirectories = array(); self::_setSkippedPaths($workingDir, $blackList); $licenseInstances = array(); foreach ($config as $path => $types) { // whether to scan directory recursively $recursive = isset($types['_recursive']) ? $types['_recursive'] : true; unset($types['_recursive']); // update licenses foreach ($types as $fileType => $licenseType) { if (!isset($licenseInstances[$licenseType])) { $licenseInstances[$licenseType] = Routine::createLicenseInstance($licenseType); } Routine::updateLicense(array($workingDir . ($path ? DIRECTORY_SEPARATOR . $path : '')), Routine::$fileTypes[$fileType], $licenseInstances[$licenseType], $recursive); } } Routine::printLog(sprintf("\n" . 'Updated: %d; Skipped: %d; Errors: %d.' . "\n", self::$_updatedCount, self::$_skippedCount, self::$_errorsCount)); if (self::$_errorsCount || self::$_skippedCount) { throw new Exception('Failed: check skipped files or errors.' . "\n"); } Routine::printLog('Success.' . "\n"); }
USAGE ); $options = getopt('e:w:vd0'); if (!isset($options['e'])) { print USAGE; exit(1); } if (isset($options['v'])) { Routine::$isVerbose = true; } $dryRun = false; if (isset($options['d'])) { Routine::$dryRun = true; } $workingDir = '.'; if (isset($options['w'])) { $workingDir = rtrim($options['w'], DIRECTORY_SEPARATOR); } if (!is_dir($workingDir)) { Routine::printLog("Directory '{$workingDir}' does not exist.\n"); exit(1); } $config = (require __DIR__ . "/conf/{$options['e']}.php"); $blackList = (require __DIR__ . '/../../../../dev/tools/license_placeholder/blacklist.php'); try { Routine::run($workingDir, $config, $blackList); } catch (Exception $e) { Routine::printLog($e->getMessage()); exit(isset($options['0']) ? 0 : 1); }