protected function loadCachedFile()
 {
     if (!$this->cacheFile->isReadable()) {
         return null;
     }
     if ($this->cacheFile->getMTime() < $this->dataFile->getMTime()) {
         return null;
     }
     $jsonString = file_get_contents($this->cacheFile->getPathname());
     if (false === $jsonString) {
         throw new InvalidArgumentException("Can not read file content from '{$this->cacheFile->getPathname()}'!");
     }
     return CiteCollection::loadFromJson($jsonString);
 }
Example #2
0
 public function importSingleMovie(\SplFileInfo $source)
 {
     if (!$source->isReadable()) {
         return $this->output->writelnError(sprintf("File %s not readable", $source->getFilename()));
     }
     $this->output->writelnInfo(sprintf("Importing %s ...", $source->getRealPath()));
     $file = $source->openFile();
     /** @var Movies $movie */
     $movie = $this->getMovie($file->fread($file->getSize()), $file->getBasename('.html'));
     if (!$movie) {
         return $this->output->writelnError(sprintf("Not found dmm id", $source->getFilename()));
     }
     $this->currentDmmId = $movie->banngo;
     if (Movies::findFirstById($movie->id)) {
         return $this->output->writelnWarning(sprintf("Movie %s already exists, insert skipped", $movie->banngo));
     }
     /** @var Mysql $db */
     $db = $this->getDI()->get('dbMaster');
     $db->begin();
     if (false === $movie->save()) {
         $db->rollback();
         return $this->output->writelnError(sprintf("Movie saving failed by %s", implode(',', $movie->getMessages())));
     }
     $db->commit();
     $this->output->writelnSuccess(sprintf("Movie %s saving success as %s, detail: %s", $movie->banngo, $movie->id, ''));
 }
Example #3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $fileInfo = new \SplFileInfo($this->getContainer()->getParameter('kernel.root_dir') . '/../web/sitemap.xml');
     if ($fileInfo->isFile() && $fileInfo->isReadable()) {
         $output->write('Reading sitemap.xml...');
         $file = $fileInfo->openFile();
         $xml = '';
         while (!$file->eof()) {
             $xml .= $file->fgets();
         }
         $output->writeln(' done.');
         $output->write('Updating sitemap.xml...');
         $sitemap = new \SimpleXMLIterator($xml);
         $sitemap->rewind();
         $lastmodDate = new \DateTime();
         $lastmodDate->sub(new \DateInterval('P1D'));
         $lastmodDateFormatted = $lastmodDate->format('Y-m-d');
         while ($sitemap->valid()) {
             $sitemap->current()->lastmod = $lastmodDateFormatted;
             $sitemap->next();
         }
         $file = $file->openFile('w');
         $file->fwrite($sitemap->asXML());
         $output->writeln(' done.');
     } else {
         $output->writeln('Error: Cannot open file web/sitemap.xml');
     }
 }
Example #4
0
 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;
 }
/**
 * 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);
    }
}
 /**
  * Main check method
  *
  * @param string $pathToFile
  * @throws \RuntimeException if file not found
  * @return bool
  */
 public function validate($pathToFile)
 {
     $this->clearErrors();
     $path = new \SplFileInfo($pathToFile);
     if (!$path->isFile() || !$path->isReadable()) {
         throw new \RuntimeException(sprintf('File "%s" not found', $pathToFile));
     }
     $file = $path->openFile('r');
     $currentLineNumber = 1;
     while (!$file->eof()) {
         $line = $file->fgets();
         if ($line == '' && $file->eof()) {
             break;
         }
         // Validate line structure
         $this->validateEOL($currentLineNumber, $line);
         $nodes = array_filter(preg_split('/\\s+/', $line));
         // Validate label
         $label = array_shift($nodes);
         $this->validateLabel($currentLineNumber, $label);
         // Validate features format
         $this->validateFeatures($currentLineNumber, $nodes);
         // Increate the line number
         $currentLineNumber++;
     }
     return $this->isValid();
 }
Example #7
0
 /**
  * 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()));
     }
 }
Example #8
0
 public function __construct(\SplFileInfo $file, $priority = 0)
 {
     if (!$file->isReadable()) {
         throw new \RuntimeException(sprintf('Pipeline source not readable: "%s"', $file->getPathname()));
     }
     $this->file = $file;
     $this->priority = (int) $priority;
 }
Example #9
0
 /**
  * @see \Bolt\Database\Migration\Input\InputFileInterface::readFile()
  */
 public function readFile()
 {
     $filename = (string) $this->file;
     if ($this->file->isReadable()) {
         try {
             $data = $this->parser->parse(file_get_contents($filename) . "\n");
             $this->import->setData($data);
             return true;
         } catch (ParseException $e) {
             $this->import->setError(true)->setErrorMessage("File '{$filename}' has invalid YAML!");
             return false;
         }
     } else {
         $this->import->setError(true)->setErrorMessage("File '{$filename}' not readable!");
         return false;
     }
 }
