Ejemplo n.º 1
0
 /**
  * Initialize the package creator
  */
 function init()
 {
     try {
         if (file_exists($this->path)) {
             @unlink($this->path);
         }
         $ext = strstr(strrchr($this->path, '-'), '.');
         if (!$ext) {
             $ext = strstr(strrchr($this->path, '/'), '.');
             if (!$ext) {
                 $ext = strstr(strrchr($this->path, '\\'), '.');
             }
         }
         if (!$ext) {
             $ext = strstr($this->path, '.');
         }
         $a = $this->_classname;
         $this->phar = new $a($this->path);
         if ($this->phar instanceof Phar) {
             $this->phar = $this->phar->convertToExecutable($this->format, $this->compression, $ext);
         } else {
             $this->phar = $this->phar->convertToData($this->format, $this->compression, $ext);
         }
         $this->phar->startBuffering();
         if ($this->phar instanceof Phar) {
             $this->phar->setStub($this->stub);
         }
         if ($this->format == Phar::ZIP) {
             $this->compression = $comp;
         }
     } catch (Exception $e) {
         throw new \Pyrus\Developer\Creator\Exception('Cannot open Phar archive ' . $this->path, $e);
     }
     $this->_started = false;
 }
Ejemplo n.º 2
0
function buildModulePhar($name, $format = Phar::PHAR, $compression = Phar::NONE, $executable = true, $fake = false)
{
    echo "Building {$name}...\t";
    $glob = glob($name.'.*');
    if (count($glob) > 0) {
        foreach ($glob as $file) {
            if (!is_dir($file)) {
                unlink($file);
            }   
        }
    }
    $filename = $name . '.phar';
    $phar = new Phar($filename);
    if ($fake) {
        $phar['Module.php'] = '<?php //no class here';
    } else {
        $phar['Module.php'] = "<?php \n\nnamespace $name;\n\nclass Module\n{}";
    }
    if (false === $executable) {
        $phar->convertToData($format, $compression);
    } else {
        $phar->setDefaultStub('Module.php', 'Module.php');
        if ($format !== Phar::PHAR || $compression !== Phar::NONE) {
            $phar->convertToExecutable($format, $compression);
        }
    }
    if ($format !== Phar::PHAR || $compression !== Phar::NONE) {
        unlink($filename);
    }
    echo "Done!\n";
}
Ejemplo n.º 3
0
$files['b'] = 'b';
$files['c'] = 'c';
include 'files/phar_test.inc';
$phar = new Phar($fname);
$gz = $phar->compress(Phar::GZ);
copy($gz->getPath(), $fname2);
$a = new Phar($fname2);
var_dump($a->isCompressed());
$unc = $a->compress(Phar::NONE);
echo $unc->getPath() . "\n";
$unc2 = $gz->decompress();
echo $unc2->getPath() . "\n";
$unc3 = $gz->decompress('hooba.phar');
echo $unc3->getPath() . "\n";
$gz->decompress(array());
$zip = $phar->convertToData(Phar::ZIP);
ini_set('phar.readonly', 1);
try {
    $gz->decompress();
} catch (Exception $e) {
    echo $e->getMessage() . "\n";
}
try {
    $zip->decompress();
} catch (Exception $e) {
    echo $e->getMessage() . "\n";
}
?>
===DONE===
<?php 
unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php');
<?php

$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar';
$pname = 'phar://' . $fname;
$phar = new Phar($fname);
$phar['a/b'] = 'hi there';
$tar = $phar->convertToData(Phar::TAR);
$b = $phar['a/b'];
try {
    $phar['a']->setMetadata('hi');
} catch (Exception $e) {
    echo $e->getMessage(), "\n";
}
try {
    $phar['a']->delMetadata();
} catch (Exception $e) {
    echo $e->getMessage(), "\n";
}
ini_set('phar.readonly', 1);
try {
    $b->setMetadata('hi');
} catch (Exception $e) {
    echo $e->getMessage(), "\n";
}
try {
    $b->delMetadata();
} catch (Exception $e) {
    echo $e->getMessage(), "\n";
}
ini_set('phar.readonly', 0);
$b->setMetadata(1, 2, 3);
<?php

$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar';
$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '2.tbz';
$pname = 'phar://' . $fname;
$stub = '<?php echo "first stub\\n"; __HALT_COMPILER(); ?>';
$file = $stub;
$files = array();
$files['a'] = 'a';
$files['b'] = 'b';
$files['c'] = 'c';
include 'files/phar_test.inc';
$phar = new Phar($fname);
$zip = $phar->convertToData(Phar::ZIP);
echo $zip->getPath() . "\n";
$tgz = $phar->convertToData(Phar::TAR, Phar::GZ);
echo $tgz->getPath() . "\n";
$tbz = $phar->convertToData(Phar::TAR, Phar::BZ2);
echo $tbz->getPath() . "\n";
try {
    $phar = $tbz->convertToExecutable(Phar::PHAR, Phar::NONE);
} catch (Exception $e) {
    echo $e->getMessage() . "\n";
}
copy($tbz->getPath(), $fname2);
$tbz = new PharData($fname2);
$phar = $tbz->convertToExecutable(Phar::PHAR, Phar::NONE);
echo $phar->getPath() . "\n";
$phar['a'] = 'hi';
$phar['a']->setMetadata('hi');
$zip = $phar->convertToExecutable(Phar::ZIP);
Ejemplo n.º 6
0
Phar::mungServer('hi');
Phar::createDefaultStub(array());
Phar::loadPhar(array());
Phar::canCompress('hi');
try {
    $a = new Phar(array());
} catch (TypeError $e) {
    print_exception($e);
}
try {
    $a = new Phar(dirname(__FILE__) . '/files/frontcontroller10.phar');
} catch (PharException $e) {
    print_exception($e);
}
$a->convertToExecutable(array());
$a->convertToData(array());
try {
    $b = new PharData(dirname(__FILE__) . '/whatever.tar');
} catch (PharException $e) {
    print_exception($e);
}
try {
    $c = new PharData(dirname(__FILE__) . '/whatever.zip');
} catch (PharException $e) {
    print_exception($e);
}
$b->delete(array());
try {
    $a->delete('oops');
} catch (Exception $e) {
    echo $e->getMessage() . "\n";
Ejemplo n.º 7
0
<?php

$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar';
$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.zip';
touch($fname2);
$phar = new Phar($fname, 0, 'a.phar');
$phar['x'] = 'hi';
try {
    $phar->convertToData(Phar::ZIP, Phar::NONE, 'zip');
} catch (BadMethodCallException $e) {
    echo $e->getMessage(), "\n";
}
?>
===DONE===
<?php 
unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar');
unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.zip');