Skip to content

Commit

Permalink
refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
dpanta94 committed Jan 23, 2025
1 parent 5958240 commit c6596c6
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 72 deletions.
15 changes: 5 additions & 10 deletions src/Common/Contracts/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
use TEC\Common\Exceptions\Not_Bound_Exception;

use TEC\Common\lucatume\DI52\Container as DI52_Container;
use TEC\Common\Contracts\Provider\AlreadyRegisteredException;
use TEC\Common\Contracts\Provider\ControllerInactiveException;

class Container extends DI52_Container implements ContainerInterface {
/**
Expand Down Expand Up @@ -45,14 +43,11 @@ public function get( $id ) {
* does not provide a set of deferred registrations.
*/
public function register( $service_provider_class, ...$alias ) {
try {
// Register the provider with the parent container.
parent::register( $service_provider_class, ...$alias );
} catch ( AlreadyRegisteredException $registered_exception ) {
// If the container is registered already, DO NOT fire registration actions again. Instead silently return.
return;
} catch ( ControllerInactiveException $inactive_exception ) {
// If the controller is inactive, DO NOT fire registration actions AT ALL. Instead silently return.
// Register the provider with the parent container.
parent::register( $service_provider_class, ...$alias );

if ( ! $this->getVar( $service_provider_class . '_registered' ) ) {
// If the controller is not registered, DO NOT fire registration actions AT ALL. Instead silently return.
return;
}

Expand Down
23 changes: 0 additions & 23 deletions src/Common/Contracts/Provider/AlreadyRegisteredException.php

This file was deleted.

18 changes: 2 additions & 16 deletions src/Common/Contracts/Provider/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,20 @@ abstract class Controller extends Service_Provider {
* Registers the filters and actions hooks added by the controller if the controller has not registered yet.
*
* @since 5.0.17
* @since TBD Now throws a `AlreadyRegisteredException` exception if the controller has already been
* registered or an `ControllerInactiveException` if the controller is inactive.
*
* @return void
* @throws AlreadyRegisteredException If the controller has already been registered.
* @throws ControllerInactiveException If the controller is inactive.
*/
final public function register() {
/*
* Look up and set the value in the container request cache to allow building the same Controller
* with a **different** container. (e.g. in tests).
*/
if ( static::is_registered() ) {
throw new AlreadyRegisteredException(
sprintf(
'The controller %s has already been registered.',
static::class
)
);
return;
}

if ( ! $this->is_active() ) {
throw new ControllerInactiveException(
sprintf(
'The controller %s is inactive.',
static::class
)
);
return;
}

$this->container->setVar( static::class . '_registered', true );
Expand Down
23 changes: 0 additions & 23 deletions src/Common/Contracts/Provider/ControllerInactiveException.php

This file was deleted.

0 comments on commit c6596c6

Please sign in to comment.