Example #10
0
 /**
  * Returns file checksum
  *
  * @param string $file
  * @return string
  */
 public function calculate($file)
 {
     $file = new \SplFileInfo($file);
     if (!$file->isFile() && !$file->isReadable()) {
         throw new \InvalidArgumentException('Invalid argument supplied for checksum calculation, only existing files are allowed');
     }
     return sprintf('%s:%s', $file->getMTime(), $file->getSize());
 }
 /**
  * Scans an individual view file, adding it's version number (if found) to the
  * $this->views array.
  *
  * @param SplFileInfo $file
  */
 protected function scan_view(SplFileInfo $file)
 {
     if (!$file->isFile() || !$file->isReadable()) {
         return;
     }
     $version = $this->get_template_version($file->getPathname());
     $this->originals[$this->short_name($file->getPathname())] = $version;
 }
 /**
  * @param string $filePath
  * @throws InvalidArgumentException
  */
 public function setFilePath($filePath)
 {
     $this->fileInfo = new \SplFileInfo($filePath);
     if (!$this->fileInfo->isFile()) {
         throw new InvalidArgumentException(sprintf('File "%s" does not exists.', $filePath));
     } elseif (!$this->fileInfo->isReadable()) {
         throw new InvalidArgumentException(sprintf('File "%s" is not readable.', $this->fileInfo->getRealPath()));
     }
 }
 /**
  * @param string $filename
  * @param string $mimeType
  * @return Blob
  * @throws NuxeoClientException
  */
 public static function fromFile($filename, $mimeType)
 {
     $fileInfo = new \SplFileInfo($filename);
     if ($fileInfo->isReadable()) {
         return new Blob($fileInfo->getFilename(), $fileInfo, $mimeType);
     } else {
         throw NuxeoClientException::fromPrevious(new NoSuchFileException($filename));
     }
 }
 /**
  * @param Request $request
  *
  * @return BinaryFileResponse
  *
  * @throws HttpException
  */
 public function downloadAction(Request $request)
 {
     $document = new \SplFileInfo($this->resources . '/' . $request->get('fileName'));
     if (!$document->isReadable()) {
         throw new HttpException(404);
     }
     $response = new BinaryFileResponse($document);
     $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $document->getFilename());
     return $response;
 }
Example #15
0
 public function importXmlFile(\SplFileInfo $source)
 {
     if (!$source->isReadable()) {
         return $this->output->writelnError(sprintf("File %s not readable", $source->getFilename()));
     }
     $this->output->writelnInfo(sprintf("Importing %s ...", $source->getRealPath()));
     $file = $source->openFile();
     $xml = simplexml_load_string($file->fread($file->getSize()));
     return $this->saveDmmList($xml);
 }
Example #16
0
 /**
  * Checks for the existance of a cache file
  * Returns false if none exists, path to cache otherwise
  * @param  string $name name of template
  * @return mixed       returns false if no cache file, path otherwise
  */
 public function file($name)
 {
     $path = $this->_cacheDir . "/template/" . $name;
     $file = new \SplFileInfo($path);
     if (!$file->isFile() || !$file->isReadable()) {
         // good place to recache
         return false;
     }
     return $file->getPathname();
 }
Example #17
0
 /**
  * @param mixed $item
  *
  * @return array<\SplFileInfo, string>
  */
 public function convert($item)
 {
     if ($item instanceof \SplFileInfo === false) {
         $item = new \SplFileInfo($item);
     }
     if ($item->isReadable() === false) {
         throw new \InvalidArgumentException(sprintf('The given file "%s" is not readable.', $item->getPathname()));
     }
     return ['file' => $item, 'content' => file_get_contents($item->getPathname())];
 }
Example #18
0
 /**
  * @see \Bolt\Database\Migration\Input\InputFileInterface::readFile()
  */
 public function readFile()
 {
     $filename = (string) $this->file;
     if ($this->file->isReadable()) {
         try {
             $data = $this->parser->parse(file_get_contents($filename));
             $this->import->setData($data);
             return true;
         } catch (ParsingException $e) {
             $this->import->setError(true)->setErrorMessage("File '{$filename}' has invalid JSON!");
             $details = $e->getDetails();
             foreach ($details as $detail) {
                 $this->import->setErrorMessage($detail);
             }
             return false;
         }
     } else {
         $this->import->setError(true)->setErrorMessage("File '{$filename}' not readable!");
         return false;
     }
 }
