Elgg  Version master
TimeUsing.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Traits;
4 
10 trait TimeUsing {
11 
12  private ?\DateTimeImmutable $time = null;
13 
22  public function getCurrentTime(string $modifier = ''): \DateTimeImmutable {
23  $time = $this->time ?? new \DateTimeImmutable();
24  if ($modifier) {
25  $time = $time->modify($modifier);
26  }
27 
28  return $time;
29  }
30 
38  public function setCurrentTime(?\DateTimeInterface $time = null): void {
39  if ($time instanceof \DateTimeInterface) {
40  $this->time = \DateTimeImmutable::createFromInterface($time);
41  } else {
42  $this->time = new \DateTimeImmutable();
43  }
44  }
45 
53  public function resetCurrentTime(): void {
54  unset($this->time);
55  }
56 }
setCurrentTime(?\DateTimeInterface $time=null)
Set the current time.
Definition: TimeUsing.php:38
resetCurrentTime()
Reset the current time Use after the time has been set with setCurrentTime and it no longer needs to ...
Definition: TimeUsing.php:53
trait TimeUsing
Adds methods for setting the current time (for testing)
Definition: TimeUsing.php:10
getCurrentTime(string $modifier='')
Get the time.
Definition: TimeUsing.php:22
if(! $annotation instanceof ElggAnnotation) $time
Definition: time.php:20
if(parse_url(elgg_get_site_url(), PHP_URL_PATH) !=='/') if(file_exists(elgg_get_root_path() . 'robots.txt'))
Set robots.txt.
Definition: robots.php:10