src/Components.php
public static function detectClassComponent($mClass): ?Component
    {
        $oReflect  = new \ReflectionClass($mClass);
        $sPath     = $oReflect->getFileName();
        $bIsVendor = (bool) preg_match('/^' . preg_quote(NAILS_APP_PATH . 'vendor', '/') . '/', $sPath);

        if (!$bIsVendor) {
            return static::getApp();
        }

        foreach (static::available() as $oComponent) {

            if ($oComponent->slug === 'app') {
                continue;
            } elseif (preg_match('/^' . preg_quote($oComponent->path, '/') . '/', $sPath)) {
                return $oComponent;
            }
        }

        return null;
    }
public static function detectClassComponent($mClass): ?Component
    {
        $oReflect  = new \ReflectionClass($mClass);
        $sPath     = $oReflect->getFileName();
        $bIsVendor = (bool) preg_match('/^' . preg_quote(NAILS_APP_PATH . 'vendor', '/') . '/', $sPath);

        if (!$bIsVendor) {
            return static::getApp();
        }

        foreach (static::available() as $oComponent) {

            if ($oComponent->slug === 'app') {
                continue;
            } elseif (preg_match('/^' . preg_quote($oComponent->path, '/') . '/', $sPath)) {
                return $oComponent;
            }
        }

        return null;
    }
public static function detectClassComponent ( $ mClass ) : ? Component { $ oReflect = new \ ReflectionClass ( $ mClass ) ; $ sPath = $ oReflect -> getFileName ( ) ; $ bIsVendor = ( bool ) preg_match ( '/^' . preg_quote ( NAILS_APP_PATH . 'vendor' , '/' ) . '/' , $ sPath ) ; if ( ! $ bIsVendor ) { return static :: getApp ( ) ; } foreach ( static :: available ( ) as $ oComponent ) { if ( $ oComponent -> slug === 'app' ) { continue ; } elseif ( preg_match ( '/^' . preg_quote ( $ oComponent -> path , '/' ) . '/' , $ sPath ) ) { return $ oComponent ; } } return null ; }
Attempt to detect which component a class belongs to

@param mixed $mClass A class as a string or an object

@return Component|null
@throws \ReflectionException
Attempt to detect which component a class belongs to