skinContext = $skinContext; } /** * Get a component. This method has side effects in that * if registered components have been not initialized they * will be registered as part of this method. * * @param string $name * @throws RuntimeException with unknown name * @return SkinComponent */ public function getComponent( string $name ): SkinComponent { if ( $this->components === null ) { $this->registerComponents(); } $component = $this->components[$name] ?? null; if ( !$component ) { throw new RuntimeException( 'Unknown component: ' . $name ); } return $component; } /** * Return all registered components. * * @since 1.38 * @return SkinComponent[] */ public function getComponents() { if ( $this->components === null ) { $this->registerComponents(); } return $this->components; } /** * Registers a component for use with the skin. * Private for now, but in future we may consider making this a * public method to allow skins to extend component definitions. * * @param string $name * @throws RuntimeException if given an unknown name */ private function registerComponent( string $name ) { $skin = $this->skinContext; switch ( $name ) { case 'copyright': $component = new SkinComponentCopyright( $skin ); break; case 'logos': $component = new SkinComponentLogo( $skin->getConfig(), $skin->getLanguage() ); break; case 'search-box': $component = new SkinComponentSearch( $skin->getConfig(), $skin->getMessageLocalizer(), SpecialPage::newSearchPage( $skin->getUser() ) ); break; case 'toc': $component = new SkinComponentTableOfContents( $skin->getOutput() ); break; case 'last-modified': $component = new SkinComponentLastModified( $skin, $skin->getOutput()->getRevisionTimestamp() ); break; case 'footer': $component = new SkinComponentFooter( $skin ); break; default: throw new RuntimeException( 'Unknown component: ' . $name ); } $this->components[$name] = $component; } /** * Registers components used by skin. */ private function registerComponents() { $this->registerComponent( 'copyright' ); $this->registerComponent( 'last-modified' ); $this->registerComponent( 'logos' ); $this->registerComponent( 'toc' ); $this->registerComponent( 'search-box' ); $this->registerComponent( 'footer' ); } }