public function dir_name() { $path = ini_get("xhprof.output_dir"); $path = empty($path) ? sys_get_temp_dir() : $path; return $path; // return DATA_DIR."/xhprof/"; }
public function __construct($namespace = '', $defaultLifetime = 0, $directory = null) { parent::__construct('', $defaultLifetime); if (!isset($directory[0])) { $directory = sys_get_temp_dir() . '/symfony-cache'; } if (isset($namespace[0])) { if (preg_match('#[^-+_.A-Za-z0-9]#', $namespace, $match)) { throw new InvalidArgumentException(sprintf('FilesystemAdapter namespace contains "%s" but only characters in [-+_.A-Za-z0-9] are allowed.', $match[0])); } $directory .= '/' . $namespace; } if (!file_exists($dir = $directory . '/.')) { @mkdir($directory, 0777, true); } if (false === ($dir = realpath($dir))) { throw new InvalidArgumentException(sprintf('Cache directory does not exist (%s)', $directory)); } if (!is_writable($dir .= DIRECTORY_SEPARATOR)) { throw new InvalidArgumentException(sprintf('Cache directory is not writable (%s)', $directory)); } // On Windows the whole path is limited to 258 chars if ('\\' === DIRECTORY_SEPARATOR && strlen($dir) > 234) { throw new InvalidArgumentException(sprintf('Cache directory too long (%s)', $directory)); } $this->directory = $dir; }
public function testFromNonDirectoryWithNonExistingPath() { $directory = uniqid(sys_get_temp_dir() . 'non-existing', true); $exception = InvalidDirectory::fromNonDirectory($directory); self::assertInstanceOf(InvalidDirectory::class, $exception); self::assertSame(sprintf('"%s" does not exists', $directory), $exception->getMessage()); }
/** * @dataProvider getFormat * @runInSeparateProcess */ public function testExecution($format) { $tmpDir = sys_get_temp_dir() . '/sf_hello'; $filesystem = new Filesystem(); $filesystem->remove($tmpDir); $filesystem->mkdirs($tmpDir); chdir($tmpDir); $tester = new CommandTester(new InitCommand()); $tester->execute(array('--name' => 'Hello' . $format, '--app-path' => 'hello' . $format, '--web-path' => 'web', '--src-path' => 'src', '--format' => $format)); // autoload $content = file_get_contents($file = $tmpDir . '/src/autoload.php'); $content = str_replace("__DIR__.'/vendor", "'" . __DIR__ . "/../../../../src/vendor", $content); file_put_contents($file, $content); // Kernel $class = 'Hello' . $format . 'Kernel'; $file = $tmpDir . '/hello' . $format . '/' . $class . '.php'; $this->assertTrue(file_exists($file)); $content = file_get_contents($file); $content = str_replace("__DIR__.'/../src/vendor/Symfony/src/Symfony/Bundle'", "'" . __DIR__ . "/../../../../src/vendor/Symfony/src/Symfony/Bundle'", $content); file_put_contents($file, $content); require_once $file; $kernel = new $class('dev', true); $response = $kernel->handle(Request::create('/')); $this->assertRegExp('/successfully/', $response->getContent()); $filesystem->remove($tmpDir); }
public static function processemail($emailsrc, $pdfout, $coverfile = '') { $combfilelist = array(); # Process the email $emailparts = Mail_mimeDecode::decode(array('include_bodies' => true, 'decode_bodies' => true, 'decode_headers' => true, 'input' => file_get_contents($emailsrc), 'crlf' => "\r\n")); # Process the cover if it exists if ($coverfile !== '') { $combfilelist[] = self::processpart(file_get_contents($coverfile), mime_content_type($coverfile)); } # Process the parts $combfilelist = array_merge($combfilelist, self::processparts($emailparts)); # Create an intermediate file to build the pdf $tmppdffilename = sys_get_temp_dir() . '/e2p-' . (string) abs((int) (microtime(true) * 100000)) . '.pdf'; # Build the command to combine all of the intermediate files into one $conbcom = str_replace(array_merge(array('INTFILE', 'COMBLIST'), array_keys(self::$driver_paths)), array_merge(array($tmppdffilename, implode(' ', $combfilelist)), array_values(self::$driver_paths)), self::$mime_drivers['gs']); exec($conbcom); # Remove the intermediate files foreach ($combfilelist as $combfilename) { unlink($combfilename); } # Write the intermediate file to the final destination $intfileres = fopen($tmppdffilename, 'rb'); $outfileres = fopen($pdfout, 'ab'); while (!feof($intfileres)) { fwrite($outfileres, fread($intfileres, 8192)); } fclose($intfileres); fclose($outfileres); # Remove the intermediate file unlink($tmppdffilename); }
public function testSetPath() { $exporter = $this->getMockForAbstractClass(AbstractExporter::class); $path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . sha1(time()) . DIRECTORY_SEPARATOR; $exporter->setPath($path); $this->assertEquals($path, $exporter->getPath()); }
public function setUp() { $this->numberOfPayloads = 5; $this->tempDirectory = sys_get_temp_dir() . '/orphanage'; $this->realDirectory = sys_get_temp_dir() . '/storage'; $this->payloads = array(); $filesystem = new Filesystem(); $filesystem->mkdir($this->tempDirectory); $filesystem->mkdir($this->realDirectory); for ($i = 0; $i < $this->numberOfPayloads; $i++) { // create temporary file $file = tempnam(sys_get_temp_dir(), 'uploader'); $pointer = fopen($file, 'w+'); fwrite($pointer, str_repeat('A', 1024), 1024); fclose($pointer); $this->payloads[] = new FilesystemFile(new UploadedFile($file, $i . 'grumpycat.jpeg', null, null, null, true)); } // create underlying storage $this->storage = new FilesystemStorage($this->realDirectory); // is ignored anyways $chunkStorage = new FilesystemChunkStorage('/tmp/'); // create orphanage $session = new Session(new MockArraySessionStorage()); $session->start(); $config = array('directory' => $this->tempDirectory); $this->orphanage = new FilesystemOrphanageStorage($this->storage, $session, $chunkStorage, $config, 'cat'); }
public function setUp() { $this->tmpdir = sys_get_temp_dir() . '/' . uniqid('conveyor'); $this->projectdir = $this->tmpdir . '/project'; $this->reposdir = $this->tmpdir . '/repos'; $this->reposurl = 'file:///' . $this->reposdir; $this->filesystem = new Filesystem(); $this->filesystem->mkdir($this->tmpdir); $this->filesystem->mkdir($this->projectdir); $svnadminbin = getenv('SVNADMIN_BIN') ? getenv('SVNADMIN_BIN') : '/usr/local/bin/svnadmin'; $svnbin = getenv('SVN_BIN') ? getenv('SVN_BIN') : '/usr/local/bin/svn'; if (!file_exists($svnadminbin)) { $this->markTestSkipped(sprintf('%s not found', $svnadminbin)); } if (!file_exists($svnbin)) { $this->markTestSkipped(sprintf('%s not found', $svnbin)); } $svnadmin = new Svnadmin($this->tmpdir, $svnadminbin); $svnadmin->create(basename($this->reposdir)); $svn = new Svn($this->reposurl, new CliAdapter($svnbin, new Cli(), new CliParser())); $svn->import(__DIR__ . '/../Test/Fixtures/skeleton/svn/trunk', '/', 'imported skeleton'); $svn->setHead(new Reference('2.1', Reference::TAG)); $svn->import(__DIR__ . '/../Test/Fixtures/skeleton/svn/tags/2.1', '/', 'imported skeleton'); $svn->setHead(new Reference('feature1', Reference::BRANCH)); $svn->import(__DIR__ . '/../Test/Fixtures/skeleton/svn/branches/feature1', '/', 'imported skeleton'); $content = file_get_contents(__DIR__ . '/../Test/Fixtures/conveyor.yml.twig'); $content = str_replace('{{ repository.url }}', $this->reposurl, $content); file_put_contents($this->projectdir . '/conveyor.yml', $content); chdir($this->projectdir); }
public function assembleBook() { // implode all the contents to create the whole book $book = $this->app->render('book.twig', array('items' => $this->app['publishing.items'])); $temp = tempnam(sys_get_temp_dir(), 'easybook_'); fputs(fopen($temp, 'w+'), $book); // use PrinceXML to transform the HTML book into a PDF book $prince = $this->app->get('prince'); $prince->setBaseURL($this->app['publishing.dir.contents'] . '/images'); // Prepare and add stylesheets before PDF conversion if ($this->app->edition('include_styles')) { $defaultStyles = tempnam(sys_get_temp_dir(), 'easybook_style_'); $this->app->renderThemeTemplate('style.css.twig', array('resources_dir' => $this->app['app.dir.resources'] . '/'), $defaultStyles); $prince->addStyleSheet($defaultStyles); } // TODO: custom book styles could also be defined with Twig $customCss = $this->app->getCustomTemplate('style.css'); if (file_exists($customCss)) { $prince->addStyleSheet($customCss); } // TODO: the name of the book file (book.pdf) must be configurable $errorMessages = array(); $prince->convert_file_to_file($temp, $this->app['publishing.dir.output'] . '/book.pdf', $errorMessages); // show PDF conversion errors if (count($errorMessages) > 0) { foreach ($errorMessages as $message) { echo $message[0] . ': ' . $message[2] . ' (' . $message[1] . ')' . "\n"; } } }
public function setUp() { parent::setUp(); $this->originalFile = __DIR__ . '/files/testimage.gif'; $this->compressedFile = $temp_file = sys_get_temp_dir() . '/php_image_optimizer.gif'; copy($this->originalFile, $this->compressedFile); }
private static function getZippedFile($filename) { if(!self::zipModuleLoaded()) { throw new WURFL_WURFLException("The Zip extension is not loaded. Load the extension or use the flat wurfl.xml file"); } $tmpDir = sys_get_temp_dir(); $zip = new ZipArchive(); if ($zip->open($filename)!==TRUE) { exit("cannot open <$filename>\n"); } $zippedFile = $zip->statIndex(0); $wurflFile = $zippedFile['name']; //$wurflFile = md5(uniqid(rand(), true)); //$zip->extractTo($tmpDir, $wurflFile); $zip->extractTo($tmpDir); $zip->close(); return $tmpDir . '/' .$wurflFile; }
/** * @expectedException XML_XRD_Loader_Exception * @expectedExceptionMessage Cannot open file to determine type */ public function testDetectTypeFromFileCannotOpen() { $file = tempnam(sys_get_temp_dir(), 'xml_xrd-unittests'); $this->cleanupList[] = $file; chmod($file, '0000'); @$this->loader->detectTypeFromFile($file); }
protected function tempFilename() { $temp_dir = is_null($this->temp_dir) ? sys_get_temp_dir() : $this->temp_dir; $filename = tempnam($temp_dir, "xlsx_writer_"); $this->temp_files[] = $filename; return $filename; }
/** * NOTE: This function is incomplete, the fallback is to '/tmp' which targets Unix-like. * * @return string */ function php_sys_get_temp_dir() { // (PHP 5 >= 5.2.1) if (function_exists('sys_get_temp_dir')) { return sys_get_temp_dir(); } // (PHP 4 >= 4.3.0, PHP 5) if (function_exists('stream_get_meta_data')) { $handle = tmpfile(); // (PHP 4, PHP 5) $meta = stream_get_meta_data($handle); // (PHP 5 >= 5.1.0) if (isset($meta['uri'])) { return dirname($meta['uri']); } } // emulate PHP 4 <= 4.0.6 tempnam() behavior, fragile foreach (array('TMPDIR', 'TMP') as $key) { if (isset($_ENV[$key])) { return $_ENV[$key]; } } // fallback for Unix-like (php_shell specifically) return '/tmp'; }
public function generate() { $tempPath = sys_get_temp_dir() . '/'; // FastCGI fix for Windows machines, where temp path is not available to // PHP, and defaults to the unwritable system directory. If the temp // path is pointing to the system directory, shift to the 'TEMP' // sub-folder, which should also exist, but actually be writable. if (IS_WIN && $tempPath == getenv("SystemRoot") . '/') { $tempPath = getenv("SystemRoot") . '/TEMP/'; } $keyFile = $tempPath . md5(microtime(true)); if (!is_dir($tempPath)) { mkdir($tempPath); } $return = array(); if ($this->canGenerateKeys()) { shell_exec('ssh-keygen -q -t rsa -b 2048 -f ' . $keyFile . ' -N "" -C "deploy@phpci"'); $pub = file_get_contents($keyFile . '.pub'); $prv = file_get_contents($keyFile); if (empty($pub)) { $pub = ''; } if (empty($prv)) { $prv = ''; } $return = array('private_key' => $prv, 'public_key' => $pub); } return $return; }
/** * * @param resource $pipe * @param string $job * * @throws PHPUnit_Framework_Exception * * @since Method available since Release 3.5.12 */ protected function process($pipe, $job) { if (!($this->tempFile = tempnam(sys_get_temp_dir(), 'PHPUnit')) || file_put_contents($this->tempFile, $job) === false) { throw new PHPUnit_Framework_Exception('Unable to write temporary file'); } fwrite($pipe, '<?php require_once ' . var_export($this->tempFile, true) . '; ?>'); }
public function filterDump(AssetInterface $asset) { $pb = $this->createProcessBuilder(array($this->jpegtranBin)); if ($this->optimize) { $pb->add('-optimize'); } if ($this->copy) { $pb->add('-copy')->add($this->copy); } if ($this->progressive) { $pb->add('-progressive'); } if (null !== $this->restart) { $pb->add('-restart')->add($this->restart); } $pb->add($input = tempnam(sys_get_temp_dir(), 'assetic_jpegtran')); file_put_contents($input, $asset->getContent()); $proc = $pb->getProcess(); $code = $proc->run(); unlink($input); if (0 < $code) { throw FilterException::fromProcess($proc)->setInput($asset->getContent()); } $asset->setContent($proc->getOutput()); }
/** * @return BundleInterface|\PHPUnit_Framework_MockObject_MockObject */ private function createBundleMock() { $bundleMock = $this->getMock('Symfony\\Component\\HttpKernel\\Bundle\\BundleInterface'); $bundleMock->expects($this->any())->method('getNamespace')->will($this->returnValue('Sonata\\AdminBundle\\Tests\\Fixtures')); $bundleMock->expects($this->any())->method('getPath')->will($this->returnValue(sprintf('%s/%s', sys_get_temp_dir(), lcg_value()))); return $bundleMock; }
public static function start(){ //PHP self::$params["safe_mode"] = (int) ini_get("safe_mode"); self::$params["safe_mode_gid"] = (int) ini_get("safe_mode_gid"); self::$params["upload_max_size"] = ini_get("upload_max_filesize"); self::$params["post_max_size"] = ini_get("post_max_size"); self::$params["memory_limit"] = ((ini_get("memory_limit")!="")?ini_get("memory_limit"):get_cfg_var("memory_limit")); self::$params["max_execution_time"] = ini_get("max_execution_time"); $uploadTmpDir = ini_get("upload_tmp_dir"); $uploadTmpDir = $uploadTmpDir ? $uploadTmpDir : realpath(sys_get_temp_dir()); self::$params["upload_tmp_dir"] = $uploadTmpDir; self::$params["upload_tmp_dir_writable"] = @is_writable($uploadTmpDir); self::$params["output_buffering"] = (int) !! ini_get('output_buffering'); //ZLIB self::$params["zlib"] = (int) function_exists('gzopen'); //For future or commercial versions self::$params["xml_parser_create"] = (int) function_exists("xml_parser_create"); //GD self::$params['gd'] = (int) (function_exists("gd_info") && function_exists("imagecopyresized") && function_exists("imagecopyresampled")) ; self::liveTests(); }
public function testRouteSetupInstallerInstall() { $emMock = $this->createEntityManagerMock(); $this->app['repo.sessions'] = $this->createEntityRepositoryMock(); $this->app['EM'] = $emMock; $this->app['phraseanet.configuration-tester']->expects($this->once())->method('isBlank')->will($this->returnValue(true)); $this->app['phraseanet.installer'] = $this->getMockBuilder('Alchemy\\Phrasea\\Setup\\Installer')->disableOriginalConstructor()->getMock(); $user = $this->createUserMock(); $this->app['phraseanet.installer']->expects($this->once())->method('install')->will($this->returnValue($user)); $authenticator = $this->getMockBuilder('Alchemy\\Phrasea\\Authentication\\Authenticator')->disableOriginalConstructor()->getMock(); $session = $this->getMock('Entities\\Session'); $authenticator->expects($this->once())->method('openAccount')->with($this->equalTo($user))->will($this->returnValue($session)); $this->app['authentication'] = $authenticator; $client = $this->createClient(); $settings = Yaml::parse(file_get_contents(__DIR__ . '/../../../../../resources/hudson/InstallDBs.yml')); $settings = $settings['database']; $host = isset($settings['host']) ? $settings['host'] : 'localhost'; $port = isset($settings['port']) ? $settings['port'] : '3306'; $user = isset($settings['user']) ? $settings['user'] : '******'; $password = isset($settings['password']) ? $settings['password'] : ''; $abName = isset($settings['ab_name']) ? $settings['ab_name'] : null; $dbName = isset($settings['db_name']) ? $settings['db_name'] : null; $params = array('email' => '*****@*****.**', 'password' => 'prètty%%password', 'binary_xpdf' => '/path/to/xpdf', 'binary_mplayer' => '/path/to/mplayer', 'binary_MP4Box' => '/path/to/MP4Box', 'binary_ffmpeg' => '/path/to/ffmpeg', 'binary_unoconv' => '/path/to/unoconv', 'binary_swfrender' => '/path/to/swfrender', 'binary_pdf2swf' => '/path/to/pdf2swf', 'binary_swfextract' => '/path/to/swfextract', 'binary_exiftool' => '/path/to/exiftool', 'binary_composite' => '/path/to/composite', 'binary_convert' => '/path/to/convert', 'binary_php' => '/path/to/php', 'datapath_noweb' => sys_get_temp_dir() . '/datainstall/noweb', 'hostname' => $host, 'port' => $port, 'user' => $user, 'db_password' => $password, 'ab_name' => $abName, 'db_name' => $dbName, 'db_template' => 'en', 'create_task' => array(), 'binary_phraseanet_indexer' => '/path/to/phraseanet_indexer'); $client->request('POST', '/setup/installer/install/', $params); $response = $client->getResponse(); $this->assertEquals(302, $response->getStatusCode()); $this->assertTrue(false === strpos($response->headers->get('location'), '/setup/installer/'), $response); }
public function filterLoad(AssetInterface $asset) { $sassProcessArgs = array(); if (null !== $this->nodePath) { $sassProcessArgs[] = $this->nodePath; } $sassProcessArgs[] = $this->sassPath; $pb = $this->createProcessBuilder($sassProcessArgs); if ($dir = $asset->getSourceDirectory()) { $pb->add('--include-path')->add($dir); } if ($this->style) { $pb->add('--output-style')->add($this->style); } if ($this->sourceMap) { $pb->add('--source-map'); } if ($this->debugInfo) { $pb->add('--source-comments'); } foreach ($this->loadPaths as $loadPath) { $pb->add('--include-path')->add($loadPath); } // input $pb->add($input = tempnam(sys_get_temp_dir(), 'assetic_sass')); file_put_contents($input, $asset->getContent()); $pb->add('--stdout'); $proc = $pb->getProcess(); $code = $proc->run(); unlink($input); if (0 !== $code) { throw FilterException::fromProcess($proc)->setInput($asset->getContent()); } $asset->setContent($proc->getOutput()); }
/** * @covers Alchemy\Phrasea\SearchEngine\SphinxSearch\SphinxSearchEngine */ public function bootTestCase() { $binaryFinder = new ExecutableFinder(); $indexer = $binaryFinder->find('indexer'); $searchd = $binaryFinder->find('searchd'); if (!$indexer || !$searchd) { self::$skipped = true; return; } $app = self::$DI['app']; $appbox = $app['phraseanet.appbox']; $app['conf']->set(['main', 'search-engine', 'options'], ['host' => '127.0.0.1', 'port' => 9312, 'rt_host' => '127.0.0.1', 'rt_port' => 9306]); self::$searchEngine = SphinxSearchEngine::create($app, $app['conf']->get(['main', 'search-engine', 'options'])); self::$config = tempnam(sys_get_temp_dir(), 'tmp_sphinx.conf'); $configuration = self::$searchEngine->getConfigurationPanel()->getConfiguration(); $configuration['date_fields'] = []; foreach ($appbox->get_databoxes() as $databox) { foreach ($databox->get_meta_structure() as $databox_field) { if ($databox_field->get_type() != \databox_field::TYPE_DATE) { continue; } $configuration['date_fields'][] = $databox_field->get_name(); } } $configuration['date_fields'] = array_unique($configuration['date_fields']); self::$searchEngine->getConfigurationPanel()->saveConfiguration($configuration); $configFile = self::$searchEngine->getConfigurationPanel()->generateSphinxConf($appbox->get_databoxes(), $configuration); file_put_contents(self::$config, $configFile); $process = new Process($indexer . ' --all -c ' . self::$config); $process->run(); self::$searchd = new Process($searchd . ' -c ' . self::$config); self::$searchd->run(); self::$searchEngine = SphinxSearchEngine::create($app, $app['conf']->get(['main', 'search-engine', 'options'])); self::$searchEngineClass = 'Alchemy\\Phrasea\\SearchEngine\\SphinxSearch\\SphinxSearchEngine'; }
public function setUp() { $tmpDir = sys_get_temp_dir() . '/zend_memory'; $this->_removeCacheDir($tmpDir); mkdir($tmpDir); $this->cacheDir = $tmpDir; }
public function setUp() { $this->workspace = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . time() . rand(0, 1000); mkdir($this->workspace, 0777, true); $this->workspace = realpath($this->workspace); $this->cache = new Cache($this->workspace); }
/** * Get the Platform object for this class * * @return Platform */ protected function getPlatform() { if (!$this->platform) { $this->platform = new MysqlPlatform(); $configFileContent = <<<EOF propel: database: connections: bookstore: adapter: mysql classname: \\Propel\\Runtime\\Connection\\DebugPDO dsn: mysql:host=127.0.0.1;dbname=test user: root password: adapters: mysql: tableType: InnoDB generator: defaultConnection: bookstore connections: - bookstore runtime: defaultConnection: bookstore connections: - bookstore EOF; $configFile = sys_get_temp_dir() . '/propel.yaml'; file_put_contents($configFile, $configFileContent); $config = new GeneratorConfig($configFile); $this->platform->setGeneratorConfig($config); } return $this->platform; }
public function testSources() { $params = array('action' => 'get_sources', 'session' => file_get_contents(sys_get_temp_dir() . '/session')); $out = shell_exec("php data_.php " . addslashes(json_encode($params))); $res = json_decode($out); $this->assertEquals(true, $res->success); }
protected function getBuilder($dir = null) { $dir = $dir ?: sys_get_temp_dir(); $logger = $this->getMock('Psr\\Log\\LoggerInterface'); $builder = $this->getMock('Yuhao\\Builder', null, [$logger, $dir]); return $builder; }
public static function setUpBeforeClass() { $reflect = new \ReflectionClass(__CLASS__); self::$directory = @tempnam(sys_get_temp_dir(), $reflect->getShortName() . '-'); @unlink(self::$directory); @mkdir(self::$directory); }
/** * @return CacheInterface */ public function getCache() { if (null === $this->cache) { $this->cache = new FilesystemCache($this->options['cache_dir'] ?: sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'php-github-api-cache'); } return $this->cache; }
public static function upload_large($file, $options = array()) { $src = fopen($file, 'r'); $temp_file_name = tempnam(sys_get_temp_dir(), 'cldupload.' + pathinfo($file, PATHINFO_EXTENSION)); $upload = $upload_id = NULL; $public_id = \Cloudinary::option_get($upload, "public_id"); $index = 1; while (!feof($src)) { $dest = fopen($temp_file_name, 'w'); stream_copy_to_stream($src, $dest, 20000000); fclose($dest); try { $upload = Uploader::upload_large_part($temp_file_name, array_merge($options, array("public_id" => $public_id, "upload_id" => $upload_id, "part_number" => $index, "final" => feof($src)))); } catch (\Exception $e) { unlink($temp_file_name); fclose($src); throw $e; } $upload_id = \Cloudinary::option_get($upload, "upload_id"); $public_id = \Cloudinary::option_get($upload, "public_id"); $index += 1; } unlink($temp_file_name); fclose($src); return $upload; }