Skip to content

Commit

Permalink
Add isServiceProvider() util
Browse files Browse the repository at this point in the history
  • Loading branch information
aedart committed Apr 13, 2024
1 parent c63db18 commit 532610d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/support/src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ export {
ServiceProvider,
}

export * from "./isServiceProvider";
export * from "./isServiceProviderConstructor";
export * from "./ServiceProviderClassBlueprint"
27 changes: 27 additions & 0 deletions packages/support/src/services/isServiceProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { isset } from "@aedart/support/misc";
import { isServiceProviderConstructor } from "./isServiceProviderConstructor";
import ServiceProvider from "./ServiceProvider";

/**
* Determine if given object is a [ServiceProvider]{@link import('@aedart/contracts/support/services').ServiceProvider}
*
* @param {object} instance
*
* @returns {boolean}
*/
export function isServiceProvider(instance: object): boolean
{
if (!isset(instance) || typeof instance !== 'object') {
return false;
}

if (instance instanceof ServiceProvider) {
return true;
}

if (!Reflect.has(instance, 'constructor')) {
return false;
}

return isServiceProviderConstructor(instance.constructor);
}

0 comments on commit 532610d

Please sign in to comment.