diff --git a/src/Core/Interfaces/RequestChainableInterface.php b/src/Core/Interfaces/RequestChainableInterface.php index acd4b7d..450f6ad 100644 --- a/src/Core/Interfaces/RequestChainableInterface.php +++ b/src/Core/Interfaces/RequestChainableInterface.php @@ -41,6 +41,18 @@ interface RequestChainableInterface */ public function getRequestChain(): array; + /** + * Climb up the request chain searching for + * an object of a certain class + * + * If the object is found it will be returned, + * otherwise the method returns null + * + * @author Benjamin Blake (sitelease.ca) + * @param string $class The class of the object you are searching for + * @return object|null + */ + public function searchRequestChain(string $class): ?object; /** * Return the request chain heirarchy diff --git a/src/Core/Traits/RequestChainable.php b/src/Core/Traits/RequestChainable.php index 8c1a79b..b3386c9 100644 --- a/src/Core/Traits/RequestChainable.php +++ b/src/Core/Traits/RequestChainable.php @@ -74,6 +74,32 @@ trait RequestChainable return $requestChain; } + /** + * Climb up the request chain searching for + * an object of a certain class + * + * If the object is found it will be returned, + * otherwise the method returns null + * + * @author Benjamin Blake (sitelease.ca) + * @param string $class The class of the object you are searching for + * @return object|null + */ + public function searchRequestChain(string $class): ?object + { + $requestChain = $this->getRequestChain(); + + $foundObj = null; + foreach ($requestChain as $callerObj) { + if ($class == get_class($callerObj)) { + $foundObj = $callerObj; + break; + } + } + + return $foundObj; + } + /** * Return the request chain heirarchy * as a string of class names diff --git a/src/TestRun.php b/src/TestRun.php index dad2bc0..53476ee 100644 --- a/src/TestRun.php +++ b/src/TestRun.php @@ -5,6 +5,7 @@ namespace Gitea; require 'vendor/autoload.php'; use Gitea\Client; +use Gitea\Model\Repository; print("Starting Script... \n"); print("Creating Guzzle client \n"); @@ -65,6 +66,13 @@ if ($repository) { if ($debugChain) { print("Chain ".$debugChain."\n"); } + $foundObj = $branch->searchRequestChain(Repository::class); + if ($foundObj) { + print("Repository class found \n"); + print("Type: ".get_class($foundObj)." \n"); + } else{ + print("Repository class NOT found \n"); + } print("\n\n"); } print("Total Branches: ".count($branches)."\n");