Debian Codegraph @

vendor/wikimedia/parsoid/src/Ext/Gallery/Mode.php

raw
1 <?php
2 declare( strict_types = 1 );
3
4 namespace Wikimedia\Parsoid\Ext\Gallery;
5
6 use Wikimedia\Parsoid\DOM\DocumentFragment;
7 use Wikimedia\Parsoid\Ext\ParsoidExtensionAPI;
8
9 abstract class Mode {
10 /**
11 * The name of this mode.
12 * @var string
13 */
14 protected $mode;
15
16 /**
17 * Construct a (singleton) mode.
18 * @param string $name The name of this mode, all lowercase.
19 */
20 protected function __construct( string $name ) {
21 $this->mode = $name;
22 }
23
24 public function getModules(): array {
25 return [];
26 }
27
28 public function getModuleStyles(): array {
29 return [];
30 }
31
32 /**
33 * Format the dimensions as a string.
34 */
35 abstract public function dimensions( Opts $opts ): string;
36
37 /**
38 * Render HTML for the given lines in this mode.
39 * @param ParsoidExtensionAPI $extApi
40 * @param Opts $opts
41 * @param ?DocumentFragment $caption
42 * @param ParsedLine[] $lines
43 * @return DocumentFragment
44 */
45 abstract public function render(
46 ParsoidExtensionAPI $extApi, Opts $opts, ?DocumentFragment $caption,
47 array $lines
48 ): DocumentFragment;
49
50 /**
51 * Return the Mode object with the given name,
52 * or null if the name is invalid.
53 * @param string $name
54 * @return Mode|null
55 */
56 public static function byName( string $name ): ?Mode {
57 static $modesByName = null;
58 if ( $modesByName === null ) {
59 $modesByName = [
60 'traditional' => new TraditionalMode(),
61 'nolines' => new NoLinesMode(),
62 'slideshow' => new SlideshowMode(),
63 'packed' => new PackedMode(),
64 'packed-hover' => new PackedHoverMode(),
65 'packed-overlay' => new PackedOverlayMode()
66 ];
67 }
68 return $modesByName[$name] ?? null;
69 }
70 }