예제 #1
0
 /**
  * Test if the `setSize` method dispatches the
  * `ResourceStatisticsChangeEvent` event.
  */
 public function testSetSizeDispatchesEvent()
 {
     $dispatched = false;
     $listener = function (ResourceStatisticsChangeEvent $event) use(&$dispatched) {
         $dispatched = true;
     };
     $stat = new ResourceStatistics();
     $stat->addEventListener(ResourceStatisticsChangeEvent::SIZE_CHANGED, $listener);
     $stat->setSize(1);
     $this->assertTrue($dispatched);
 }
예제 #2
0
 /**
  * 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;
 }
예제 #3
0
 /**
  * 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;
 }