diff --git a/packages/php/email-editor/src/class-container.php b/packages/php/email-editor/src/class-container.php index 9cbc833398..444488156f 100644 --- a/packages/php/email-editor/src/class-container.php +++ b/packages/php/email-editor/src/class-container.php @@ -1,29 +1,61 @@ -services[ $name ] = $callable; + /** + * The method for registering a new service + * + * @param string $name The name of the service. + * @param callable $callback The callable that will be used to create the service. + * @return void + */ + public function set( string $name, callable $callback ): void { + $this->services[ $name ] = $callback; } /** + * Method for getting a registered service + * * @template T - * @param class-string $name + * @param class-string $name The name of the service. * @return T + * @throws \Exception If the service is not found. */ - public function get( string $name ) { - // Check if the service is already instantiated + public function get( $name ) { + // Check if the service is already instantiated. if ( isset( $this->instances[ $name ] ) ) { return $this->instances[ $name ]; } - // Check if the service is registered + // Check if the service is registered. if ( ! isset( $this->services[ $name ] ) ) { - throw new \Exception( "Service not found: $name" ); + throw new \Exception( esc_html( "Service not found: $name" ) ); } $this->instances[ $name ] = $this->services[ $name ]( $this );