<?php

$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar';
$tname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
$alias = 'phar://hio';
$phar = new Phar($fname);
$phar['a.php'] = '<?php echo "This is a\\n"; include "' . $alias . '/b.php"; ?>';
$phar->setAlias('hio');
$phar->addEmptyDir('test');
$phar->stopBuffering();
copy($fname, $tname);
$phar->setAlias('hio2');
try {
    $p = new Phar($tname);
} catch (Exception $e) {
    echo $e->getMessage() . "\n";
}
?>
===DONE===
예제 #2
0
<?php

$fname = dirname(__FILE__) . '/tempmanifest2.phar.php';
$pname = 'phar://' . $fname;
$phar = new Phar($fname);
$phar->setDefaultStub();
$phar->setAlias('fred');
$phar['file1.txt'] = 'hi';
$phar['file2.txt'] = 'hi2';
$phar['subdir/ectory/file.txt'] = 'hi3';
$phar->mount($pname . '/mount2', __FILE__);
$phar->addEmptyDir('one/level');
$phar->extractTo(dirname(__FILE__) . '/extract2', 'mount2');
$phar->extractTo(dirname(__FILE__) . '/extract2');
$out = array();
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator(dirname(__FILE__) . '/extract2', 0x3000), RecursiveIteratorIterator::CHILD_FIRST) as $path => $file) {
    $extracted[] = $path;
}
sort($extracted);
foreach ($extracted as $out) {
    echo "{$out}\n";
}
?>
===DONE===
<?php 
@unlink(dirname(__FILE__) . '/tempmanifest2.phar.php');
$dir = dirname(__FILE__) . '/extract2/';
@unlink($dir . 'file1.txt');
@unlink($dir . 'file2.txt');
@unlink($dir . 'subdir/ectory/file.txt');
@rmdir($dir . 'subdir/ectory');
예제 #3
0
<?php

$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
$phar = new Phar($fname);
$phar['a/b'] = 'file contents
this works';
$phar->addEmptyDir('hi');
echo $phar['a/b']->getContent() . "\n";
try {
    echo $phar['a']->getContent(), "\n";
} catch (Exception $e) {
    echo $e->getMessage(), "\n";
}
try {
    echo $phar['hi']->getContent(), "\n";
} catch (Exception $e) {
    echo $e->getMessage(), "\n";
}
?>
===DONE===
<?php 
error_reporting(0);
unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php');
__halt_compiler();
?>
예제 #4
0
파일: rmdir.php 프로젝트: badlamer/hhvm
<?php

$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip';
$alias = 'phar://' . $fname;
$phar = new Phar($fname);
$phar->setStub("<?php\nPhar::mapPhar('hio');\n__HALT_COMPILER(); ?>");
$phar->addEmptyDir('a');
$phar['a/x'] = 'a';
$phar->stopBuffering();
include $fname;
echo file_get_contents($alias . '/a/x') . "\n";
var_dump(rmdir($alias . '/a'));
echo file_get_contents($alias . '/a/x') . "\n";
unlink($alias . '/a/x');
var_dump(rmdir($alias . '/a'));
error_reporting(0);
unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip');
예제 #5
0
<?php

