本文整理汇总了PHP中SplFileInfo::isFile方法的典型用法代码示例。如果您正苦于以下问题:PHP SplFileInfo::isFile方法的具体用法?PHP SplFileInfo::isFile怎么用?PHP SplFileInfo::isFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SplFileInfo
的用法示例。
在下文中一共展示了SplFileInfo::isFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validateContent
/**
* {@inheritDoc}
*/
public function validateContent($content)
{
if (is_string($content)) {
$content = new \SplFileInfo($content);
}
return $content instanceof \SplFileInfo && $content->isFile();
}
示例2: accept
/**
* UnsortedEpisodesFilter::accept()
*
* @return
*/
public function accept()
{
$file = new SplFileInfo( $this->getInnerIterator()->current() );
if ( !$file->isFile() )
{
echo "Not a file<br />";
return false;
}
if ( !preg_match( '/\.(mkv|avi)$/ ', $file->getBasename() ) )
{
echo "Not a video<br />";
return false;
}
if ( $file->getSize() < ( 25 * 1024 * 1024 ) )
{
echo "Too small<br />";
return false;
}
$subtitleFileNames = array( $file->getBasename() . '.srt', $file->getBasename() . '.ass' );
foreach ( $subtitleFileNames as $subtitleFileName )
if ( file_exists( $subtitleFileName ) )
return false;
}
示例3: make_writable
/**
* This function will make directory writable.
*
* @param string path
* @return void
* @throw Kohana_Exception
*/
public static function make_writable($path, $chmod = NULL)
{
try {
$dir = new SplFileInfo($path);
if ($dir->isFile()) {
throw new Kohana_Exception('Could not make :path writable directory because it is regular file', array(':path' => Debug::path($path)));
} elseif ($dir->isLink()) {
throw new Kohana_Exception('Could not make :path writable directory because it is link', array(':path' => Debug::path($path)));
} elseif (!$dir->isDir()) {
// Try create directory
Ku_Dir::make($path, $chmod);
clearstatcache(TRUE, $path);
}
if (!$dir->isWritable()) {
// Try make directory writable
chmod($dir->getRealPath(), $chmod === NULL ? Ku_Dir::$default_dir_chmod : $chmod);
clearstatcache(TRUE, $path);
// Check result
if (!$dir->isWritable()) {
throw new Exception('Make dir writable failed', 0);
}
}
} catch (Kohana_Exception $e) {
// Rethrow exception
throw $e;
} catch (Exception $e) {
throw new Kohana_Exception('Could not make :path directory writable', array(':path' => Debug::path($path)));
}
}
示例4: findResource
public function findResource($path)
{
$path = trim($path, '/\\');
if ($path == '') {
$info = new \SplFileInfo($this->pathBase);
if ($info->isFile()) {
return new FilesystemFile('', $info, $this);
}
return new FilesystemDirectory('', $info, $this);
}
$target = @realpath($this->pathBase . DIRECTORY_SEPARATOR . $path);
if ($target === false || !file_exists($target) || 0 !== strpos($target, $this->pathBase)) {
throw new \OutOfBoundsException(sprintf('Target resource not found: "%s"', $path));
}
$info = new \SplFileInfo($target);
if ($info->isFile()) {
$resource = new FilesystemFile($path, $info, $this);
$sql = 'SELECT * FROM "file_locks" WHERE "resource" = :resource AND "expires" > :time';
$stmt = $this->lockStore->prepare($sql);
$stmt->bindValue('resource', trim($resource->getPath(), '/'));
$stmt->bindValue('time', time());
$stmt->execute();
if (false !== ($row = $stmt->fetch(\PDO::FETCH_ASSOC))) {
$resource->setLockInfo($this->unserializeLock($row));
}
return $resource;
}
return new FilesystemDirectory($path, $info, $this);
}
示例5: 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');
}
}
示例6: __construct
/**
* Stores the file object.
*
* @param \SplFileInfo $file The file object
*
* @throws \InvalidArgumentException If $file is not a file
*/
public function __construct(\SplFileInfo $file)
{
if (!$file->isFile()) {
throw new \InvalidArgumentException(sprintf('%s is not a file.', $file));
}
$this->file = $file;
}
示例7: 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();
}
示例8: testGetFilename
/**
* @covers Versionable\Prospect\Response\File::__construct
* @covers Versionable\Prospect\Response\File::getFilename
*/
public function testGetFilename()
{
$filename = $this->object->getFilename();
$this->assertNotNull($filename);
$test = new \SplFileInfo($filename);
$this->assertFalse($test->isFile());
}
示例9: 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;
}
示例10: 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;
}
示例11: 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());
}
示例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: __construct
public function __construct(SplFileInfo $fileInfo)
{
$this->perms = $fileInfo->getPerms();
$this->size = $fileInfo->getSize();
$this->is_dir = $fileInfo->isDir();
$this->is_file = $fileInfo->isFile();
$this->is_link = $fileInfo->isLink();
if (($this->perms & 0xc000) === 0xc000) {
$this->typename = 'File socket';
$this->typeflag = 's';
} elseif ($this->is_file) {
if ($this->is_link) {
$this->typename = 'File symlink';
$this->typeflag = 'l';
} else {
$this->typename = 'File';
$this->typeflag = '-';
}
} elseif (($this->perms & 0x6000) === 0x6000) {
$this->typename = 'Block special file';
$this->typeflag = 'b';
} elseif ($this->is_dir) {
if ($this->is_link) {
$this->typename = 'Directory symlink';
$this->typeflag = 'l';
} else {
$this->typename = 'Directory';
$this->typeflag = 'd';
}
} elseif (($this->perms & 0x2000) === 0x2000) {
$this->typename = 'Character special file';
$this->typeflag = 'c';
} elseif (($this->perms & 0x1000) === 0x1000) {
$this->typename = 'FIFO pipe file';
$this->typeflag = 'p';
}
parent::__construct('FsPath');
$this->path = $fileInfo->getPathname();
$this->realpath = realpath($this->path);
if ($this->is_link && method_exists($fileInfo, 'getLinktarget')) {
$this->linktarget = $fileInfo->getLinktarget();
}
$flags = array($this->typeflag);
// User
$flags[] = $this->perms & 0x100 ? 'r' : '-';
$flags[] = $this->perms & 0x80 ? 'w' : '-';
$flags[] = $this->perms & 0x40 ? $this->perms & 0x800 ? 's' : 'x' : ($this->perms & 0x800 ? 'S' : '-');
// Group
$flags[] = $this->perms & 0x20 ? 'r' : '-';
$flags[] = $this->perms & 0x10 ? 'w' : '-';
$flags[] = $this->perms & 0x8 ? $this->perms & 0x400 ? 's' : 'x' : ($this->perms & 0x400 ? 'S' : '-');
// Other
$flags[] = $this->perms & 0x4 ? 'r' : '-';
$flags[] = $this->perms & 0x2 ? 'w' : '-';
$flags[] = $this->perms & 0x1 ? $this->perms & 0x200 ? 't' : 'x' : ($this->perms & 0x200 ? 'T' : '-');
$this->contents = implode($flags);
}
示例14: getEntryWithPermalinkId
public function getEntryWithPermalinkId($permalink_id)
{
$this->validatePermalinkId($permalink_id);
$file = new \SplFileInfo($this->datadir . '/' . $permalink_id . '.' . $this->file_extension);
if ($file->isFile()) {
return new Entry($file, $this);
}
return null;
}
示例15: createBatch
public function createBatch($name)
{
$dir = sprintf('%s/%s', $this->dir, $this->checkName($name));
$fileInfo = new \SplFileInfo($dir);
if ($fileInfo->isDir() || $fileInfo->isFile()) {
throw new InvalidArgumentException(sprintf('Batch name exists: "%s"', $name));
}
mkdir($dir, 0777);
return $this->batchFactory->getInstance($dir);
}