Example #19
0
 public function __construct(SoxiRunner $soxiRunner, $pathname)
 {
     $info = new \SplFileInfo($pathname);
     if (!$info->isFile()) {
         throw new InvalidArgumentException(sprintf('Audio file not found: %s', $pathname));
     }
     if (!$info->isReadable()) {
         throw new InvalidArgumentException(sprintf('Audio file not readable: %s', $pathname));
     }
     $this->soxiRunner = $soxiRunner;
     $this->pathname = $pathname;
 }
 public function __construct(XmlParser $xmlParser, $file)
 {
     $info = new \SplFileInfo($file);
     if (!$info->isFile()) {
         throw new InvalidArgumentException(sprintf('Godisko metadata Xml file not found'));
     }
     if (!$info->isReadable()) {
         throw new InvalidArgumentException(sprintf('Godisko metadata Xml file not readable'));
     }
     $this->xmlParser = $xmlParser;
     $this->file = $file;
 }
 private function getVboxUserPassword()
 {
     $file = new FileInfo("/etc/default/openmediavault-virtualbox");
     if (!$file->isReadable()) {
         throw new Exception("Can't read /etc/defaults/openmediavault-virtualbox");
     }
     $file = $file->openFile();
     $password = $file->fgets();
     $file = null;
     // Trim the password variable since it may contain a newline char.
     return trim($password);
 }
 private function getSplFile($source, $item)
 {
     if ($item == '.' || $item == '..') {
         return false;
     }
     $splFile = new \SplFileInfo($source . '/' . $item);
     $extension = $splFile->getExtension();
     if ($extension != 'json' || $splFile->isDir() || false == $splFile->isReadable()) {
         return false;
     }
     return $splFile;
 }
Example #23
0
 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);
 }
Example #24
0
 public function read($file)
 {
     $info = new \SplFileInfo($file);
     if (!$info->isFile()) {
         throw new InvalidArgumentException(sprintf('File not found'));
     }
     if (!$info->isReadable()) {
         throw new InvalidArgumentException(sprintf('File not readable'));
     }
     $handle = fopen($file, 'r');
     $fileContents = fread($handle, filesize($file));
     fclose($handle);
     return $fileContents;
 }
Example #25
0
 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;
 }
Example #26
0
function wfLeBibValidateFile(SplFileInfo $file)
{
    if (!$file->isFile()) {
        if (LEBIBDEBUG) {
            echo "LeBib: {$file} is not a file.";
        }
        throw new Exception("LeBib: {$file} is not a file.");
    }
    if (!$file->isReadable()) {
        if (LEBIBDEBUG) {
            echo "LeBib: {$file} is not readable.";
        }
        throw new Exception("LeBib: {$file} is not readable.");
    }
}
Example #27
0
 protected function __construct($path, $fn, $delimiter)
 {
     $this->delimiter = $delimiter;
     if (substr($path, -1) != DIRECTORY_SEPARATOR) {
         $path .= DIRECTORY_SEPARATOR;
     }
     $conf_file = new \SplFileInfo($path . $fn);
     if (!$conf_file->isReadable()) {
         $conf_file = new \SplFileInfo($path . $fn . '.dist');
         if (!$conf_file->isReadable()) {
             throw new UnreadableConfigException($conf_file->getRealPath());
         }
     }
     $this->data = Yaml::parse(file_get_contents($conf_file->getRealPath()));
 }
Example #28
0
 /**
  * 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);
     }
 }
Example #29
0
 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;
 }
Example #30
0
 /**
  * Load class from specified file.
  *
  * @param \SplFileInfo $file
  *
  * @return TestCase
  *
  * @throws FilterException If cannot open file
  * @throws FilterException If TestCase class does not exists in this file
  */
 public static function load(\SplFileInfo $file)
 {
     if (!$file->isReadable()) {
         throw new FilterException(sprintf('Cannot open file "%s"', $file->getRealPath()));
     }
     $loadedClasses = get_declared_classes();
     include_once $file;
     $loadedClasses = array_reverse(array_values(array_diff(get_declared_classes(), $loadedClasses)));
     $name = $file->getBasename('.php');
     /** @var TestCase $class */
     foreach ($loadedClasses as $class) {
         if (preg_match('{^([\\w\\\\]+\\\\)?' . $name . '$}', $class)) {
             if (is_subclass_of($class, '\\Unteist\\TestCase')) {
                 return new $class();
             }
         }
     }
     throw new FilterException(sprintf('TestCase class does not found in file "%s"', $file->getRealPath()));
 }