src/Contao/Callback/Callbacks.php
protected static function evaluateCallback($callback)
    {
        if (\is_array($callback) && (2 === \count($callback)) && \is_string($callback[0]) && \is_string($callback[1])) {
            $serviceCallback = static::evaluateServiceCallback($callback);
            if ($serviceCallback[0] !== $callback[0]) {
                return $serviceCallback;
            }

            $class = new \ReflectionClass($callback[0]);

            // Ff the method is static, do not create an instance.
            if ($class->hasMethod($callback[1]) && $class->getMethod($callback[1])->isStatic()) {
                return $callback;
            }

            // Fetch singleton instance.
            if ($class->hasMethod('getInstance')) {
                $getInstanceMethod = $class->getMethod('getInstance');

                if ($getInstanceMethod->isStatic()) {
                    $callback[0] = $getInstanceMethod->invoke(null);
                    return $callback;
                }
            }

            // Create a new instance.
            $constructor = $class->getConstructor();

            if (!$constructor || $constructor->isPublic()) {
                $callback[0] = $class->newInstance();
            } else {
                // Graceful fallback, to prevent access violation to non-public \Backend::__construct().
                $callback[0] = $class->newInstanceWithoutConstructor();
                $constructor->setAccessible(true);
                $constructor->invoke($callback[0]);
            }
        }

        return $callback;
    }
protected static function evaluateCallback($callback)
    {
        if (\is_array($callback) && (2 === \count($callback)) && \is_string($callback[0]) && \is_string($callback[1])) {
            $serviceCallback = static::evaluateServiceCallback($callback);
            if ($serviceCallback[0] !== $callback[0]) {
                return $serviceCallback;
            }

            $class = new \ReflectionClass($callback[0]);

            // Ff the method is static, do not create an instance.
            if ($class->hasMethod($callback[1]) && $class->getMethod($callback[1])->isStatic()) {
                return $callback;
            }

            // Fetch singleton instance.
            if ($class->hasMethod('getInstance')) {
                $getInstanceMethod = $class->getMethod('getInstance');

                if ($getInstanceMethod->isStatic()) {
                    $callback[0] = $getInstanceMethod->invoke(null);
                    return $callback;
                }
            }

            // Create a new instance.
            $constructor = $class->getConstructor();

            if (!$constructor || $constructor->isPublic()) {
                $callback[0] = $class->newInstance();
            } else {
                // Graceful fallback, to prevent access violation to non-public \Backend::__construct().
                $callback[0] = $class->newInstanceWithoutConstructor();
                $constructor->setAccessible(true);
                $constructor->invoke($callback[0]);
            }
        }

        return $callback;
    }
protected static function evaluateCallback ( $ callback ) { if ( \ is_array ( $ callback ) && ( 2 === \ count ( $ callback ) ) && \ is_string ( $ callback [ 0 ] ) && \ is_string ( $ callback [ 1 ] ) ) { $ serviceCallback = static :: evaluateServiceCallback ( $ callback ) ; if ( $ serviceCallback [ 0 ] !== $ callback [ 0 ] ) { return $ serviceCallback ; } $ class = new \ ReflectionClass ( $ callback [ 0 ] ) ; // Ff the method is static, do not create an instance. if ( $ class -> hasMethod ( $ callback [ 1 ] ) && $ class -> getMethod ( $ callback [ 1 ] ) -> isStatic ( ) ) { return $ callback ; } // Fetch singleton instance. if ( $ class -> hasMethod ( 'getInstance' ) ) { $ getInstanceMethod = $ class -> getMethod ( 'getInstance' ) ; if ( $ getInstanceMethod -> isStatic ( ) ) { $ callback [ 0 ] = $ getInstanceMethod -> invoke ( null ) ; return $ callback ; } } // Create a new instance. $ constructor = $ class -> getConstructor ( ) ; if ( ! $ constructor || $ constructor -> isPublic ( ) ) { $ callback [ 0 ] = $ class -> newInstance ( ) ; } else { // Graceful fallback, to prevent access violation to non-public \Backend::__construct(). $ callback [ 0 ] = $ class -> newInstanceWithoutConstructor ( ) ; $ constructor -> setAccessible ( true ) ; $ constructor -> invoke ( $ callback [ 0 ] ) ; } } return $ callback ; }
Evaluate the callback and create an object instance if required and possible.

@param array|callable $callback The callback to invoke.

@return array|callable

@SuppressWarnings(PHPMD.CyclomaticComplexity)
Evaluate the callback and create an object instance if required and possible .