/** * Process current config. * * @param int $mode mode to run the process */ public function process($mode = self::MODE_NORMAL) { $license = $this->parseLicense($this->config->getLicense()); $finder = $this->config->getFinderBuilder()->build(); foreach ($finder->files() as $file) { $content = $file->getContents(); //convert line separators, force use Unix style if (strpos($content, "\r\n") !== false) { $content = str_replace("\r\n", "\n", $content); } $licensedContent = null; //match license in the file header if (preg_match('/^(?\'opentag\'(\\S{1,5})?\\n+)?(?\'license\'\\/\\**(\\s?\\**[\\S ]+\\n*)((?m)^\\s*\\*[\\S ]*\\n)+)/', $content, $matches)) { $phpHeader = $matches['opentag'] . $license; if ($matches[0] !== $phpHeader) { if ($this->logger) { $this->logger->updated($file); } $licensedContent = str_replace($matches[0], $phpHeader, $content); } else { if ($this->logger) { $this->logger->untouched($file); } } } else { if ($this->logger) { $this->logger->addition($file); } $licensedContent = preg_replace('/^(?\'opentag\'(\\S{1,5})?\\n{1,2})?/', '$1' . $license, $content); } if ($licensedContent !== null && $mode === self::MODE_NORMAL) { file_put_contents($file->getPathname(), $licensedContent); } } }