本文整理汇总了PHP中SplFileInfo::isReadable方法的典型用法代码示例。如果您正苦于以下问题:PHP SplFileInfo::isReadable方法的具体用法?PHP SplFileInfo::isReadable怎么用?PHP SplFileInfo::isReadable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SplFileInfo
的用法示例。
在下文中一共展示了SplFileInfo::isReadable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadCachedFile
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);
}
示例2: importSingleMovie
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, ''));
}
示例3: execute
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');
}
}
示例4: execute
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;
}
示例5: createDirectory
/**
* 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);
}
}
示例6: validate
/**
* 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();
}
示例7: __construct
/**
* 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()));
}
}
示例8: __construct
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;
}
示例9: readFile
/**
* @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;
}
}
示例10: calculate
/**
* 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());
}
示例11: scan_view
/**
* 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;
}
示例12: setFilePath
/**
* @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()));
}
}
示例13: fromFile
/**
* @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));
}
}
示例14: downloadAction
/**
* @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;
}
示例15: importXmlFile
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);
}