/**
  * @param AddStorage $addStorage
  */
 public function add(AddStorage $addStorage)
 {
     Assertion::integer($addStorage->storage);
     Assertion::integer($addStorage->quota);
     $storage = Storage::withUserDateUsageQuota(User::named($addStorage->name), new \DateTime(), Bytes::allocateUnits((int) $addStorage->storage), Quota::fromBytes(Bytes::allocateUnits((int) $addStorage->quota)));
     $this->storageRepository->add($storage);
 }
예제 #2
0
 /**
  * @test
  */
 public function shouldReturnDateSeparatelyOnJsonSerialize()
 {
     $dateTime = new \DateTime("2015-12-31 23:50:01");
     $storage = Storage::withUserDateUsageQuota(User::named('username'), $dateTime, Bytes::allocateUnits(0), Quota::fromBytes(Bytes::allocateUnits(1)));
     $serializedStorage = $storage->jsonSerialize();
     $this->assertSame('2015', $serializedStorage['year']);
     $this->assertSame('12', $serializedStorage['month']);
     $this->assertSame('31', $serializedStorage['day']);
     $this->assertSame('23', $serializedStorage['hour']);
     $this->assertSame('50', $serializedStorage['minute']);
 }
 /**
  * @param array $row
  * @param string $unitOfMeasurement
  * @return Storage
  */
 private function mapStorageUsageRowToStorage($row, $unitOfMeasurement = 'b')
 {
     $bytes = Bytes::allocateUnits((int) $row['usage']);
     switch ($unitOfMeasurement) {
         case 'gb':
             $bytes = $bytes->gigaBytes();
             break;
         case 'mb':
             $bytes = $bytes->megaBytes();
             break;
         case 'kb':
             $bytes = $bytes->kiloBytes();
             break;
     }
     return Storage::withUserDateUsageQuota(User::named($row['username']), \DateTime::createFromFormat("Y-m-d H:i:s", $row['created']), $bytes, Quota::fromBytes(Bytes::allocateUnits((int) $row['maximumusage'])));
 }
 /**
  * @param Storage $storage
  * @return CouldNotAddStorage
  */
 public static function byStorage(Storage $storage)
 {
     return new self("Could not add storage for " . $storage->user()->name());
 }
 /**
  * @param StorageCollection $collection
  * @param string $username
  */
 private function addStorageToCollection(StorageCollection $collection, $username)
 {
     $collection->add(Storage::withUserDateUsageQuota(User::named($username), new \DateTime("2015-12-31 23:50:01"), Bytes::allocateUnits(0), Quota::fromBytes(Bytes::allocateUnits(1))));
 }