Debian Codegraph @

includes/widget/SpinnerWidget.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Widget;
4
5 use MediaWiki\Html\Html;
6 use Stringable;
7
8 /**
9 * PHP version of jquery.spinner.
10 *
11 * If used with jquery.spinner.styles, can be used to show a
12 * spinner before JavaScript has loaded.
13 *
14 * @copyright 2011-2020 MediaWiki Widgets Team and others; see AUTHORS.txt
15 * @license MIT
16 */
17 class SpinnerWidget implements Stringable {
18
19 /** @var array */
20 private $attributes;
21 /** @var string */
22 private $content;
23
24 /**
25 * @param array $config Configuration options
26 */
27 public function __construct( array $config = [] ) {
28 $size = $config['size'] ?? 'small';
29 $type = $config['type'] ?? 'inline';
30
31 $this->attributes = [];
32
33 if ( isset( $config['id'] ) ) {
34 $this->attributes['id'] = $config['id'];
35 }
36
37 // Initialization
38 $this->attributes['class'] = [
39 'mw-spinner',
40 $size === 'small' ? 'mw-spinner-small' : 'mw-spinner-large',
41 $type === 'inline' ? 'mw-spinner-inline' : 'mw-spinner-block',
42 ];
43
44 $this->content =
45 '<div class="mw-spinner-container">' .
46 str_repeat( '<div></div>', 12 ) .
47 '</div>';
48 }
49
50 /**
51 * Render element into HTML.
52 * @return string HTML serialization
53 */
54 public function toString() {
55 return Html::rawElement( 'div', $this->attributes, $this->content );
56 }
57
58 /**
59 * Magic method implementation.
60 *
61 * Copied from OOUI\Tag
62 *
63 * @return string
64 */
65 public function __toString() {
66 return $this->toString();
67 }
68 }