Exemplo n.º 1
0
 protected function getMp3TestFile($method)
 {
     $tmpDir = getTmpDir();
     $pathname = $tmpDir->makeSubDir($tmpDir->prepareSubDirPath($method));
     $inFile = sprintf('%s/_files/EyeD3HelperTest/30-seconds.mp3', __DIR__);
     $outFile = sprintf('%s/30-seconds.mp3', $pathname);
     copy($inFile, $outFile);
     return $outFile;
 }
Exemplo n.º 2
0
 public function testClear()
 {
     $tmpDir = getTmpDir();
     $tmpDir->clear();
     $subDir = $tmpDir->prepareSubDirPath(__METHOD__);
     $pathname = $tmpDir->makeSubDir($subDir);
     $this->assertFileExists($pathname);
     $tmpDir->clear();
     $this->assertFalse(is_dir($pathname));
 }
 /**
  * @param string|string[] $srcFiles path or array of path of source file(s) relative to server root
  * @param array $options array of options
  * @param array $styleConfig full style configuration
  */
 public function __construct($srcFiles, array $options, array $styleConfig)
 {
     if (is_array($srcFiles)) {
         $this->_srcFiles = $srcFiles;
     } else {
         $this->_srcFiles = array($srcFiles);
     }
     $this->_options = $options;
     $this->_options['cache_dir'] = getTmpDir();
     $this->_options['cache_method'] = 'serialize';
     $this->_styleConfig = $styleConfig;
 }
Exemplo n.º 4
0
 public function testStandard()
 {
     $tmpDir = getTmpDir();
     $pathname = $tmpDir->makeSubDir($tmpDir->prepareSubDirPath(__CLASS__));
     $inFile = sprintf('%s/_files/LameHelperTest/30-seconds.wav', __DIR__);
     $outFile = sprintf('%s/30-seconds.mp3', $pathname);
     $lameHelper = new LameHelper();
     $lameRunner = new LameRunner(TESTS_KOMPAKT_AUDIOTOOLS_LAME);
     $lameHelper->setPreset(112);
     $lameRunner->execute($lameHelper->getCmd($inFile, $outFile));
     $this->assertFileExists($outFile);
 }
Exemplo n.º 5
0
 protected function getTmpDir($class)
 {
     $tmpDir = getTmpDir();
     return $tmpDir->replaceSubDir($tmpDir->prepareSubDirPath($class));
 }
Exemplo n.º 6
0
 protected function getTmpDir($method)
 {
     $tmpDir = getTmpDir();
     return $tmpDir->makeSubDir($tmpDir->prepareSubDirPath($method));
 }
Exemplo n.º 7
0
<?php

/*
 * This file is part of the kompakt/b3d package.
 *
 * (c) Christian Hoegl <*****@*****.**>
 *
 */
require sprintf('%s/bootstrap.php', dirname(__DIR__));
use GuzzleHttp\Client;
use Kompakt\B3d\Details\Endpoint\Resource\Stock\Endpoint as StockEndpoint;
use Kompakt\B3d\Details\Endpoint\Cache\PhpFile\Serializer as PhpFileSerializer;
use Kompakt\B3d\Util\File\Writer;
use Symfony\Component\Stopwatch\Stopwatch;
$tmpDir = getTmpDir();
$phpSerializerTmpDirPathname = $tmpDir->replaceSubDir('php-cache-stock-data');
// http client
$client = new Client();
// data file
$stockFilePathname = sprintf('%s/stocks.data', $phpSerializerTmpDirPathname);
// endpoint
$stockEndpoint = new StockEndpoint($client, EXAMPLE_KOMPAKT_B3D_BASE_URL, EXAMPLE_KOMPAKT_B3D_API_KEY);
// serializer
$stockPhpFileSerializer = new PhpFileSerializer(new Writer(), $stockFilePathname);
// run
$stopwatch = new Stopwatch();
$stopwatch->start('b3d', 'b3d');
$stockPhpFileSerializer->serialize($stockEndpoint->fetch(['uuid-1', 'uuid-2']));
$event = $stopwatch->stop('b3d');
echo sprintf("%s\n", $event);
Exemplo n.º 8
0
function unphar_toZip($tmpName, &$result, $name = "")
{
    $result = ["tmpDir" => null, "zipPath" => null, "zipRelativePath" => null, "basename" => null, "error" => false];
    rename($tmpName, "{$tmpName}.phar");
    $tmpName .= ".phar";
    try {
        $phar = new Phar($tmpName);
        $result["tmpDir"] = $tmpDir = getTmpDir();
        $pharPath = "phar://{$phar->getPath()}/";
        foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($pharPath)) as $f) {
            $subpath = substr($f, strlen($pharPath));
            @mkdir(dirname($realSubpath = $tmpDir . $subpath), 0777, true);
            copy($f, $realSubpath);
        }
        $zip = new ZipArchive();
        $dir = "/data/phars/";
        while (is_file($file = htdocs . ($rel = $dir . randomClass(16, "zip_" . $name . "_") . ".zip"))) {
        }
        $result["zipPath"] = $file;
        $result["zipRelativePath"] = $rel;
        $result["basename"] = substr($rel, 12);
        $err = $zip->open($file, ZipArchive::CREATE);
        if ($err !== true) {
            $msg = "Error creating zip file: ";
            switch ($err) {
                case ZipArchive::ER_EXISTS:
                    $msg .= "ER_EXISTS ({$err}) File already exists ({$file})";
                    break;
                case ZipArchive::ER_INCONS:
                    $msg .= "ER_INCONS ({$err}) Zip archive inconsistent.";
                    break;
                case ZipArchive::ER_INVAL:
                    $msg .= "ER_INVAL ({$err}) Invalid argument.";
                    break;
                case ZipArchive::ER_MEMORY:
                    $msg .= "ER_MEMORY ({$err}) Malloc failure.";
                    break;
                case ZipArchive::ER_NOENT:
                    $msg .= "ER_NOENT ({$err}) No such file.";
                    break;
                case ZipArchive::ER_NOZIP:
                    $msg .= "ER_NOZIP ({$err}) Not a zip archive.";
                    break;
                case ZipArchive::ER_OPEN:
                    $msg .= "ER_OPEN ({$err}) Can't open file.";
                    break;
                case ZipArchive::ER_READ:
                    $msg .= "ER_READ ({$err}) Read error.";
                    break;
                case ZipArchive::ER_SEEK:
                    $msg .= "ER_SEEK ({$err}) Seek error.";
            }
            throw new RuntimeException($msg . " Dump: " . var_export($result, true));
        }
        $tmpDir = realpath($tmpDir);
        foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($tmpDir)) as $file) {
            if (!is_file($file)) {
                continue;
            }
            $file = realpath($file);
            $rel = substr($file, strlen($tmpDir) + 1);
            $zip->addFile($file, str_replace("\\", "/", $rel));
        }
        $zip->setArchiveComment(json_encode($phar->getMetadata(), JSON_PRETTY_PRINT));
        $zip->close();
    } catch (Exception $e) {
        echo "<pre>";
        echo get_class($e) . ": {$e->getMessage()}";
        echo "\r\n\tat {$e->getFile()}:{$e->getLine()}</pre>";
        $result["error"] = true;
    }
}