public static function createPharArchive($arg, $origin_dir, $archive_file, $stub = null, $web_stub = null, $overwrite = false) { if (!extension_loaded('phar')) { throw new pakeException(__CLASS__ . ' module requires "phar" extension'); } if (false === $overwrite and file_exists($archive_file)) { return true; } if (!self::endsWith($archive_file, '.phar')) { throw new pakeException("Archive must have .phar extension"); } $files = pakeFinder::get_files_from_argument($arg, $origin_dir, true); pake_echo_action('file+', $archive_file); try { $arc = new Phar($archive_file); foreach ($files as $file) { $full_path = $origin_dir . '/' . $file; pake_echo_action('phar', '-> ' . $file); if (is_dir($full_path)) { $arc->addEmptyDir($file); } else { $arc->addFile($full_path, $file); } } if (null !== $stub) { pake_echo_action('phar', '[stub] ' . $stub . (null === $web_stub ? '' : ', ' . $web_stub)); $arc->setStub($arc->createDefaultStub($stub, $web_stub)); } } catch (PharException $e) { unset($arc); pake_remove($archive_file); throw $e; } }
public function add($files = null) { if (null === $files) { $files = array('--all'); } else { $files = pakeFinder::get_files_from_argument($files, $this->repository_path, true); } $this->git_run('add ' . implode(' ', array_map('escapeshellarg', $files))); return $this; }
function pake_strip_php_comments($arg, $target_dir = '') { /* T_ML_COMMENT does not exist in PHP 5. * The following three lines define it in order to * preserve backwards compatibility. * * The next two lines define the PHP 5-only T_DOC_COMMENT, * which we will mask as T_ML_COMMENT for PHP 4. */ if (!defined('T_ML_COMMENT')) { define('T_ML_COMMENT', T_COMMENT); } else { if (!defined('T_DOC_COMMENT')) { define('T_DOC_COMMENT', T_ML_COMMENT); } } $files = pakeFinder::get_files_from_argument($arg, $target_dir); foreach ($files as $file) { if (!is_file($file)) { continue; } $source = file_get_contents($file); $output = ''; $tokens = token_get_all($source); foreach ($tokens as $token) { if (is_string($token)) { // simple 1-character token $output .= $token; } else { // token array list($id, $text) = $token; switch ($id) { case T_COMMENT: case T_ML_COMMENT: // we've defined this // we've defined this case T_DOC_COMMENT: // and this // no action on comments break; default: // anything else -> output "as is" $output .= $text; break; } } } file_put_contents($file, $output); } }