-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add static helpers for WpService and AcfService
- Loading branch information
Showing
3 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace Municipio\Helper; | ||
|
||
use AcfService\AcfService as OriginalAcfService; | ||
|
||
/** | ||
* Class AcfService | ||
* | ||
* Static class to hold the AcfService instance. | ||
* Use this class when you are unable to pass the AcfService instance as a parameter. | ||
*/ | ||
class AcfService | ||
{ | ||
private static ?OriginalAcfService $acfService = null; | ||
|
||
/** | ||
* Set the AcfService instance. | ||
* | ||
* @param OriginalAcfService $acfService | ||
*/ | ||
public static function set(OriginalAcfService $acfService): void | ||
{ | ||
if (self::$acfService === null) { | ||
// Allow setting once to prevent accidental overwriting. | ||
self::$acfService = $acfService; | ||
} | ||
} | ||
|
||
/** | ||
* Get the AcfService instance. | ||
* | ||
* @return OriginalAcfService | ||
* @throws \Exception | ||
*/ | ||
public static function get(): OriginalAcfService | ||
{ | ||
if (self::$acfService === null) { | ||
throw new \Exception('AcfService not set'); | ||
} | ||
|
||
return self::$acfService; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace Municipio\Helper; | ||
|
||
use WpService\WpService as OriginalWpService; | ||
|
||
/** | ||
* Class WpService | ||
* | ||
* Static class to hold the WpService instance. | ||
* Use this class when you are unable to pass the WpService instance as a parameter. | ||
*/ | ||
class WpService | ||
{ | ||
private static ?OriginalWpService $wpService = null; | ||
|
||
/** | ||
* Set the WpService instance. | ||
* | ||
* @param OriginalWpService $wpService | ||
*/ | ||
public static function set(OriginalWpService $wpService): void | ||
{ | ||
if (self::$wpService === null) { | ||
// Allow setting once to prevent accidental overwriting. | ||
self::$wpService = $wpService; | ||
} | ||
} | ||
|
||
/** | ||
* Get the WpService instance. | ||
* | ||
* @return OriginalWpService|null | ||
*/ | ||
public static function get(): ?OriginalWpService | ||
{ | ||
if (self::$wpService === null) { | ||
throw new \Exception('WpService not set'); | ||
} | ||
|
||
return self::$wpService; | ||
} | ||
} |