public function render($view = null, $layout = null) { try { ob_start(); if (defined('DOMPDF_TEMP_DIR')) { $dir = new SplFileInfo(DOMPDF_TEMP_DIR); if (!$dir->isDir() || !$dir->isWritable()) { trigger_error(__('%s is not writable', DOMPDF_TEMP_DIR), E_USER_WARNING); } } $errors = ob_get_contents(); ob_end_clean(); $download = false; $name = pathinfo($this->here, PATHINFO_BASENAME); $paperOrientation = 'portrait'; $paperSize = 'letter'; extract($this->viewVars, EXTR_IF_EXISTS); $dompdf = new DOMPDF(); $dompdf->load_html($errors . parent::render($view, $layout), Configure::read('App.encoding')); $dompdf->set_protocol(''); $dompdf->set_protocol(WWW_ROOT); $dompdf->set_base_path('/'); $dompdf->set_paper($paperSize, $paperOrientation); $dompdf->render(); $dompdf->stream($name, array('Attachment' => $download)); } catch (Exception $e) { $this->request->params['ext'] = 'html'; throw $e; } }
/** * Upload (move to target dir) given file * @param string $filename * @param string $content * @return string path to filename */ public function upload($filename, $content) { if (false === $this->uploadDir->isDir()) { try { $this->fs->mkdir($this->uploadDir->getPathname()); } catch (\Exception $e) { throw new \RuntimeException('Upload directory is not writable, doesn\'t exist or no space left on the disk.'); } } if (false === $this->uploadDir->isWritable()) { throw new \RuntimeException('Upload directory is not writable, doesn\'t exist or no space left on the disk.'); } $this->fs->dumpFile($this->uploadDir->getRealPath() . '/' . $filename, $content); return $this->uploadDir->getRealPath() . '/' . $filename; }
/** * Constructs the file cache driver * * [!!] Note: This method cannot be invoked externally. * * The file cache driver must be instantiated using the `Cache::instance()` method. * * @param array $config Config for file cache driver * * @throws Cache_Exception */ protected function __construct(array $config) { // Setup parent parent::__construct($config); $directory = Arr::get($this->_config, 'cache_dir', Kohana::$cache_dir); try { $this->_cache_dir = new SplFileInfo($directory); } catch (ErrorException $e) { $this->_cache_dir = $this->_make_directory($directory, 0777, TRUE); } catch (UnexpectedValueException $e) { $this->_cache_dir = $this->_make_directory($directory, 0777, TRUE); } // If the defined directory is a file, get outta here if ($this->_cache_dir->isFile()) { throw new Cache_Exception('Unable to create cache directory as a file already exists : :resource', array(':resource' => $this->_cache_dir->getRealPath())); } // Check the read status of the directory if (!$this->_cache_dir->isReadable()) { throw new Cache_Exception('Unable to read from the cache directory :resource', array(':resource' => $this->_cache_dir->getRealPath())); } // Check the write status of the directory if (!$this->_cache_dir->isWritable()) { throw new Cache_Exception('Unable to write to the cache directory :resource', array(':resource' => $this->_cache_dir->getRealPath())); } }
protected function execute(InputInterface $input, OutputInterface $output) { $configHelper = $this->getHelper('configuration'); /* @var $configHelper GlobalConfigurationHelper */ $questionHelper = $this->getHelper('question'); /* @var $questionHelper QuestionHelper */ $sshConfig = new \SplFileInfo($configHelper->getConfiguration()->getSshDirectory() . '/config'); if (!$sshConfig->isFile()) { throw new NotAFileException($sshConfig); } if (!$sshConfig->isReadable()) { throw new UnreadableFileException($sshConfig); } if (!$sshConfig->isWritable()) { throw new UnwritableFileException($sshConfig); } $sshConfigLines = file($sshConfig->getPathname()); $repoName = $input->getArgument('repository'); $repositoryConfig = $configHelper->getConfiguration()->getRepositoryConfiguration($repoName); if (!$questionHelper->ask($input, $output, new ConfirmationQuestion(sprintf('Are you sure you want to remove the ssh key for "%s"? This action is irreversible.', $repoName)))) { return 1; } $sshKeyFile = $repositoryConfig->getIdentityFile(); $this->unlinkFile($output, $sshKeyFile); $this->unlinkFile($output, $sshKeyFile . '.pub'); if (Util::removeSshAliasLines($sshConfigLines, $repositoryConfig)) { $output->writeln(sprintf('Removed section <info>Host %s</info> from <info>%s</info>', $repositoryConfig->getSshAlias(), $sshConfig->getPathname()), OutputInterface::VERBOSITY_VERBOSE); } $output->writeln(sprintf('Removed repository <info>%s</info>', $repoName)); $configHelper->getConfiguration()->removeRepositoryConfiguration($repoName); FsUtil::file_put_contents($sshConfig->getPathname(), implode('', $sshConfigLines)); $configHelper->getConfiguration()->write(); return 0; }
/** * Upload an image to local server then return new image path after upload success * * @param array $file [tmp_name, name, error, type, size] * @param string image path for saving (this may constain filename) * @param string image filename for saving * @return string Image path after uploaded * @throws Exception If upload failed */ public function upload($file, $newImagePath = '.', $newImageName = NULL) { if (!empty($file['error'])) { $this->_throwException(':method: Upload error. Number: :number', array(':method' => __METHOD__, ':number' => $file['error'])); } if (getimagesize($file['tmp_name']) === FALSE) { $this->_throwException(':method: The file is not an image file.', array(':method' => __METHOD__)); } $fileInfo = new \SplFileInfo($newImagePath); if (!$fileInfo->getRealPath() or !$fileInfo->isDir()) { $this->_throwException(':method: The ":dir" must be a directory.', array(':method' => __METHOD__, ':dir' => $newImagePath)); } $defaultExtension = '.jpg'; if (empty($newImageName)) { if (!in_array($fileInfo->getBasename(), array('.', '..')) and $fileInfo->getExtension()) { $newImageName = $fileInfo->getBasename(); } else { $newImageName = uniqid() . $defaultExtension; } } if (!$fileInfo->isWritable()) { $this->_throwException(':method: Directory ":dir" is not writeable.', array(':method' => __METHOD__, ':dir' => $fileInfo->getRealPath())); } $destination = $fileInfo->getRealPath() . DIRECTORY_SEPARATOR . $newImageName; if (move_uploaded_file($file['tmp_name'], $destination)) { return $destination; } else { $this->_throwException(':method: Cannot move uploaded file to :path', array(':method' => __METHOD__, ':path' => $fileInfo->getRealPath())); } }
/** * Recursively create a directory if allowed. * * @param string $path The path to the directory which will be created. * @param int $permissions The Unix permissions to set on the directory. Ignored * on Windows machines. * * @return void * * @throws \LogicException if the directory already exists. * @throws \UnexpectedValueException if the first existing parent directory in * the $path argument is not readable or * writable by the user running PHP. * @throws \UnexpectedValueException when a recursive call to mkdir() with the * given $path and $permissions arguments * fails. */ function createDirectory($path, $permissions = 0755) { if (is_dir($path)) { throw new \LogicException('De map "' . $path . '" bestaat al.', 2); } // Find the first parent directory and check its permissions. $permission = false; $parentPath = $path; do { $parentPath = explode(DIRECTORY_SEPARATOR, trim($parentPath, DIRECTORY_SEPARATOR)); $parentPathCount = count($parentPath); unset($parentPath[--$parentPathCount]); $parentPath = implode(DIRECTORY_SEPARATOR, $parentPath); // Don't prepend the path with a directory separator on Windows. // The drive letter, for example: "C:\", is enough. if (PHP_OS !== 'Windows') { $parentPath = DIRECTORY_SEPARATOR . $parentPath; } if (file_exists($parentPath)) { $fileInfo = new \SplFileInfo($parentPath); if ($fileInfo->isReadable() && $fileInfo->isWritable()) { $permission = true; break; } } } while ($parentPathCount > 1); if ($permission) { if (!mkdir($path, $permissions, true)) { throw new \UnexpectedValueException('De map "' . $path . '" kon niet aangemaakt worden.', 8); } } else { throw new \UnexpectedValueException('De eerstvolgende bestaande map die boven "' . $path . '" ligt ' . 'is niet lees- of schrijfbaar.', 4); } }
public function __construct($filename, $dir) { $info = new \SplFileInfo($dir); if (!$info->isDir()) { throw new InvalidArgumentException(sprintf('Selection file parent dir not found')); } if (!$info->isReadable()) { throw new InvalidArgumentException(sprintf('Selection file parent dir not readable')); } if (!$info->isWritable()) { throw new InvalidArgumentException(sprintf('Selection file parent dir not writable')); } $this->file = sprintf('%s/%s', $dir, $filename); }
public function __construct($dir) { $info = new \SplFileInfo($dir); if (!$info->isDir()) { throw new InvalidArgumentException(sprintf('Dir not found')); } if (!$info->isReadable()) { throw new InvalidArgumentException(sprintf('Dir not readable')); } if (!$info->isWritable()) { throw new InvalidArgumentException(sprintf('Dir not writable')); } $this->dir = $dir; }
/** * init class instance by validating cache directory for being readable and writable * * @error 16202 * @return void * @throws Xapp_Cache_Driver_Exception */ protected function init() { try { $dir = new SplFileInfo(xapp_get_option(self::PATH, $this)); if (!$dir->isReadable()) { throw new Xapp_Cache_Driver_Exception(_("cache directory is not readable"), 1620201); } if (!$dir->isWritable()) { throw new Xapp_Cache_Driver_Exception(_("cache directory is not writable"), 1620202); } xapp_set_option(self::PATH, rtrim($dir->getRealPath(), DS) . DS, $this); } catch (Exception $e) { throw new Xapp_Cache_Driver_Exception(xapp_sprintf(_("cache directory file info error: %d, %s"), $e->getCode(), $e->getMessage()), 1620203); } }
public function __construct(BatchFactoryInterface $batchFactory, DirectoryFactory $directoryFactory, $dir) { $info = new \SplFileInfo($dir); if (!$info->isDir()) { throw new InvalidArgumentException(sprintf('Drop dir not found')); } if (!$info->isReadable()) { throw new InvalidArgumentException(sprintf('Drop dir not readable')); } if (!$info->isWritable()) { throw new InvalidArgumentException(sprintf('Drop dir not writable')); } $this->batchFactory = $batchFactory; $this->directoryFactory = $directoryFactory; $this->dir = $dir; }
public function write($data, $file) { $info = new \SplFileInfo(dirname($file)); if (!$info->isDir()) { throw new InvalidArgumentException(sprintf('File dir not found')); } if (!$info->isWritable()) { throw new InvalidArgumentException(sprintf('File dir not writable')); } $fileInfo = new \SplFileInfo($file); if ($fileInfo->isFile()) { unlink($file); } $h = fopen($file, 'w'); fwrite($h, $data); fclose($h); }
public function render($view = null, $layout = null) { try { ob_start(); if (defined('DOMPDF_TEMP_DIR')) { $dir = new SplFileInfo(DOMPDF_TEMP_DIR); if (!$dir->isDir() || !$dir->isWritable()) { trigger_error(__('%s is not writable', DOMPDF_TEMP_DIR), E_USER_WARNING); } } $errors = ob_get_contents(); ob_end_clean(); $download = false; $name = pathinfo($this->here, PATHINFO_BASENAME); $paperOrientation = 'portrait'; $paperSize = 'letter'; $preData = null; $postData = null; extract($this->viewVars, EXTR_IF_EXISTS); $dompdf = new DOMPDF(); $dompdf->set_protocol(''); $dompdf->set_protocol(WWW_ROOT); $dompdf->set_base_path('/'); $dompdf->set_paper($paperSize, $paperOrientation); if (!empty($preData) || !empty($postData)) { App::import('Vendor', 'Dompdf.PDFMerger', true, array(), 'PDFMerger' . DS . 'PDFMerger.php'); $merger = new PDFMerger(); if (!empty($preData)) { $merger->addPdfData($preData, DOMPDF_TEMP_DIR); } //Get the static information sheet $merger->addPdfData(file_get_contents("../View/Courses/survey_explanation.pdf"), DOMPDF_TEMP_DIR); if (!empty($postData)) { $merger->addPdfData($postData, DOMPDF_TEMP_DIR); } $merger->merge($download ? 'download' : 'browser'); } else { $dompdf->stream($name, array('Attachment' => $download)); } } catch (Exception $e) { $this->request->params['ext'] = 'html'; throw $e; } }
public function createOutFile(File $response) { $filename = $response->getFilename(); if ($filename == null) { throw new CurlFileException('The target filename of the response is null'); } $outFileInfo = new \SplFileInfo($filename); $parentDir = new \SplFileInfo($outFileInfo->getPath()); if (!$parentDir->isDir()) { throw new CurlFileException('The target filename directory does not exist'); } if (!$parentDir->isWritable()) { throw new CurlFileException('The target filename directory is not writable'); } if ($outFileInfo->isFile() && !$outFileInfo->isWritable()) { throw new CurlFileException('The target filename is not writable'); } $this->fileHandle = \fopen($response->getFilename(), 'w+'); }
public function __construct(LayoutFactoryInterface $layoutFactory, MetadataWriterFactoryInterface $metadataWriterFactory, MetadataLoaderFactoryInterface $metadataLoaderFactory, ArtworkLocatorFactoryInterface $artworkLocatorFactory, AudioLocatorFactoryInterface $audioLocatorFactory, $dir) { $info = new \SplFileInfo($dir); if (!$info->isDir()) { throw new InvalidArgumentException(sprintf('Packshot dir not found')); } if (!$info->isReadable()) { throw new InvalidArgumentException(sprintf('Packshot dir not readable')); } if (!$info->isWritable()) { throw new InvalidArgumentException(sprintf('Packshot dir not writable')); } $this->metadataWriterFactory = $metadataWriterFactory; $this->metadataLoaderFactory = $metadataLoaderFactory; $this->artworkLocatorFactory = $artworkLocatorFactory; $this->audioLocatorFactory = $audioLocatorFactory; $this->dir = $dir; $this->name = basename($dir); $this->layout = $layoutFactory->getInstance($dir); }
public function getCmd($inFile, $outFile) { $info = new \SplFileInfo($inFile); if (!$info->isFile()) { throw new InvalidArgumentException(sprintf('Audio file not found: %s', $inFile)); } if (!$info->isReadable()) { throw new InvalidArgumentException(sprintf('Audio file not readable: %s', $inFile)); } $info = new \SplFileInfo(dirname($outFile)); if (!$info->isDir()) { throw new InvalidArgumentException(sprintf('Output file dir not found: %s', dirname($outFile))); } if (!$info->isWritable()) { throw new InvalidArgumentException(sprintf('Output file dir not writable: %s', dirname($outFile))); } $cmd = ''; if ($this->preset !== null) { $cmd = sprintf("%s --preset %s", $cmd, $this->preset); } return sprintf("%s '%s' '%s'", $cmd, $inFile, $outFile); }
public function deleteSubDir($subDir) { $pathname = $this->getPathname($subDir); if (!$this->isValidSubDir($pathname)) { throw new InvalidArgumentException(sprintf('Not a valid subDir of temporary dir: "%s"', $pathname)); } $fileInfo = new \SplFileInfo($pathname); if (!$fileInfo->isDir() || !$fileInfo->isReadable() || !$fileInfo->isWritable()) { return; } foreach (new \DirectoryIterator($pathname) as $fileInfo) { if ($fileInfo->isDot()) { continue; } if ($fileInfo->isDir()) { $this->deleteSubDir($this->getSubDir($fileInfo->getPathname())); } else { unlink($fileInfo->getPathname()); } } rmdir($pathname); }
/** * Move the children of this directory into targetDir * * @param string $targetDir Target directory pathname * * @return void */ public function moveChildren($targetDir) { $info = new \SplFileInfo($targetDir); if (!$info->isDir()) { throw new InvalidArgumentException(sprintf('Target dir not found')); } if (!$info->isReadable()) { throw new InvalidArgumentException(sprintf('Target dir not readable')); } if (!$info->isWritable()) { throw new InvalidArgumentException(sprintf('Target dir not writable')); } foreach (new \DirectoryIterator($this->dir) as $info) { if ($info->isDot()) { continue; } $sourcePathname = $info->getPathname(); $subdirPathname = $this->subtractBasedir($sourcePathname, $this->dir); $targetPathname = sprintf('%s/%s', $targetDir, $subdirPathname); rename($sourcePathname, $targetPathname); } }
protected function _loadFile() { if (!file_exists($this->_filePath)) { if ($this->_id > 0) { foreach ($this->getOriginalFiles() as $file) { list($title, $id) = DevTools_Helper_File::getIdAndTitleFromFileName($file['fileName']); if ($id == $this->_id) { $this->_filePath = $file['filePath']; } } } if (!file_exists($this->_filePath)) { $this->_data = false; return; } } $file = new SplFileInfo($this->_filePath); if (!$file->isFile() or !$file->isReadable() or !$file->isWritable()) { return; } list($title, $id) = DevTools_Helper_File::getIdAndTitleFromFileName($file->getFilename()); $this->_data = array('id' => $id, 'title' => $title, 'fileName' => $file->getFilename(), 'contents' => file_get_contents($file->getPathname()), 'lastModifiedTime' => $file->getMTime(), 'filePath' => $file->getPathname()); }
protected function _checkPerms($path, $value) { if (!$path instanceof SplFileInfo) { try { $path = new SplFileInfo($path); } catch (Exception $e) { return false; } } // Get perms $perms = 0; if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN' || $path->isExecutable()) { $perms |= 0x1; } if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { $value |= 0x1; } if ($path->isWritable()) { $perms |= 0x2; } if ($path->isReadable()) { $perms |= 0x4; } // Apply file umask to requested permission if ($path->isFile()) { $value &= ~$this->_fileUmask; } // Check if (($perms & $value) != $value) { return false; } // Recurse if necessary, and is directory if ($this->_recursive && $path->isDir()) { try { $it = new DirectoryIterator($path->getPathname()); } catch (Exception $e) { // AFAIK this is caused by not having enough permissions return false; } foreach ($it as $fileinfo) { $flname = $fileinfo->getFilename(); if ($fileinfo->isDot() || $flname[0] == '.' || $flname == 'CVS') { continue; } if ($this->_ignoreFiles && $fileinfo->isFile()) { continue; } if (!$this->_checkPerms($fileinfo, $value)) { return false; } } } return true; }
<?php include __DIR__ . '/../../../test/sample_dir/fix_mtimes.inc'; $info = new SplFileInfo(__DIR__ . '/../../sample_dir'); if (!$info->isFile()) { echo $info->getRealPath(); } $info = new SplFileInfo(__DIR__ . '/../../sample_dir/file'); var_dump($info->getbaseName()); var_dump($info->getbaseName('.cpp')); $info->getCTime(); $info->getGroup(); $info->getInode(); $info->getMTime(); $info->getOwner(); $info->getPerms(); $info->getSize(); $info->getType(); $info->isDir(); $info->isFile(); $info->isLink(); $info->isReadable(); $info->isWritable();
/** * Determine is cache directory is writable * * @return boolean */ protected function _active() { $dir = new SplFileInfo($this->settings['path']); if (Configure::read('debug')) { $path = $dir->getPathname(); if (!is_dir($path)) { mkdir($path, 0775, true); } } if ($this->_init && !($dir->isDir() && $dir->isWritable())) { $this->_init = false; trigger_error(__d('cake_dev', '%s is not writable', $this->settings['path']), E_USER_WARNING); return false; } return true; }
/** * Determine is cache directory is writable * * @return bool */ protected function _active() { $dir = new \SplFileInfo($this->_config['path']); $path = $dir->getPathname(); if (!is_dir($path)) { mkdir($path, 0775, true); } if ($this->_init && !($dir->isDir() && $dir->isWritable())) { $this->_init = false; trigger_error(sprintf('%s is not writable', $this->_config['path']), E_USER_WARNING); return false; } return true; }
/** * Determine is cache directory is writable * * @return boolean */ protected function _active() { $dir = new SplFileInfo($this->settings['path']); if ($this->_init && !($dir->isDir() && $dir->isWritable())) { $this->_init = false; trigger_error(__d('cake_dev', '%s is not writable', $this->settings['path']), E_USER_WARNING); return false; } return true; }
/** * Create directory * @param string $directory */ private function createDirectory($directory) { if (!$this->filesystem->exists($directory)) { $this->filesystem->mkdir($directory); } $directory = new \SplFileInfo($directory); if (!$directory->isWritable()) { $this->filesystem->chmod($directory->getRealPath(), 0777); } }
public function splice($inFile, $outFile, $partLength = 45, $excess = 1, array $splices = array()) { $info = new \SplFileInfo($inFile); if (!$info->isFile()) { throw new InvalidArgumentException(sprintf('Audio file not found: %s', $inFile)); } if (!$info->isReadable()) { throw new InvalidArgumentException(sprintf('Audio file not readable: %s', $inFile)); } $info = new \SplFileInfo(dirname($outFile)); if (!$info->isDir()) { throw new InvalidArgumentException(sprintf('Output file dir not found: %s', dirname($outFile))); } if (!$info->isWritable()) { throw new InvalidArgumentException(sprintf('Output file dir not writable: %s', dirname($outFile))); } if (!count($splices)) { throw new InvalidArgumentException('At least one splice file must be provided'); } foreach ($splices as $splice) { $info = new \SplFileInfo($splice); if (!$info->isFile()) { throw new InvalidArgumentException(sprintf('Splice file not found: %s', $splice)); } if (!$info->isReadable()) { throw new InvalidArgumentException(sprintf('Splice file not readable: %s', $splice)); } $soxi = $this->soxiFactory->getInstance($splice); if ($soxi->getDuration() != 6) { throw new InvalidArgumentException(sprintf('Splice file duration must be 6 seconds: ', $splice)); } if ($soxi->getSampleRate() != 44100) { throw new InvalidArgumentException(sprintf('Splice file must have sampling-rate of 44100: ', $splice)); } } $spliceLength = 6; $jobId = uniqid(); $cleanInFile = sprintf("%s/%s-in.wav", $this->tmpDir, $jobId); $this->soxRunner->execute(sprintf("%s -r 44100 -t wav %s", $inFile, $cleanInFile)); $soxi = $this->soxiFactory->getInstance($cleanInFile); $duration = $soxi->getDuration(); $numParts = floor($duration / $partLength); $tailLength = $duration - $numParts * $partLength; $partStart = 0; $parts = array(); if ($numParts == 0) { // too short - use as is rename($cleanInFile, $outFile); return; } else { if ($numParts == 1) { if ($tailLength > $partLength / 2) { // make 2 parts with shorter partLength $partLength = floor($duration / 2); $numParts = floor($duration / $partLength); $tailLength = $duration - $numParts * $partLength; } // use directly with part > partLength rename($cleanInFile, $outFile); return; } } $makePartName = function ($dir, $jobId, $num) { return sprintf("%s/%s-part-%s.wav", $dir, $jobId, $num); }; for ($x = 1; $x < $numParts; $x++) { $parts[$x] = $makePartName($this->tmpDir, $jobId, $x); $this->trimAudio($cleanInFile, $parts[$x], $partStart, $partLength); $partStart = $partLength * $x; } if ($tailLength > $partLength / 2) { # trim last full part and tail as separate pieces $parts[$numParts] = $makePartName($this->tmpDir, $jobId, $numParts); $this->trimAudio($cleanInFile, $parts[$numParts], $partStart, $partLength); $partStart = $partLength * $numParts; $numLastPart = $numParts + 1; $parts[$numLastPart] = $makePartName($this->tmpDir, $jobId, $numLastPart); $this->trimAudio($cleanInFile, $parts[$numLastPart], $partStart, $tailLength); $numParts++; } else { # make one piece from last full part and tail $parts[$numParts] = $makePartName($this->tmpDir, $jobId, $numParts); $lastPartLength = $partLength + $tailLength; $this->trimAudio($cleanInFile, $parts[$numParts], $partStart, $lastPartLength); } $splicedParts = array(); foreach ($parts as $key => $part) { if ($key < count($parts)) { $splice = $splices[rand(0, count($splices) - 1)]; $splicedParts[$key] = sprintf("%s/%s-spliced-%s.wav", $this->tmpDir, $jobId, $key); $this->spliceAudio($parts[$key], $splice, $splicedParts[$key], $partLength, $excess); } } #print_r($parts); #print_r($splicedParts); $tmpFileOne = sprintf("%s/%s-tmp-one.wav", $this->tmpDir, $jobId); $tmpFileTwo = sprintf("%s/%s-tmp-two.wav", $this->tmpDir, $jobId); if (count($splicedParts) > 1) { foreach ($splicedParts as $key => $part) { if ($key === 1) { $nextKey = $key + 1; $currentLength = $partLength + $spliceLength - 2 * $excess; $this->spliceAudio($splicedParts[$key], $splicedParts[$nextKey], $tmpFileOne, $currentLength, $excess); copy($tmpFileOne, $tmpFileTwo); } else { if ($key > 2 && $key <= count($splicedParts)) { $soxi = $this->soxiFactory->getInstance($tmpFileTwo); $currentLength = $soxi->getDuration(); $this->spliceAudio($tmpFileTwo, $splicedParts[$key], $tmpFileOne, $currentLength, $excess); copy($tmpFileOne, $tmpFileTwo); } } } #print count($parts)."\n"; $soxi = $this->soxiFactory->getInstance($tmpFileTwo); $currentLength = $soxi->getDuration(); $lastPart = count($parts); $this->spliceAudio($tmpFileTwo, $parts[$lastPart], $tmpFileOne, $currentLength, $excess); unlink($tmpFileTwo); } else { $onlyPartWithNoise = $splicedParts[count($splicedParts)]; $soxi = $this->soxiFactory->getInstance($onlyPartWithNoise); $currentLength = $soxi->getDuration(); $lastPart = count($parts); $this->spliceAudio($onlyPartWithNoise, $parts[$lastPart], $tmpFileOne, $currentLength, $excess); } rename($tmpFileOne, $outFile); unlink($cleanInFile); foreach ($parts as $part) { unlink($part); } foreach ($splicedParts as $splicedPart) { unlink($splicedPart); } }
/** */ public function isWritable() { if (null === $this->w) { $this->w = parent::isWritable(); } return $this->w; }
/** * Get data from composer.json * * @param string $file Full path to composer.json * @return mixed */ protected function get_composer_data($file) { $file = new \SplFileInfo($file); if (!$file->isReadable() || !$file->isWritable()) { return null; } $data = file_get_contents($file->getPathname()); if (!$data) { return null; } return json_decode($data, true); }
/** * Checks whether thumbnail already exists. * * @return bool */ public function hasThumb() { return $this->thumb && $this->thumb->isWritable(); }
public function testDecoratedMethods() { $decorated = $this->getMockBuilder('hanneskod\\classtools\\Tests\\MockSplFileInfo')->setConstructorArgs([''])->getMock(); $decorated->expects($this->once())->method('getRelativePath'); $decorated->expects($this->once())->method('getRelativePathname'); $decorated->expects($this->once())->method('getContents'); $decorated->expects($this->once())->method('getATime'); $decorated->expects($this->once())->method('getBasename'); $decorated->expects($this->once())->method('getCTime'); $decorated->expects($this->once())->method('getExtension'); $decorated->expects($this->once())->method('getFileInfo'); $decorated->expects($this->once())->method('getFilename'); $decorated->expects($this->once())->method('getGroup'); $decorated->expects($this->once())->method('getInode'); $decorated->expects($this->once())->method('getLinkTarget'); $decorated->expects($this->once())->method('getMTime'); $decorated->expects($this->once())->method('getOwner'); $decorated->expects($this->once())->method('getPath'); $decorated->expects($this->once())->method('getPathInfo'); $decorated->expects($this->once())->method('getPathname'); $decorated->expects($this->once())->method('getPerms'); $decorated->expects($this->once())->method('getRealPath'); $decorated->expects($this->once())->method('getSize'); $decorated->expects($this->once())->method('getType'); $decorated->expects($this->once())->method('isDir'); $decorated->expects($this->once())->method('isExecutable'); $decorated->expects($this->once())->method('isFile'); $decorated->expects($this->once())->method('isLink'); $decorated->expects($this->once())->method('isReadable'); $decorated->expects($this->once())->method('isWritable'); $decorated->expects($this->once())->method('openFile'); $decorated->expects($this->once())->method('setFileClass'); $decorated->expects($this->once())->method('setInfoClass'); $decorated->expects($this->once())->method('__toString')->will($this->returnValue('')); $fileInfo = new SplFileInfo($decorated); $fileInfo->getRelativePath(); $fileInfo->getRelativePathname(); $fileInfo->getContents(); $fileInfo->getATime(); $fileInfo->getBasename(); $fileInfo->getCTime(); $fileInfo->getExtension(); $fileInfo->getFileInfo(); $fileInfo->getFilename(); $fileInfo->getGroup(); $fileInfo->getInode(); $fileInfo->getLinkTarget(); $fileInfo->getMTime(); $fileInfo->getOwner(); $fileInfo->getPath(); $fileInfo->getPathInfo(); $fileInfo->getPathname(); $fileInfo->getPerms(); $fileInfo->getRealPath(); $fileInfo->getSize(); $fileInfo->getType(); $fileInfo->isDir(); $fileInfo->isExecutable(); $fileInfo->isFile(); $fileInfo->isLink(); $fileInfo->isReadable(); $fileInfo->isWritable(); $fileInfo->openFile(); $fileInfo->setFileClass(); $fileInfo->setInfoClass(); (string) $fileInfo; }
public static function create($kernelRootDir, Filesystem $filesystem) { $branchLogoDir = realpath($kernelRootDir . '/../web') . Logo::PATH_TO_LOGO_DIR; if (!$filesystem->exists($branchLogoDir)) { $filesystem->mkdir($branchLogoDir); } $branchLogoDir = new \SplFileInfo($branchLogoDir); if (!$branchLogoDir->isWritable()) { $filesystem->chmod($branchLogoDir->getRealPath(), 0777); } return new BranchLogoHandler($branchLogoDir, $filesystem); }