Ejemplo n.º 1
0
 /**
  * Get the PHP standard `stat()` function result
  *
  * The resulting table is returned with string indexes only
  * and few values transformed added depending on object's flags.
  *
  * @return array The result of the `stat()` function on the file, with string indexes only
  */
 public function getStat()
 {
     if ($this->exists()) {
         $flags = $this->getFlags();
         $stats = @stat($this->getRealPath());
         if ($stats) {
             foreach ($stats as $i => $val) {
                 if (!is_string($i)) {
                     unset($stats[$i]);
                 } else {
                     if (self::STAT_DATETIME_FIELD & $this->flags && in_array($i, array('atime', 'mtime', 'ctime'))) {
                         $stats[$i . 'DateTime'] = WebFilesystem::getDateTimeFromTimestamp($val);
                     } elseif (self::STAT_SIZE_FIELD & $this->flags && $i === 'size') {
                         $stats[$i . 'Transformed'] = WebFilesystem::getTransformedFilesize($val);
                     }
                 }
             }
         }
         return $stats;
     }
     return null;
 }
Ejemplo n.º 2
0
 /**
  * Returns TRUE if the object is an image
  *
  * @see isCommonImage()
  */
 public function isImage()
 {
     return $this->exists() && WebFilesystem::isCommonImage($this->getFilename());
 }
Ejemplo n.º 3
0
 public function getDocBookStack()
 {
     if (!isset($this->cache['docbook_stack'])) {
         $truefile = $this;
         $filepath = $truefile->getRealPath();
         if ($this->isLink() || $this->isRootLink()) {
             if ($this->isLink()) {
                 try {
                     $rp_tmp = realpath($this->getLinkTarget());
                 } catch (\Exception $e) {
                 }
                 if (empty($rp_tmp)) {
                     $rp_tmp = $this->getRealPath();
                 }
                 $truefile = new WebFileInfo($rp_tmp);
             } elseif ($this->isRootLink()) {
                 try {
                     $rp_tmp = @readlink($this->getPathname());
                 } catch (\Exception $e) {
                 }
                 if (empty($rp_tmp)) {
                     $rp_tmp = $this->getRealPath();
                 }
                 $truefile = new WebFileInfo($rp_tmp);
             }
         }
         $_size = $truefile->isDir() ? Helper::getDirectorySize($truefile->getPathname()) : $truefile->getSize();
         $this->cache['docbook_stack'] = array('path' => $this->getDocBookPath(), 'type' => $this->getType(), 'route' => Helper::getRoute($this->getRealPath()), 'name' => $this->getHumanReadableFilename(), 'size' => WebFilesystem::getTransformedFilesize($_size), 'plainsize' => $_size, 'mtime' => WebFilesystem::getDateTimeFromTimestamp($truefile->getMTime()), 'description' => $this->getDescription(), 'trans' => $this->isDir() ? array() : $this->findTranslations(), 'dirpath' => dirname($this->getPathname()), 'lines_nb' => $this->isDir() ? null : Helper::getFileLinesCount($this->getRealPath()), 'extension' => $this->getExtension());
     }
     return $this->cache['docbook_stack'];
 }
Ejemplo n.º 4
0
 public function isDotFile()
 {
     $this->getIterator();
     return $this->iterator->current()->isFile() && WebFilesystem::isDotFile($this->iterator->current()->getRealPath());
 }
Ejemplo n.º 5
0
 /**
  * Get the file size in human readable string
  *
  * @param int $decimals The decimals number to use in calculated file size
  * @return string A human readable string describing a file size
  */
 public function getHumanSize($decimals = 2)
 {
     return WebFilesystem::getTransformedFilesize($this->getSize());
 }