/**
  * {@inheritDoc}
  */
 public function validateContent($content)
 {
     if (is_string($content)) {
         $content = new \SplFileInfo($content);
     }
     return $content instanceof \SplFileInfo && $content->isFile();
 }
    /**
     * 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;
    }
Example #3
0
 /**
  * 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)));
     }
 }
Example #4
0
 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);
 }
Example #5
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');
     }
 }
 /**
  * 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;
 }
 /**
  * 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 #8
0
 /**
  * @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());
 }
Example #9
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;
 }
 /**
  * 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;
 }
Example #11
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());
 }
 /**
  * @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()));
     }
 }
Example #13
0
 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);
 }
 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;
 }
Example #15
0
 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);
 }
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
/**
 * @return boolean
 */
function verifyTemplateIsFile($template)
{
    $file = new \SplFileInfo($template);
    try {
        $file->isFile();
    } catch (Exception $e) {
        return false;
    }
    return true;
}
Example #18
0
 public function loadMigrationsFromDirectory($dir)
 {
     foreach (glob($dir . DIRECTORY_SEPARATOR . '*.php') as $file) {
         $file = new \SplFileInfo($file);
         $m = NULL;
         if ($file->isFile() && preg_match("'^(Version([0-9]{14}))\\.php\$'i", $file->getFilename(), $m)) {
             $this->migrations[$m[2]] = realpath($file->getPathname());
         }
     }
     ksort($this->migrations);
 }
Example #19
0
 public static function factory($path)
 {
     $fileInfo = new SplFileInfo($path);
     if ($fileInfo->isDir()) {
         $element = new Stagehand_DirectorySnap_Element_Directory($path);
     } elseif ($fileInfo->isLink()) {
         $element = new Stagehand_DirectorySnap_Element_Link($path);
     } elseif ($fileInfo->isFile()) {
         $element = new Stagehand_DirectorySnap_Element_File($path);
     }
     return $element;
 }
Example #20
0
 public function make($prefix = '', $postfix = '', $suffix = '')
 {
     $name = $this->assemble($prefix, $postfix, $suffix, null);
     $count = 1;
     while (true) {
         $fileInfo = new \SplFileInfo(sprintf('%s/%s', $this->dir, $name));
         if (!$fileInfo->isDir() && !$fileInfo->isFile()) {
             return basename($name);
         }
         $name = $this->assemble($prefix, $postfix, $suffix, $count++);
     }
 }
Example #21
0
 /**
  * @param string $filePath
  *
  * @return StandardLexer
  * @throws \InvalidArgumentException
  */
 public function fromFile($filePath)
 {
     $fileDescriptor = new \SplFileInfo($filePath);
     if (!$fileDescriptor->isFile()) {
         throw new \InvalidArgumentException('file not found at: ' . $filePath);
     }
     $source = new FileSource($fileDescriptor);
     $reader = $source->createReader();
     $tokenMatchers = TokenPatterns::regexPatterns();
     $lexer = new StandardLexer($tokenMatchers, new WhitespaceMatcher(), new LongestMatchWinsStrategy(), $reader);
     return $lexer;
 }
 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;
 }
Example #23
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;
 }
Example #24
0
 /**
  * @param $directory
  *
  * @return $this
  */
 public function setPathname($directory)
 {
     try {
         $directory = new \SplFileInfo($directory);
     } catch (\Exception $ex) {
         throw new \InvalidArgumentException('An error occur', 0, $ex);
     }
     if ($directory->isFile()) {
         throw new \InvalidArgumentException('Expecting a directory, got file');
     }
     $this->directory = $directory;
     return $this;
 }
 public function __construct(\SplFileInfo $file)
 {
     if (!$file->isFile()) {
         throw new \LogicException("Please pass a file not a directory.");
     }
     $this->originalPhp = file_get_contents($this->file->getPathname());
     $php = new Php($this->originalPhp);
     if (!$php->isValid($errors, true)) {
         throw new BadPhpException($this->originalPhp, $errors);
     }
     $this->file = $file;
     $this->analyse();
 }
Example #26
0
 /**
  * @param  \SplFileInfo  $file
  * @return bool
  */
 private function checkType(\SplFileInfo $file)
 {
     if ($this->type == 'any') {
         return TRUE;
     }
     if ($file->isFile() && $this->type == 'file') {
         return TRUE;
     }
     if ($file->isDir() && $this->type == 'dir') {
         return TRUE;
     }
     return FALSE;
 }
Example #27
0
 /**
  * Validate file permissions
  *
  * Checks to see if file permissions match correctly
  *
  * @param SplFileInfo $file     File to check
  * @param array       $badFiles current array of bad files to report
  *
  * @return array
  * @access public
  */
 public function validateSetting(SplFileInfo $file, array $badFiles)
 {
     if ($file->isFile()) {
         $path = substr_replace($file->getPath(), '', 0, strlen(Mage::getBaseDir()) + 1);
         $filepath = substr_replace($file->__toString(), '', 0, strlen(Mage::getBaseDir()) + 1);
         if (Mage::helper('bronto_verify/permissionchecker')->accept($path) && Mage::helper('bronto_verify/permissionchecker')->accept($filepath)) {
             $octalPerms = substr(sprintf('%o', $file->getPerms()), -$this->_permLen);
             if ($octalPerms != $this->_permission) {
                 $badFiles[$filepath]['file permission'] = $octalPerms;
             }
         }
     }
     return parent::validateSetting($file, $badFiles);
 }
Example #28
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;
 }
 /**
  * executes the Composer task
  */
 public function main()
 {
     $commandLine = $this->prepareCommandLine();
     $this->log("executing " . $commandLine);
     $composerFile = new SplFileInfo($this->getComposer());
     if (false === $composerFile->isFile()) {
         throw new BuildException(sprintf('Composer binary not found, path is "%s"', $composerFile));
     }
     $return = 0;
     passthru($commandLine, $return);
     if ($return > 0) {
         throw new BuildException("Composer execution failed");
     }
 }
 /**
  * @param string $type
  * @param string $filePath
  * @param array  $options
  *
  * @throws UnsupportedTypeException
  * @throws FileNotFoundException
  */
 public function __construct($type, $filePath, array $options = [])
 {
     $this->type = $type;
     $this->filePath = $filePath;
     $this->fileInfo = new \SplFileInfo($filePath);
     if (!$this->fileInfo->isFile()) {
         throw new FileNotFoundException(sprintf('File "%s" could not be found', $this->filePath));
     }
     $mimeType = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $this->filePath);
     if ('application/zip' === $mimeType && Type::XLSX !== $this->fileInfo->getExtension()) {
         $this->extractZipArchive();
     }
     $this->reader = ReaderFactory::create($type);
     if (isset($options['reader_options'])) {
         $this->setReaderOptions($options['reader_options']);
     }
     $this->reader->open($this->filePath);
     $this->reader->getSheetIterator()->rewind();
     $sheet = $this->reader->getSheetIterator()->current();
     $sheet->getRowIterator()->rewind();
     $this->headers = $sheet->getRowIterator()->current();
     $this->rows = $sheet->getRowIterator();
 }