/** * Test if the `setModificationTime` method dispatches the * `ResourceStatisticsChangeEvent` event. */ public function testSetModificationTimeDispatchesEvent() { $dispatched = false; $listener = function (ResourceStatisticsChangeEvent $event) use(&$dispatched) { $dispatched = true; }; $stat = new ResourceStatistics(); $stat->addEventListener(ResourceStatisticsChangeEvent::MODIFICATION_TIME_CHANGED, $listener); $stat->setModificationTime(time()); $this->assertTrue($dispatched); }
/** * Return the `ResourceStatistics` object for the resource. * * This resource supports the modification of the following statistical values: * <ul> * <li>modification time</li> * <li>access time</li> * </ul> * * @return ResourceStatistics An object containing statistics information about a resource. */ public function getStat() { clearstatcache(); $stat = new ResourceStatistics(); $stat->setAccessTime($this->fileInfo->getATime()); $stat->setCreationTime($this->fileInfo->getCTime()); $stat->setModificationTime($this->fileInfo->getMTime()); $stat->setSize($this->fileInfo->getSize()); // The event listener used to set the modification and access time $fileInfo = $this->fileInfo; $listener = function (ResourceStatisticsChangeEvent $event) use($fileInfo) { /* @var ResourceStatistics $target */ /* @var SplFileInfo $fileInfo */ $target = $event->getTarget(); touch($fileInfo->getPathname(), $target->getModificationTime(), $target->getAccessTime()); }; // Add event listeners $stat->addEventListener(ResourceStatisticsChangeEvent::ACCESS_TIME_CHANGED, $listener); $stat->addEventListener(ResourceStatisticsChangeEvent::MODIFICATION_TIME_CHANGED, $listener); return $stat; }
/** * Return the `ResourceStatistics` object for the resource. * * This resource supports the modification of the following statistical values: * <ul> * <li>creation time</li> * <li>modification time</li> * <li>access time</li> * </ul> * * @return ResourceStatistics An object containing statistics information about a resource. */ public function getStat() { $stat = new ResourceStatistics(); $stat->setCreationTime($this->creationTime); $stat->setAccessTime($this->accessTime); $stat->setModificationTime($this->modificationTime); $stat->setSize($this->size); $stat->addEventListener(ResourceStatisticsChangeEvent::CREATION_TIME_CHANGED, function (Event $event) { /* @var \com\mohiva\common\io\ResourceStatistics $target */ $target = $event->getTarget(); $this->creationTime = $target->getCreationTime(); }); $stat->addEventListener(ResourceStatisticsChangeEvent::ACCESS_TIME_CHANGED, function (Event $event) { /* @var \com\mohiva\common\io\ResourceStatistics $target */ $target = $event->getTarget(); $this->accessTime = $target->getAccessTime(); }); $stat->addEventListener(ResourceStatisticsChangeEvent::MODIFICATION_TIME_CHANGED, function (Event $event) { /* @var \com\mohiva\common\io\ResourceStatistics $target */ $target = $event->getTarget(); $this->modificationTime = $target->getModificationTime(); }); return $stat; }