コード例 #1
0
ファイル: Renderer.php プロジェクト: maslosoft/hedron
 /**
  * @param type $text
  */
 private function _wrapWithStars(&$text)
 {
     $newline = StringHelper::detectNewline($text);
     $text = preg_replace('~^(.*)~m', ' * \\1', $text);
     $text = preg_replace('~\\s+$~m', '', $text);
     $text = "/**{$newline}{$text}{$newline} */";
 }
コード例 #2
0
ファイル: Applier.php プロジェクト: maslosoft/hedron
 private function _applyHeaders($file, $checkOnly = false)
 {
     $this->processed++;
     $source = file_get_contents($file);
     $tokens = token_get_all($source);
     $ns = '';
     $line = 0;
     foreach ($tokens as $i => $token) {
         if (is_string($token)) {
             continue;
         }
         $type = array_shift($token);
         $value = array_shift($token);
         $line = array_shift($token);
         if ($type == T_NAMESPACE) {
             $ns = $tokens[$i + 2][1];
             break;
         }
     }
     if (!$line) {
         return;
     }
     if (!$ns) {
         return;
     }
     $n = StringHelper::detectNewline($source);
     $lines = array_slice(explode($n, $source), $line - 1);
     $new = sprintf("<?php{$n}{$n}%s{$n}{$n}%s", $this->renderer->render(), implode($n, $lines));
     if ($checkOnly) {
         if ($new == $source) {
             return false;
         } else {
             return true;
         }
     }
     if (is_writable($file)) {
         if ($new == $source) {
             $success = true;
         } else {
             $success = file_put_contents($file, $new);
         }
         $niceFile = ltrim($file, './\\');
         if ($success) {
             // Success
             if ($new == $source) {
                 if ($this->output->isVerbose()) {
                     $this->output->writeln(sprintf('<comment>Skipped</comment> %s', $niceFile));
                 }
             } else {
                 $this->output->writeln(sprintf('<info>Written</info> %s', $niceFile));
                 $this->success[] = true;
             }
         } else {
             // Fail
             $this->output->writeln(sprintf('Failed %s', $niceFile));
             $this->success[] = false;
         }
     } else {
         $this->success[] = false;
     }
 }