Skip to content

Instantly share code, notes, and snippets.

@monooso
Created July 17, 2015 21:39
Show Gist options
  • Save monooso/817318b369a07ebc2d9b to your computer and use it in GitHub Desktop.
Save monooso/817318b369a07ebc2d9b to your computer and use it in GitHub Desktop.
Helper method to determine whether a third-party Composer package is loaded by a particular Craft plugin.
/**
* Returns a boolean indicating whether the specified class is loaded from
* the directory of the specified plugin.
*
* @param $namespacedClass
* @param $pluginHandle
*
* @return bool
*/
protected function isPackageLoadedByPlugin($namespacedClass, $pluginHandle)
{
$reflector = new \ReflectionClass($namespacedClass);
$pattern = '#' . CRAFT_PLUGINS_PATH . $pluginHandle . '/#';
return (bool) preg_match($pattern, $reflector->getFileName());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment