Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
attach.php
1<?php
2
3
5
6
7use Bitrix\Calendar\SerializeObject;
8use Serializable;
9
10class Attach implements Serializable
11{
12 use SerializeObject;
16 private $link;
20 private $name;
24 private $size;
25
32 public static function createInstance(string $link, string $name, int $size): Attach
33 {
34 return new self($link, $name, $size);
35 }
36
43 public function __construct(string $link, string $name, int $size)
44 {
45 $this->link = $link;
46 $this->name = $name;
47 $this->size = $size;
48 }
49
53 public function getName(): string
54 {
55 return $this->name;
56 }
57
61 public function getLink(): string
62 {
63 return $this->link;
64 }
65
69 public function getSize(): int
70 {
71 return $this->size;
72 }
73
74 public function getFormatSize($precision = 2): string
75 {
76 $suffix = array('b', 'Kb', 'Mb', 'Gb', 'Tb');
77 $pos = 0;
78 $size = $this->size;
79 while($size >= 1024 && $pos < 4)
80 {
81 $size /= 1024;
82 $pos++;
83 }
84
85 return round($size, $precision) . ' ' . $suffix[$pos];
86 }
87}
static createInstance(string $link, string $name, int $size)
Definition attach.php:32
__construct(string $link, string $name, int $size)
Definition attach.php:43