MediaWiki master
SpinnerWidget.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Widget;
4
5use Exception;
7use Stringable;
8
18class SpinnerWidget implements Stringable {
19
21 private $attributes;
23 private $content;
24
28 public function __construct( array $config = [] ) {
29 $size = $config['size'] ?? 'small';
30 $type = $config['type'] ?? 'inline';
31
32 $this->attributes = [];
33
34 if ( isset( $config['id'] ) ) {
35 $this->attributes['id'] = $config['id'];
36 }
37
38 // Initialization
39 $this->attributes['class'] = [
40 'mw-spinner',
41 $size === 'small' ? 'mw-spinner-small' : 'mw-spinner-large',
42 $type === 'inline' ? 'mw-spinner-inline' : 'mw-spinner-block',
43 ];
44
45 $this->content =
46 '<div class="mw-spinner-container">' .
47 str_repeat( '<div></div>', 12 ) .
48 '</div>';
49 }
50
55 public function toString() {
56 return Html::rawElement( 'div', $this->attributes, $this->content );
57 }
58
66 public function __toString() {
67 try {
68 return $this->toString();
69 } catch ( Exception $ex ) {
70 trigger_error( (string)$ex, E_USER_ERROR );
71 }
72 }
73}
This class is a collection of static functions that serve two purposes:
Definition Html.php:56
PHP version of jquery.spinner.
toString()
Render element into HTML.
__toString()
Magic method implementation.