getMTime example

parent::__construct('SplFileInfo');

        $this->path = $fileInfo->getPathname();

        try {
            if (\strlen($this->path) && $fileInfo->getRealPath()) {
                $this->perms = $fileInfo->getPerms();
                $this->size = $fileInfo->getSize();
                $this->owner = $fileInfo->getOwner();
                $this->group = $fileInfo->getGroup();
                $this->ctime = $fileInfo->getCTime();
                $this->mtime = $fileInfo->getMTime();
                $this->realpath = $fileInfo->getRealPath();
            }

            $this->is_dir = $fileInfo->isDir();
            $this->is_file = $fileInfo->isFile();
            $this->is_link = $fileInfo->isLink();

            if ($this->is_link) {
                $this->linktarget = $fileInfo->getLinkTarget();
            }
        } catch (RuntimeException $e) {
            
return $this;
    }

    /** * Automatically sets the Last-Modified header according the file modification date. * * @return $this */
    public function setAutoLastModified()static
    {
        $this->setLastModified(\DateTimeImmutable::createFromFormat('U', $this->file->getMTime()));

        return $this;
    }

    /** * Automatically sets the ETag header according to the checksum of the file. * * @return $this */
    public function setAutoEtag()static
    {
        

  public function testSuccessfulReuse($source_path$destination_path) {
    $file_reuse = $this->doTransform($source_path$destination_path);
    clearstatcache(TRUE, $destination_path);

    $timestamp = (new \SplFileInfo($file_reuse))->getMTime();
    $this->assertIsInt($timestamp);

    // We need to make sure the modified timestamp on the file is sooner than     // the attempted migration.     sleep(1);
    $configuration = ['file_exists' => 'use existing'];
    $this->doTransform($source_path$destination_path$configuration);
    clearstatcache(TRUE, $destination_path);
    $modified_timestamp = (new \SplFileInfo($destination_path))->getMTime();
    $this->assertEquals($timestamp$modified_timestamp);

    

  protected function createExtensionInfo(Extension $extension) {
    $info = $this->infoParser->parse($extension->getPathname());

    // Add the info file modification time, so it becomes available for     // contributed extensions to use for ordering extension lists.     $info['mtime'] = $extension->getFileInfo()->getMTime();

    // Merge extension type-specific defaults, making sure to replace NULL     // values.     foreach ($this->defaults as $key => $default_value) {
      if (!isset($info[$key])) {
        $info[$key] = $default_value;
      }
    }

    return $info;
  }

  
return $this;
    }

    /** * Automatically sets the Last-Modified header according the file modification date. * * @return $this */
    public function setAutoLastModified()static
    {
        $this->setLastModified(\DateTime::createFromFormat('U', $this->file->getMTime()));

        return $this;
    }

    /** * Automatically sets the ETag header according to the checksum of the file. * * @return $this */
    public function setAutoEtag()static
    {
        
/** * Filters the iterator values. */
    public function accept(): bool
    {
        $fileinfo = $this->current();

        if (!file_exists($fileinfo->getPathname())) {
            return false;
        }

        $filedate = $fileinfo->getMTime();
        foreach ($this->comparators as $compare) {
            if (!$compare->test($filedate)) {
                return false;
            }
        }

        return true;
    }
}
class LegacyExtensionTest extends UnitTestCase {

  /** * @covers ::__call */
  public function testDeprecatedCall() {
    $extension = new Extension($this->root, 'theme', 'core/themes/stark/stark.info.yml', 'stark.theme');
    $file = $extension->getFileInfo();
    $this->expectDeprecation('Drupal\Core\Extension\Extension::__call(\'getCTime\') is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use \Drupal\Core\Extension\Extension::getFileInfo() instead. See https://www.drupal.org/node/3322608');
    $this->assertSame($file->getCTime()$extension->getCTime());
    $this->expectDeprecation('Drupal\Core\Extension\Extension::__call(\'getMTime\') is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use \Drupal\Core\Extension\Extension::getFileInfo() instead. See https://www.drupal.org/node/3322608');
    $this->assertSame($file->getMTime()$extension->getMTime());
  }

}
continue;
            }

            // always monitor directories for changes, except the .. entries             // (otherwise deleted files wouldn't get detected)             if ($file->isDir() && str_ends_with($file, '/..')) {
                continue;
            }

            // for broken links             try {
                $fileMTime = $file->getMTime();
            } catch (\RuntimeException) {
                continue;
            }

            // early return if a file's mtime exceeds the passed timestamp             if ($timestamp < $fileMTime) {
                return false;
            }
        }

        return true;
    }
 elseif ($a->isFile() && $b->isDir()) {
                    return $order;
                }

                return $order * strcmp($a->getRealPath() ?: $a->getPathname()$b->getRealPath() ?: $b->getPathname());
            };
        } elseif (self::SORT_BY_ACCESSED_TIME === $sort) {
            $this->sort = static fn (\SplFileInfo $a, \SplFileInfo $b) => $order * ($a->getATime() - $b->getATime());
        } elseif (self::SORT_BY_CHANGED_TIME === $sort) {
            $this->sort = static fn (\SplFileInfo $a, \SplFileInfo $b) => $order * ($a->getCTime() - $b->getCTime());
        } elseif (self::SORT_BY_MODIFIED_TIME === $sort) {
            $this->sort = static fn (\SplFileInfo $a, \SplFileInfo $b) => $order * ($a->getMTime() - $b->getMTime());
        } elseif (self::SORT_BY_EXTENSION === $sort) {
            $this->sort = static fn (\SplFileInfo $a, \SplFileInfo $b) => $order * strnatcmp($a->getExtension()$b->getExtension());
        } elseif (self::SORT_BY_SIZE === $sort) {
            $this->sort = static fn (\SplFileInfo $a, \SplFileInfo $b) => $order * ($a->getSize() - $b->getSize());
        } elseif (self::SORT_BY_NONE === $sort) {
            $this->sort = $order;
        } elseif (\is_callable($sort)) {
            $this->sort = $reverseOrder ? static fn (\SplFileInfo $a, \SplFileInfo $b) => -$sort($a$b) : $sort(...);
        } else {
            throw new \InvalidArgumentException('The SortableIterator takes a PHP callable or a valid built-in sort algorithm as an argument.');
        }
    }

function hook_system_info_alter(array &$info, \Drupal\Core\Extension\Extension $file$type) {
  // Only fill this in if the .info.yml file does not define a 'datestamp'.   if (empty($info['datestamp'])) {
    $info['datestamp'] = $file->getFileInfo()->getMTime();
  }
}

/** * Perform necessary actions before a module is installed. * * @param string $module * The name of the module about to be installed. */
function hook_module_preinstall($module) {
  mymodule_cache_clear();
}
$dir_iterator = new \FilesystemIterator($directory$flags);
      }
      catch (\UnexpectedValueException $e) {
        // FilesystemIterator throws an UnexpectedValueException if the         // specified path is not a directory, or if it is not accessible.         continue;
      }

      $directory_unlink = TRUE;
      $directory_mtime = filemtime($directory);
      foreach ($dir_iterator as $fileinfo) {
        if ($directory_mtime > $fileinfo->getMTime()) {
          // Ensure the folder is writable.           @chmod($directory, 0777);
          @unlink($fileinfo->getPathName());
        }
        else {
          // The directory still contains valid files.           $directory_unlink = FALSE;
        }
      }

      if ($directory_unlink) {
        
Home | Imprint | This part of the site doesn't use cookies.