Generate::generateFiles PHP Méthode

generateFiles() public méthode

public generateFiles ( )
    public function generateFiles()
    {
        date_default_timezone_set('UTC');
        $date = date('Y-m-d H:i:s');
        $lines = $this->domainWorker();
        $this->createApache($date, $lines);
        $this->createNginx($date, $lines);
        $this->createVarnish($date, $lines);
        $this->createIIS($date, $lines);
        $this->createGoogleExclude($lines);
    }

Usage Example

     * @param string $date
     * @param array $lines
     */
    public function createIIS($date, array $lines)
    {
        $file = __DIR__ . '/../web.config';
        $data = "<!-- " . $this->projectUrl . " -->\n<!-- Updated " . $date . " -->\n" . "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" . "<configuration>\n\t<system.webServer>\n\t\t<rewrite>\n\t\t\t<rules>\n";
        foreach ($lines as $line) {
            $data .= "\t\t\t\t<rule name=\"Referrer Spam " . $line . "\" stopProcessing=\"true\">" . "<match url=\".*\" /><conditions><add input=\"{HTTP_REFERER}\" pattern=\"(" . preg_quote($line) . ")\"/></conditions><action type=\"AbortRequest\" /></rule>\n";
        }
        $data .= "\t\t\t</rules>\n\t\t</rewrite>\n\t</system.webServer>\n</configuration>";
        $this->writeToFile($file, $data);
    }
    /**
     * @param array $lines
     */
    public function createGoogleExclude(array $lines)
    {
        $file = __DIR__ . '/../google-exclude.txt';
        $regexLines = [];
        foreach ($lines as $line) {
            $regexLines[] = preg_quote($line);
        }
        $data = implode('|', $regexLines);
        $this->writeToFile($file, $data);
    }
}
require __DIR__ . '/vendor/autoload.php';
$generator = new Generate();
$generator->generateFiles();