+
+ /**
+ * @param string $prefix
+ * @return VirtualRESTService
+ */
+ private function getInstance( $prefix ) {
+ if ( !isset( $this->instances[$prefix] ) ) {
+ throw new RuntimeException( "No service registered at prefix '{$prefix}'." );
+ }
+
+ if ( !( $this->instances[$prefix] instanceof VirtualRESTService ) ) {
+ $config = $this->instances[$prefix]['config'];
+ $class = $this->instances[$prefix]['class'];
+ $service = new $class( $config );
+ if ( !( $service instanceof VirtualRESTService ) ) {
+ throw new UnexpectedValueException( "Registered service has the wrong class." );
+ }
+ $this->instances[$prefix] = $service;
+ }
+
+ return $this->instances[$prefix];
+ }