public static function prepareSharedFolders(array $paths = array()) { if (empty($paths)) { return false; } $fs = new \Symfony\Component\Filesystem\Filesystem(); $releaseRoot = dirname(dirname(dirname(dirname(__FILE__)))) . '/'; // Current version root $root = dirname(dirname($releaseRoot)); $sharedDirectory = $root . '/shared/'; // Create the shared directory first (if it does not exists) if (!$fs->exists($sharedDirectory)) { $fs->mkdir($sharedDirectory, 0777); } foreach ($paths as $path) { $pathDirectory = $releaseRoot . $path; $sharedPathDirectory = $sharedDirectory . $path; if (!$fs->exists($sharedPathDirectory)) { $fs->mkdir($sharedPathDirectory, 0777); } $pathDirectoryTmp = $pathDirectory . '_tmp'; // Symlink it per hand exec("ln -f -s {$sharedPathDirectory} {$pathDirectoryTmp}"); exec("rm -rf {$pathDirectory}"); exec("mv -Tf {$pathDirectoryTmp} {$pathDirectory}"); //$fs->symlink($pathDirectory, $sharedPathDirectory, true); } }
public function setUp() { $this->numberOfPayloads = 5; $this->realDirectory = sys_get_temp_dir() . '/storage'; $this->chunkDirectory = $this->realDirectory . '/' . $this->chunksKey; $this->tempDirectory = $this->realDirectory . '/' . $this->orphanageKey; $this->payloads = array(); if (!$this->checkIfTempnameMatchesAfterCreation()) { $this->markTestSkipped('Temporary directories do not match'); } $filesystem = new \Symfony\Component\Filesystem\Filesystem(); $filesystem->mkdir($this->realDirectory); $filesystem->mkdir($this->chunkDirectory); $filesystem->mkdir($this->tempDirectory); $adapter = new Adapter($this->realDirectory, true); $filesystem = new GaufretteFilesystem($adapter); $this->storage = new GaufretteStorage($filesystem, 100000); $chunkStorage = new GaufretteChunkStorage($filesystem, 100000, null, 'chunks'); // create orphanage $session = new Session(new MockArraySessionStorage()); $session->start(); $config = array('directory' => 'orphanage'); $this->orphanage = new GaufretteOrphanageStorage($this->storage, $session, $chunkStorage, $config, 'cat'); for ($i = 0; $i < $this->numberOfPayloads; $i++) { // create temporary file as if it was reassembled by the chunk manager $file = tempnam($this->chunkDirectory, 'uploader'); $pointer = fopen($file, 'w+'); fwrite($pointer, str_repeat('A', 1024), 1024); fclose($pointer); //gaufrette needs the key relative to it's root $fileKey = str_replace($this->realDirectory, '', $file); $this->payloads[] = new GaufretteFile(new File($fileKey, $filesystem), $filesystem); } }
public function setUp() { $this->tmpdir = sys_get_temp_dir() . '/' . uniqid('conveyor'); $fs = new \Symfony\Component\Filesystem\Filesystem(); $fs->mkdir($this->tmpdir); chdir($this->tmpdir); }
protected function moveFile($original, $destination) { $fs = new \Symfony\Component\Filesystem\Filesystem(); $fileDir = dirname($destination); if (!$fs->exists($fileDir)) { $fs->mkdir($fileDir); } $fs->rename($original, $destination, true); }
/** * @covers \Foote\Ginny\Package\Foote\Generator\LaravelGenerator::map * @covers \Foote\Ginny\Package\Foote\Generator\LaravelGenerator::extendTwig * @covers \Foote\Ginny\Package\Foote\Generator\LaravelGenerator::genSchema * @covers \Foote\Ginny\Package\Foote\Generator\LaravelGenerator::genFixtures * @covers \Foote\Ginny\Package\Foote\Generator\LaravelGenerator::genFolders * @covers \Foote\Ginny\Package\Foote\Generator\LaravelGenerator::genModels * @covers \Foote\Ginny\Package\Foote\Generator\LaravelGenerator::genControllers * @covers \Foote\Ginny\Package\Foote\Generator\LaravelGenerator::genViews * @covers \Foote\Ginny\Package\Foote\Generator\LaravelGenerator::genTests */ public function testVarious() { $input = $this->getInput(); //create target path $filesystem = new \Symfony\Component\Filesystem\Filesystem(); $filesystem->remove($input->getFullTargetPath()); $filesystem->mkdir($input->getFullTargetPath()); // $this->assertCount(2, scandir($input->getFullTargetPath())); # init generator $generator = new LaravelGenerator($input, new ConsoleOutput(ConsoleOutput::VERBOSITY_QUIET)); $this->assertTrue($generator->twig->hasExtension('ui_extension')); $this->assertNotEmpty($generator->map->bundles); $generator->bundle = $generator->map->bundles->first(); # generate folder structure $generator->genFolders(); $this->assertTrue($filesystem->exists($input->getFullTargetPath() . 'System/Controller/Admin')); $this->assertTrue($filesystem->exists($input->getFullTargetPath() . 'System/database/migrations')); $this->assertTrue($filesystem->exists($input->getFullTargetPath() . 'System/database/seeders')); $this->assertTrue($filesystem->exists($input->getFullTargetPath() . 'System/Model')); $this->assertTrue($filesystem->exists($input->getFullTargetPath() . 'System/View/Admin/User')); # generate schema $this->assertCount(2, scandir($input->getFullTargetPath() . 'System/database/migrations/')); $generator->genSchema(); $this->assertGreaterThan(2, count(scandir($input->getFullTargetPath() . 'System/database/migrations/'))); # generate fixtures $this->assertCount(2, scandir($input->getFullTargetPath() . 'System/database/seeders')); $generator->genFixtures(); $this->assertTrue($filesystem->exists($input->getFullTargetPath() . 'System/database/seeders/SystemUserSeeder.php')); # generate models $this->assertCount(2, scandir($input->getFullTargetPath() . 'System/Model')); $generator->genModels(); $this->assertTrue($filesystem->exists($input->getFullTargetPath() . 'System/Model/User.php')); $this->assertTrue($filesystem->exists($input->getFullTargetPath() . 'System/Model/UserRole.php')); # generate controllers $this->assertCount(2, scandir($input->getFullTargetPath() . 'System/Controller/Admin')); $generator->genControllers(); $this->assertTrue($filesystem->exists($input->getFullTargetPath() . 'System/Controller/Admin/UsersController.php')); # generate views $this->assertCount(2, scandir($input->getFullTargetPath() . 'System/View/Admin/User')); $generator->genViews(); $this->assertTrue($filesystem->exists($input->getFullTargetPath() . 'System/View/Admin/User/show.blade.php')); $this->assertTrue($filesystem->exists($input->getFullTargetPath() . 'System/View/Admin/User/create.blade.php')); $this->assertTrue($filesystem->exists($input->getFullTargetPath() . 'System/View/Admin/User/edit.blade.php')); $this->assertTrue($filesystem->exists($input->getFullTargetPath() . 'System/View/Admin/User/index.blade.php')); # generate tests $this->assertCount(2, scandir($input->getFullTargetPath() . 'System/Tests/Model')); $generator->genTests(); $this->assertTrue($filesystem->exists($input->getFullTargetPath() . 'System/Tests/Controller/Admin/UsersControllerTest.php')); $this->assertTrue($filesystem->exists($input->getFullTargetPath() . 'System/Tests/Model/UserTest.php')); $filesystem->remove($input->getFullTargetPath()); $filesystem->mkdir($input->getFullTargetPath()); }
/** * @covers Alchemy\Zippy\Resource\ResourceManager::handle */ public function testFunctionnal() { $wd = __DIR__; $tmpdir = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR); $filesystem = new \Symfony\Component\Filesystem\Filesystem(); $filesystem->mkdir($tmpdir . '/path/to/local/'); $filesystem->mkdir($tmpdir . '/to/'); $filesystem->mkdir($tmpdir . '/path/to/a'); touch($tmpdir . '/path/to/local/file.ext'); touch($tmpdir . '/path/to/local/file2.ext'); touch($tmpdir . '/to/file3.ext'); $request = array($wd . '/input/path/to/local/file.ext', $wd . '/input/path/to/a/../local/file2.ext', $tmpdir . '/path/to/local/file.ext', $tmpdir . '/path/to/a/../local/file2.ext', 'http://www.google.com/+/business/images/plus-badge.png', 'http://www.google.com/+/business/images/plusone-button.png', 'file://' . $tmpdir . '/to/file3.ext', 'file://' . $wd . '/input/path/to/a/../local/file3.ext', '/I/want/this/file/to/go/there' => 'file://' . $wd . '/input/path/to/local/file2.ext', '/I/want/this/file/to/go/here' => 'file://' . $wd . '/input/path/to/local/file3.ext'); $expected = array('input/path/to/local/file.ext', 'input/path/to/local/file2.ext', 'file.ext', 'file2.ext', 'plus-badge.png', 'plusone-button.png', 'file3.ext', 'input/path/to/local/file3.ext', 'I/want/this/file/to/go/there', 'I/want/this/file/to/go/here'); $expectedSource = array($request[0], $request[1], $request[2], $request[3], $request[4], $request[5], $request[6], $request[7], $request['/I/want/this/file/to/go/there'], $request['/I/want/this/file/to/go/here']); $resourceManger = ResourceManager::create(); $collection = $resourceManger->handle($wd, $request); $this->assertCount(10, $collection); $n = 0; foreach ($collection as $resource) { $this->assertEquals($expected[$n], $resource->getTarget()); $this->assertEquals($expectedSource[$n], $resource->getOriginal()); $n++; } }
protected function getRootImageDir() { if (is_null($this->rootImageDir)) { $this->rootImageDir = $this->getParameter('kernel.root_dir') . '/../web/' . $this->getImageDir(); $fs = new \Symfony\Component\Filesystem\Filesystem(); if (!$fs->exists($this->rootImageDir)) { $fs->mkdir($this->rootImageDir); } } return $this->rootImageDir; }
* @param \Symfony\Component\Console\Output\ConsoleOutput $output * * @return boolean */ function execute_commands($commands, $output) { foreach ($commands as $command) { $output->writeln(sprintf('<info>Executing : </info> %s', $command)); $p = new \Symfony\Component\Process\Process($command); $p->setTimeout(null); $p->run(function ($type, $data) use($output) { $output->write($data); }); if (!$p->isSuccessful()) { return false; } $output->writeln(""); } return true; } $output->writeln("<info>Resetting demo</info>"); $fs->remove(sprintf('%s/web/uploads/media', $rootDir)); $fs->mkdir(sprintf('%s/web/uploads/media', $rootDir)); $fs->copy(__DIR__ . '/src/Sonata/Bundle/DemoBundle/DataFixtures/data/robots.txt', __DIR__ . '/web/app/robots.txt', true); $success = execute_commands(array('rm -rf app/cache/*', './sonata api cache:warmup --env=prod --no-debug', './sonata app cache:warmup --env=prod --no-debug', './sonata app cache:create-cache-class --env=prod --no-debug', './sonata app doctrine:database:drop --force', './sonata app doctrine:database:create', './sonata app doctrine:schema:update --force', './sonata app doctrine:fixtures:load --verbose --env=dev', './sonata app sonata:page:update-core-routes --site=all --no-debug', './sonata app sonata:page:create-snapshots --site=all --no-debug', './sonata app assets:install --symlink web', './sonata app sonata:admin:setup-acl', 'php -d memory_limit=1024M ./sonata app sonata:admin:generate-object-acl'), $output); if (!$success) { $output->writeln('<info>An error occurs when running a command!</info>'); exit(1); } $output->writeln('<info>Done!</info>'); exit(0);
private function dumpLocal() { $filesystem = new \Symfony\Component\Filesystem\Filesystem(); /** * * * * * Stop RIAK and do backup * * * * */ if ($this->switchLocal(0) == false) { return false; } $filesystem->mkdir($this->backupPath . $this->backupFilename); $this->backupFilename = rtrim($this->backupFilename, "/") . "/"; /** * Copy bitcask files */ if (is_dir($this->bitcaskPath)) { $bcPath = explode("/", rtrim($this->bitcaskPath, "/")); $bcDir = end($bcPath); $bcDir = rtrim($bcDir, "/") . "/"; $filesystem->mkdir($this->backupPath . $this->backupFilename . $bcDir); $copyAllBitcaskCommand = 'cp -Ra ' . $this->bitcaskPath . '. ' . $this->backupPath . $this->backupFilename . $bcDir; $copyAllBitcask = new Process($copyAllBitcaskCommand); $copyAllBitcask->run(); } /** * Copy leveldb files */ if (is_dir($this->levelDbPath)) { $ldbPath = explode("/", rtrim($this->levelDbPath, "/")); $ldbDir = end($ldbPath); $ldbDir = rtrim($ldbDir, "/") . "/"; $filesystem->mkdir($this->backupPath . $this->backupFilename . $ldbDir); $copyAllLeveldbCommand = 'cp -Ra ' . $this->levelDbPath . '. ' . $this->backupPath . $this->backupFilename . $ldbDir; $copyAllLeveldb = new Process($copyAllLeveldbCommand); $copyAllLeveldb->run(); } /** * Copy Backup Strong consistency */ if (is_dir($this->strongConsistencyPath)) { $sConPath = explode("/", rtrim($this->strongConsistencyPath, "/")); $sConDir = end($sConPath); $sConDir = rtrim($sConDir, "/") . "/"; $filesystem->mkdir($this->backupPath . $this->backupFilename . $sConDir); $copyAllSConCommand = 'cp -Ra ' . $this->strongConsistencyPath . '. ' . $this->backupPath . $this->backupFilename . $sConDir; $copyAllSCon = new Process($copyAllSConCommand); $copyAllSCon->run(); } /** * * * Start RIAK again * * * */ $this->switchLocal(1); return true; }
/** * Creates a directory * * @param string $dir * @param int $mode */ public static function mkdir($dir, $mode = 0750) { $fs = new \Symfony\Component\Filesystem\Filesystem(); $fs->mkdir($dir, $mode); }
* * Licensed under the MIT license: * http://www.opensource.org/licenses/MIT */ error_reporting(E_ALL | E_STRICT); if (strpos(__DIR__, DIRECTORY_SEPARATOR . 'bolt-public' . DIRECTORY_SEPARATOR) !== false) { // installed bolt with composer require_once __DIR__ . '/../../../../vendor/bolt/bolt/app/bootstrap.php'; } else { require_once __DIR__ . '/../../bootstrap.php'; } // Make sure the session is started. if (session_id() == "") { session_start(); } // Don't do anything if we're not logged in.. if (!isset($_SESSION['_sf2_attributes']['user']['id'])) { echo "Not logged in."; die; } $fileSystem = new Symfony\Component\Filesystem\Filesystem(); // Make sure the folder exists. $fileSystem->mkdir(__DIR__ . '/../../../files/' . date('Y-m')); require 'upload.class.php'; // Default accepted filetypes are: gif|jpe?g|png|zip|tgz|txt|md|docx?|pdf|xlsx?|pptx?|mp3|ogg|wav|m4a|mp4|m4v|ogv|wmv|avi|webm if (is_array($app['config']->get('general/accept_file_types'))) { $accepted_ext = implode('|', $app['config']->get('general/accept_file_types')); } else { $accepted_ext = $app['config']->get('general/accept_file_types'); } $upload_handler = new UploadHandler(array('upload_dir' => dirname(dirname(dirname(dirname($_SERVER['SCRIPT_FILENAME'])))) . '/files/' . date('Y-m') . "/", 'upload_url' => '/files/' . date('Y-m') . "/", 'accept_file_types' => '/\\.(' . $accepted_ext . ')$/i'));
private function _clearSystemCache() { if (!class_exists('\\Symfony\\Component\\Filesystem\\Filesystem', false)) { require TUBEPRESS_ROOT . '/vendor/symfony/filesystem/Filesystem.php'; require TUBEPRESS_ROOT . '/vendor/symfony/filesystem/Exception/ExceptionInterface.php'; require TUBEPRESS_ROOT . '/vendor/symfony/filesystem/Exception/IOExceptionInterface.php'; require TUBEPRESS_ROOT . '/vendor/symfony/filesystem/Exception/IOException.php'; require TUBEPRESS_ROOT . '/vendor/symfony/filesystem/Exception/FileNotFoundException.php'; } $dir = $this->_bootSettings->getPathToSystemCacheDirectory(); $filesystem = new \Symfony\Component\Filesystem\Filesystem(); if ($this->_bootLogger->isEnabled()) { $this->_logDebug(sprintf('System cache clear requested. Attempting to recursively delete <code>%s</code>', $dir)); } $filesystem->remove($dir); $filesystem->mkdir($dir, 0755); }
private function createDirectory($directory) { $filesystem = new \Symfony\Component\Filesystem\Filesystem(); if (!$filesystem->exists($directory)) { $filesystem->mkdir($directory); } }
public function testSortByTime() { $fs = new \Symfony\Component\Filesystem\Filesystem(); $fs->mkdir(__DIR__ . '/temp/'); $fs->touch(__DIR__ . '/temp/bar.css', 1371227908); $fs->touch(__DIR__ . '/temp/foo.css', 1339690408); $filesystem = new Filesystem(new Local(__DIR__ . '/temp')); $finder = new Finder($filesystem); $this->assertSame($finder, $finder->sortByTime()); $this->assertOrderedIterator(['foo.css', 'bar.css'], $finder->in('/')->getIterator()); }
/** * Local datababe(s) backup */ private function dumpLocal() { //do some research on local to find location of databases $couchDbConfigCommand = 'couch-config --db-dir'; $couchDbConfig = new Process($couchDbConfigCommand); $couchDbConfig->run(); //we couldn't find path, just return error if (!$couchDbConfig->isSuccessful()) { $this->result['status'] = 0; $this->result['message'] = $couchDbConfig->getErrorOutput(); return $this->result; } //set database local directory $this->databaseDir = trim($couchDbConfig->getOutput()); $this->databaseDir = rtrim($this->databaseDir, "/") . "/"; $filesystem = new \Symfony\Component\Filesystem\Filesystem(); //backup single database if ($this->database != '') { //check if database exists with extra check if extension wasnt set //in other case return error if everything fails if (!$filesystem->exists($this->databaseDir . $this->database)) { if (!$filesystem->exists($this->databaseDir . $this->database . ".couch")) { $this->result['status'] = 0; $this->result['message'] = "Defined Couchdb does not exist!"; return $this->result; } else { $this->database = $this->database . ".couch"; } } //copy our database to top backup path $filesystem->copy($this->databaseDir . $this->database, $this->backupPath . $this->backupFilename); } else { $filesystem->mkdir($this->backupPath . $this->backupFilename); $copyAllDatabasesCommand = 'cp -Ra ' . $this->databaseDir . '. ' . $this->backupPath . $this->backupFilename; $copyAllDatabases = new Process($copyAllDatabasesCommand); $copyAllDatabases->run(); //if backup fails return error with some extra info if (!$copyAllDatabases->isSuccessful()) { $this->result['status'] = 0; $this->result['message'] = $copyAllDatabases->getErrorOutput(); return false; } } return true; }
/** * Saves a copy of the created thumbnail with a 'nice' filename, like /thumbs/320x240/sample.jpg. * This makes it possible for subsequent requests to the same image, to circumvent the PHP layer altogether. * * @param $filename */ protected function boltSaveCopy($filename) { global $config; if ($config['general']['thumbnails']['save_files'] != true) { return; } $fileSystem = new Symfony\Component\Filesystem\Filesystem(); // Make sure the paths exists. Try to create it, if possible. $pathparts = explode("/", $_GET['requestname']); $path = BOLT_PROJECT_ROOT_DIR . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, array_slice($pathparts, 0, count($pathparts) - 1)); $fileSystem->mkdir($path); // Copy the file, and chmod $newfilename = dirname(dirname(__DIR__)) . "/" . urldecode($_GET['requestname']); copy($filename, $newfilename); @chmod($newfilename, octdec('0666')); }