Пример #1
0
 public static function updateConfig($key, $value)
 {
     /** @var XenForo_Application $app */
     $app = XenForo_Application::getInstance();
     $path = $app->getRootDir() . '/library/config.php';
     $originalContents = file_get_contents($path);
     $varNamePattern = '#(\\n|^)(?<varName>\\$config';
     foreach (explode('.', $key) as $i => $keyPart) {
         // try to match the quote
         $varNamePattern .= '\\[([\'"]?)' . preg_quote($keyPart, '#') . '\\' . ($i + 3) . '\\]';
     }
     $varNamePattern .= ').+(\\n|$)#';
     $candidates = array();
     $offset = 0;
     while (true) {
         if (!preg_match($varNamePattern, $originalContents, $matches, PREG_OFFSET_CAPTURE, $offset)) {
             break;
         }
         $offset = $matches[0][1] + strlen($matches[0][0]);
         $candidates[] = $matches;
     }
     if (count($candidates) !== 1) {
         XenForo_Helper_File::log(__METHOD__, sprintf('count($candidates) = %d', count($candidates)));
         return;
     }
     $matches = reset($candidates);
     $replacement = $matches[1][0] . $matches['varName'][0] . ' = ' . var_export($value, true) . ';' . $matches[5][0];
     $contents = substr_replace($originalContents, $replacement, $matches[0][1], strlen($matches[0][0]));
     DevHelper_Generator_File::writeFile($path, $contents, true, false);
 }
Пример #2
0
    public static function generateOurClass($clazz, DevHelper_Config_Base $config)
    {
        $path = DevHelper_Generator_File::getClassPath($clazz);
        $contents = <<<EOF
<?php

class {$clazz} extends XFCP_{$clazz}
{
}
EOF;
        return DevHelper_Generator_File::writeFile($path, $contents, true, false) === true;
    }
Пример #3
0
 protected static function _write(array $addOn, DevHelper_Config_Base $config, $contents)
 {
     $className = self::getClassName($addOn, $config);
     $path = DevHelper_Generator_File::getClassPath($className);
     return DevHelper_Generator_File::writeFile($path, $contents, true, false) === true;
 }