$fname = dirname(__FILE__) . '/tempmanifest1.phar.php';
$pname = 'phar://' . $fname;
$a = new Phar($fname);
$a['file1.txt'] = 'hi';
$a['file2.txt'] = 'hi2';
$a['subdir/ectory/file.txt'] = 'hi3';
$a->mount($pname . '/mount', __FILE__);
$a->addEmptyDir('one/level');
$a->extractTo(dirname(__FILE__) . '/extract', 'mount');
$a->extractTo(dirname(__FILE__) . '/extract');
$out = array();
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator(dirname(__FILE__) . '/extract', 0x3000), RecursiveIteratorIterator::CHILD_FIRST) as $p => $b) {
    $out[] = $p;
}
sort($out);
foreach ($out as $b) {
    echo "{$b}\n";
}
$a->extractTo(dirname(__FILE__) . '/extract1', 'file1.txt');
var_dump(file_get_contents(dirname(__FILE__) . '/extract1/file1.txt'));
$a->extractTo(dirname(__FILE__) . '/extract1', 'subdir/ectory/file.txt');
var_dump(file_get_contents(dirname(__FILE__) . '/extract1/subdir/ectory/file.txt'));
$a->extractTo(dirname(__FILE__) . '/extract1-2', array('file2.txt', 'one/level'));
var_dump(file_get_contents(dirname(__FILE__) . '/extract1-2/file2.txt'));
var_dump(is_dir(dirname(__FILE__) . '/extract1-2/one/level'));
try {
    $a->extractTo(dirname(__FILE__) . '/whatever', 134);
} catch (Exception $e) {
    echo $e->getMessage(), "\n";
예제 #6
0
파일: Phar.php 프로젝트: peopleplan/Pyrus
 /**
  * Create an internal directory, creating parent directories as needed
  *
  * @param string $dir
  */
 function mkdir($dir)
 {
     $this->phar->addEmptyDir($dir);
 }
예제 #7
0
파일: mkdir.php 프로젝트: badlamer/hhvm
<?php

$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
$pname = 'phar://' . $fname;
Phar::interceptFileFuncs();
mkdir('phar://');
mkdir('phar://foo.phar');
$a = new Phar($fname);
$a['a'] = 'hi';
mkdir($pname . '/a');
rmdir('phar://');
rmdir('phar://foo.phar');
rmdir($pname . '/a');
$a->addEmptyDir('bb');
$a->addEmptyDir('bb');
try {
    $a->addEmptyDir('.phar');
} catch (Exception $e) {
    echo $e->getMessage(), "\n";
}
?>
===DONE===
<?php 
error_reporting(0);
unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php');
__halt_compiler();
?>
예제 #8
0
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
LICENSE;
$file = 'psx-' . VERSION . '.phar';
$dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(PATH), RecursiveIteratorIterator::SELF_FIRST);
$phar = new Phar($file, 0, $file);
$phar->setMetadata($license);
foreach ($dir as $file) {
    $path = (string) $file;
    $name = substr($path, 12);
    // remove psx/library/ from path
    if ($file->isFile()) {
        $phar->addFromString($name, php_strip_whitespace($path));
    } else {
        if ($file->isDir() && $file->getFilename() != '.' && $file->getFilename() != '..') {
            $phar->addEmptyDir($name);
        }
    }
    echo 'A ' . $name . "\n";
}
    $a->copy('a', 'b');
} catch (Exception $e) {
    echo $e->getMessage() . "\n";
}
$a->offsetExists(array());
$a->offsetGet(array());
ini_set('phar.readonly', 0);
$a->offsetSet(array());
ini_set('phar.readonly', 1);
$b->offsetUnset(array());
try {
    $a->offsetUnset('a');
} catch (Exception $e) {
    echo $e->getMessage() . "\n";
}
$a->addEmptyDir(array());
$a->addFile(array());
$a->addFromString(array());
try {
    $a->setMetadata('a');
} catch (Exception $e) {
    echo $e->getMessage() . "\n";
}
ini_set('phar.readonly', 0);
$a->setMetadata(1, 2);
ini_set('phar.readonly', 1);
try {
    $a->delMetadata();
} catch (Exception $e) {
    echo $e->getMessage() . "\n";
}
예제 #10
0
 $iterator = new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::SELF_FIRST);
 if ($options['exclude_files'] || $options['exclude_dirs']) {
     $iterator = new ExcludeFilesIterator($iterator, $options['exclude_files'], $options['exclude_dirs']);
 }
 // buildFromIterator unfortunately sucks and skips nested directories (?)
 foreach ($iterator as $file) {
     if (!$iterator->isDot()) {
         if (!QUIET_MODE) {
             echo "adding " . $file . PHP_EOL;
         }
         if ($file->isFile()) {
             $phar->addFile($file, strip_from_beginning($options['src'], $file));
         }
         if ($file->isDir()) {
             // this also doesn't work :(
             $phar->addEmptyDir(strip_from_beginning($options['src'], $file));
         }
     }
 }
 //$phar->buildFromIterator($iterator, $options['src']);
 // unfortunately Phar disables openssl signing for compressed archives
 // $phar->compress(PHAR::GZ);
 if ($options['stub']) {
     if (!QUIET_MODE) {
         echo "Setting stub from {$options['stub']}" . PHP_EOL;
     }
     $phar->setStub(file_get_contents($options['stub']));
 }
 if (!$options['nosign']) {
     // apply the signature
     if (!QUIET_MODE) {
예제 #11
0
 /**
  * Compresses a directory into the archive
  * @param \Phar $archive Phar object of PHP
  * @param zibo\library\filesystem\File $dir The directory to compress in the archive
  * @param zibo\library\filesystem\File $prefix The path for the directory in the archive
  * @return null
  */
 private function compressDirectory(PhpPhar $archive, File $dir, File $prefix)
 {
     $children = $dir->read();
     if (empty($children)) {
         $archive->addEmptyDir(new File($prefix->getPath(), $dir->getName()));
     } else {
         foreach ($children as $file) {
             $this->compressFile($archive, $file, $prefix);
         }
     }
 }
예제 #12
0
파일: bug46178.php 프로젝트: alphaxxl/hhvm
<?php

$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar';
$phar = new Phar($fname);
$phar['long/path/name.txt'] = 'hi';
$phar->addEmptyDir('long/path');
?>
===DONE===
<?php 
unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar');
예제 #13
0
파일: pharExport.php 프로젝트: cebe/chive
exec("rm chive/yii/web/js/source/treeview -rf");
exec("rm chive/yii/web/js/source/yiitab -rf");
exec("rm chive/yii/web/js/source/jquery.js");
exec("rm chive/yii/web/widgets/captcha -rf");
exec("rm chive/yii/zii -rf");
// Add all files
$sourceDir = __DIR__ . "/chive";
$i = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($sourceDir), RecursiveIteratorIterator::SELF_FIRST);
foreach ($i as $file) {
    $basename = basename($file);
    if ($basename[0] == ".") {
        continue;
    }
    $targetPath = substr($file, strlen($sourceDir) + 1);
    if (is_dir($file)) {
        $phar->addEmptyDir($targetPath);
    } elseif (!substr_compare($file, ".php", -4)) {
        // Get content
        echo "- Adding PHP " . $file . "\n";
        $content = php_strip_whitespace($file);
        $content = str_replace("realpath(", "ltrim(", $content);
        file_put_contents($file, $content);
        $phar->addFile($file, $targetPath);
    } elseif (!substr_compare($file, ".js", -3)) {
        echo "- Adding JS " . $file . "\n";
        exec("./jsmin <" . $file . " >" . $file . ".min");
        unlink($file);
        $phar->addFile($file . ".min", $targetPath);
    } elseif (!substr_compare($file, ".xml", -4) && strpos($file, $sourceDir . "/protected/messages/") === 0) {
        echo "- Adding XML " . $file . "\n";
        $content = gzcompress(file_get_contents($file), 9);
예제 #14
0
 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;
     }
 }