diff --git a/.gitignore b/.gitignore index 4863f340..a72c2c6d 100644 --- a/.gitignore +++ b/.gitignore @@ -55,4 +55,5 @@ codeception.yml # Build -assets/dist \ No newline at end of file +assets/dist + diff --git a/lib/Lib/Container.php b/lib/Lib/Container.php deleted file mode 100644 index ad8983ba..00000000 --- a/lib/Lib/Container.php +++ /dev/null @@ -1,198 +0,0 @@ - $value ) { - $this->add( $value, $key ); - } - - return; - } - - if ( empty( $name ) || is_numeric( $name ) ) { - $name = is_object( $service ) ? get_class( $service ) : $service; - } - $name = $this->sanitize_name( $name ); - - // If the service already exists bail. - if ( isset( $this->services[ $name ] ) ) { - return; - } - if ( is_string( $service ) && class_exists( $service ) ) { - $service = new $service(); - } - $this->services[ $name ] = $service; - } - - /** - * Get a service from the container by name. - * - * @param string $name The service name. - * - * @since 1.0.0 - * - * @return mixed|null - */ - public function get( $name ) { - $name = $this->sanitize_name( $name ); - - if ( isset( $this->services[ $name ] ) ) { - return $this->services[ $name ]; - } - - // If the name does not contain a slash, try to find the service by its class name. - if ( false === str_contains( $name, '/' ) && isset( $this->services[ "$name/$name" ] ) ) { - return $this->services[ "$name/$name" ]; - } - - return null; - } - - /** - * Remove a service from the container. - * - * @param string $name The service name. - * - * @since 1.0.0 - * - * @return void - */ - public function remove( $name ) { - $name = $this->sanitize_name( $name ); - if ( isset( $this->services[ $name ] ) ) { - unset( $this->services[ $name ] ); - } - } - - /** - * Has a service. - * - * @param string $name The service name. - * - * @since 1.0.0 - * @return bool - */ - public function has( $name ) { - $name = $this->sanitize_name( $name ); - - if ( isset( $this->services[ $name ] ) ) { - return true; - } - - if ( false === str_contains( $name, '/' ) && isset( $this->services[ "$name/$name" ] ) ) { - return true; - } - - return false; - } - - /** - * Whether a offset exists. - * - * @param mixed $offset An offset to check for. - * - * @since 1.0.0 - * - * @return boolean - */ - #[ReturnTypeWillChange] - public function offsetExists( $offset ) { - return $this->has( $offset ); - } - - /** - * Offset to retrieve. - * - * @param mixed $offset The offset to retrieve. - * - * @since 1.0.0 - * - * @return mixed - */ - #[ReturnTypeWillChange] - public function offsetGet( $offset ) { - return $this->get( $offset ); - } - - /** - * Offset to set. - * - * @param mixed $offset The offset to assign the value to. - * @param mixed $value The value to set. - * - * @since 1.0.0 - * - * @return void - */ - #[ReturnTypeWillChange] - public function offsetSet( $offset, $value ) { - $this->add( $value, $offset ); - } - - /** - * Offset to unset. - * - * @param mixed $offset The offset to unset. - * - * @since 1.0.0 - * - * @return void - */ - #[ReturnTypeWillChange] - public function offsetUnset( $offset ) { - $this->remove( $offset ); - } - - /** - * Sanitize a service name. - * - * @param string $name The service name. - * - * @return string - */ - private function sanitize_name( $name ) { - // We will remove the base namespace from the name then convert the name to snake case. - // Find the root namespace. - $root_namespace = explode( '\\', __NAMESPACE__ )[0]; - // Remove the root namespace from the name. - $name = str_replace( $root_namespace . '\\', '', $name ); - - // Convert the name to snake case and change the backslashes to forward slashes. - return strtolower( preg_replace( '/(?