# cookiebot/3.11.3/addons/inc/Dependencies/DI/Reflection/CallableReflectionFactory.php

Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA &amp; Google Consent Mode, version 3.11.3. 52 lines.

- Page: https://pluginprobe.com/plugins/cookiebot/3.11.3/code/addons/inc/Dependencies/DI/Reflection/CallableReflectionFactory.php
- Raw: https://pluginprobe.com/plugins/cookiebot/3.11.3/raw/addons/inc/Dependencies/DI/Reflection/CallableReflectionFactory.php
- Modified: 2021-03-23T11:49:48+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/cookiebot/3.11.3/code/addons/inc/Dependencies/DI/Reflection/CallableReflectionFactory.php#L10-L20`.

```php
<?php
/**
 * PHP-DI
 *
 * @link      http://php-di.org/
 * @copyright Matthieu Napoli (http://mnapoli.fr/)
 * @license   http://www.opensource.org/licenses/mit-license.php MIT (see the LICENSE file)
 */

namespace Cybot\Dependencies\DI\Reflection;

/**
 * Create a reflection object from a callable.
 *
 * @author Matthieu Napoli <matthieu@mnapoli.fr>
 */
class CallableReflectionFactory
{
    /**
     * @param callable $callable
     *
     * @return \ReflectionFunctionAbstract
     */
    public static function fromCallable($callable)
    {
        // Array callable
        if (is_array($callable)) {
            list($class, $method) = $callable;

            return new \ReflectionMethod($class, $method);
        }

        // Closure
        if ($callable instanceof \Closure) {
            return new \ReflectionFunction($callable);
        }

        // Callable object (i.e. implementing __invoke())
        if (is_object($callable) && method_exists($callable, '__invoke')) {
            return new \ReflectionMethod($callable, '__invoke');
        }

        // Callable class (i.e. implementing __invoke())
        if (is_string($callable) && class_exists($callable) && method_exists($callable, '__invoke')) {
            return new \ReflectionMethod($callable, '__invoke');
        }

        // Standard function
        return new \ReflectionFunction($callable);
    }
}

```
