Beispiel #1
0
 public function writeLog()
 {
     $path = $this->getLogPath();
     predir($path);
     $log = $this->makeLogText();
     if (file_put_contents($path, $this->makeLogText())) {
         $this->console->println("Write references update log success!");
     }
     return $this;
 }
Beispiel #2
0
 public function cloneTemplates(string $baseDir)
 {
     foreach ($this->templates as $tpl) {
         $file = __DIR__ . '/Templates/' . $tpl;
         $target = $baseDir . '/Templates/' . $tpl;
         if (is_file($target) && !$this->isRecover) {
             $this->console->println('The template', $tpl, 'is existing!');
             continue;
         }
         if (file_put_contents(predir($target), file_get_contents($file))) {
             $this->console->println('The template', $tpl, 'clone success!');
         }
     }
 }
Beispiel #3
0
 protected function onExecute($argv = null)
 {
     $stub = $this->dir . '/stub';
     $class = static::class;
     $pathParam = FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME;
     try {
         $phar = new Phar(predir($this->getSavePath()), $pathParam, $this->getFileName());
         $phar->buildFromDirectory($this->dir, '/.php|.phtml|.inc|.tp|.txt|.json$/');
         $phar->addFromString('pack.txt', $class . " packed in " . date('Y-m-d H:i:s'));
         if (is_file($stub) && is_readable($stub)) {
             $phar->setStub(substitute(file_get_contents($stub), ['file' => $this->getFileName()]));
         }
         $this->console->println('Pack "' . $this->getFileName() . '" success, file export to "' . $this->getSavePath() . '"!');
     } catch (\Throwable $thrown) {
         $this->console->halt($thrown->getMessage());
     }
 }
Beispiel #4
0
 public function writeFile($file, array $data)
 {
     file_put_contents(predir($file), "<?php\r\nreturn " . var_export($data, true) . ";\r\n");
     return $this;
 }
Beispiel #5
0
 public function createFile($file, string $tpl = null, array $options)
 {
     $this->console->println("create file {$file}");
     $tpl = __DIR__ . '/Templates/' . $tpl;
     if (is_file($tpl)) {
         $tplContent = file_get_contents($tpl);
         if (!isset($options['replace']) || $options['replace'] !== false) {
             $tplContent = substitute($tplContent, $this->context);
         }
         if (file_put_contents(predir($file), $tplContent)) {
             $this->console->println("create file {$file} success!");
         } else {
             $this->console->println("create file {$file} lost!");
         }
     }
 }