MediaWiki  master
SpinnerWidget.php
Go to the documentation of this file.
1 <?php
2 
3 namespace MediaWiki\Widget;
4 
15 
16  private $attributes;
17  private $content;
18 
22  public function __construct( array $config = [] ) {
23  $size = $config['size'] ?? 'small';
24  $type = $config['type'] ?? 'inline';
25 
26  $this->attributes = [];
27 
28  if ( isset( $config['id'] ) ) {
29  $this->attributes['id'] = $config['id'];
30  }
31 
32  // Initialization
33  $this->attributes['class'] = [
34  'mw-spinner',
35  $size === 'small' ? 'mw-spinner-small' : 'mw-spinner-large',
36  $type === 'inline' ? 'mw-spinner-inline' : 'mw-spinner-block',
37  ];
38 
39  $this->content =
40  '<div class="mw-spinner-container">' .
41  str_repeat( '<div></div>', 12 ) .
42  '</div>';
43  }
44 
49  public function toString() {
50  return \MediaWiki\Html\Html::rawElement( 'div', $this->attributes, $this->content );
51  }
52 
60  public function __toString() {
61  try {
62  return $this->toString();
63  } catch ( \Exception $ex ) {
64  trigger_error( (string)$ex, E_USER_ERROR );
65  }
66  }
67 }
PHP version of jquery.spinner.
toString()
Render element into HTML.
__toString()
Magic method implementation.