Exemplo n.º 1
0
 public function write($path, $replacements = [], $info = null)
 {
     @mkdir($this->utils->dirname($path), 0777, true);
     if ($result = file_put_contents($path, $this->readData($replacements))) {
         $this->logger->info(($info ?? "Written file") . ": " . realpath($path));
         return $path;
     }
     throw new \Error("Cannot write file: {$path}");
 }
Exemplo n.º 2
0
 protected function startQueryLog()
 {
     $this->logFile = $this->tmpDir->getTempDir('logs') . '/query.log';
     @unlink($this->logFile);
     $this->connection->enableQueryLog();
     $this->logger->pushHandler(new StreamHandler($this->logFile, LoggerEx::INFO));
     $this->dispatcher->listen(QueryExecuted::class, function (QueryExecuted $query) {
         $sql = preg_replace_callback('/\\?/', function () use($query, &$index) {
             return sprintf("'%s'", $query->bindings[$index++ ?? 0]);
         }, $query->sql);
         $this->logger->info($sql);
     });
 }
Exemplo n.º 3
0
 public function newFunction($path, $func)
 {
     $code = file_get_contents($path);
     if (preg_match('/^(.*?)class/s', $code, $matches)) {
         $brackets = 1 + substr_count($matches[1], '{');
         $len = strlen($code);
         $pos = $len;
         while ($brackets-- > 0 && $pos !== false) {
             $pos = strrpos($code, '}', $pos - $len - 1);
         }
         if ($pos !== false) {
             $updated = sprintf("%s\n\n%s\n\t%s", trim(substr($code, 0, $pos)), $func, substr($code, $pos));
             if (file_put_contents($path, $updated)) {
                 $this->logger->info("Created new function in {$path}");
                 return true;
             }
         } else {
             trigger_error("Cannot modify file {$path}. Unable to find class brackets", E_WARNING);
         }
     }
     return false;
 }