Concerns
4 years ago
Contracts
4 years ago
Exceptions
4 years ago
Facades
4 years ago
FormFieldMediator
5 years ago
Checkbox.php
4 years ago
Date.php
4 years ago
Element.php
4 years ago
Email.php
4 years ago
Factory.php
4 years ago
Field.php
4 years ago
File.php
4 years ago
Form.php
4 years ago
Group.php
4 years ago
Hidden.php
4 years ago
Html.php
4 years ago
Option.php
4 years ago
Phone.php
4 years ago
Radio.php
4 years ago
Select.php
4 years ago
Text.php
4 years ago
Textarea.php
4 years ago
Types.php
4 years ago
Url.php
4 years ago
File.php
71 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Framework\FieldsAPI; |
| 4 | |
| 5 | /** |
| 6 | * A file upload field. |
| 7 | * |
| 8 | * @since 2.12.0 |
| 9 | */ |
| 10 | class File extends Field { |
| 11 | |
| 12 | use Concerns\AllowMultiple; |
| 13 | use Concerns\HasEmailTag; |
| 14 | use Concerns\HasHelpText; |
| 15 | use Concerns\HasLabel; |
| 16 | use Concerns\ShowInReceipt; |
| 17 | use Concerns\StoreAsMeta; |
| 18 | |
| 19 | const TYPE = 'file'; |
| 20 | |
| 21 | /** |
| 22 | * @param $name |
| 23 | */ |
| 24 | public function __construct( $name ) { |
| 25 | parent::__construct( $name ); |
| 26 | |
| 27 | $this->validationRules->rule( 'maxSize', 1024 ); |
| 28 | $this->validationRules->rule( 'allowedTypes', [ '*' ] ); |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Set the maximum file size. |
| 33 | * |
| 34 | * @param int $maxSize |
| 35 | * @return $this |
| 36 | */ |
| 37 | public function maxSize( $maxSize ) { |
| 38 | $this->validationRules->rule( 'maxSize', $maxSize ); |
| 39 | return $this; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Access the maximum file size. |
| 44 | * |
| 45 | * @return int |
| 46 | */ |
| 47 | public function getMaxSize() { |
| 48 | return $this->validationRules->getRule( 'maxSize' ); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Set the allowed file types. |
| 53 | * |
| 54 | * @param string[] $allowedTypes |
| 55 | * @return $this |
| 56 | */ |
| 57 | public function allowedTypes( $allowedTypes ) { |
| 58 | $this->validationRules->rule( 'allowedTypes', $allowedTypes ); |
| 59 | return $this; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Access the allowed file types. |
| 64 | * |
| 65 | * @return string[] |
| 66 | */ |
| 67 | public function getAllowedTypes() { |
| 68 | return $this->validationRules->getRule( 'allowedTypes' ); |
| 69 | } |
| 70 | } |
| 71 |